Untitled

 avatar
unknown
plain_text
a month ago
4.8 kB
7
Indexable
//@version=5
indicator("ALARMLI Supertrend Optimized with RSI and Vortex", overlay=true)

// Parameters
take_profit_percent = input.float(1.0, title="Take Profit (%)", minval=0.01, step=0.1)
stop_loss_percent = input.float(1.0, title="Stop Loss (%)", minval=0.01, step=0.1)
bars_to_wait = input.int(10, "Signal Wait Period (Bars)", minval=1)

// Supertrend Parameters
NEW1_atrPeriod = input.int(10, "ATR Length 1", minval=1)
NEW1_factor = input.float(1.5, "Factor 1", minval=0.1)
[supertrend_1, direction_1] = ta.supertrend(NEW1_factor, NEW1_atrPeriod)

NEW2_atrPeriod = input.int(7, "ATR Length 2", minval=1)
NEW2_factor = input.float(2.0, "Factor 2", minval=0.1)
[supertrend_2, direction_2] = ta.supertrend(NEW2_factor, NEW2_atrPeriod)

NEW3_atrPeriod = input.int(5, "ATR Length 3", minval=1)
NEW3_factor = input.float(2.5, "Factor 3", minval=0.1)
[supertrend_3, direction_3] = ta.supertrend(NEW3_factor, NEW3_atrPeriod)

// RSI Parameters
rsi_period = input.int(14, "RSI Period")
rsi_overbought = input.int(50, "RSI Overbought Level")
rsi_oversold = input.int(30, "RSI Oversold Level")
rsi = ta.rsi(close, rsi_period)

// Vortex Parameters
vortex_period = input.int(10, "Vortex Period")
vm_plus = math.abs(high - low[1])
vm_minus = math.abs(low - high[1])
tr = math.max(math.max(math.abs(high - low), math.abs(high - close[1])), math.abs(low - close[1]))
vm_plus_sum = ta.sma(vm_plus, vortex_period)
vm_minus_sum = ta.sma(vm_minus, vortex_period)
tr_sum = ta.sma(tr, vortex_period)
vi_plus = vm_plus_sum / tr_sum
vi_minus = vm_minus_sum / tr_sum

// Position tracking variables
var float entry_price = na
var bool in_position = false
var int last_signal_bar = na

// Entry conditions
can_signal = na(last_signal_bar) or (bar_index - last_signal_bar >= bars_to_wait)
longCondition = direction_1 < 0 and direction_2 < 0 and direction_3 < 0 and rsi > rsi_overbought and vi_plus > vi_minus + 0.05 and not in_position and can_signal

// Exit conditions
take_profit_hit = in_position and high >= entry_price * (1 + take_profit_percent / 100)
stop_loss_hit = in_position and low <= entry_price * (1 - stop_loss_percent / 100)

// Position management
if longCondition
    entry_price := close
    in_position := true
    last_signal_bar := bar_index
    stop_price = entry_price * (1 - stop_loss_percent / 100)
    tp_price = entry_price * (1 + take_profit_percent / 100)
    alert("šŸ”µ LONG Signal:\nGiriş Fiyatı: " + str.tostring(close) +
          "\nStop Fiyatı: " + str.tostring(stop_price) +
          "\nKar Al Fiyatı: " + str.tostring(tp_price), alert.freq_once_per_bar)

if in_position
    if take_profit_hit
        in_position := false
        last_signal_bar := bar_index
        profit_percent = ((high - entry_price) / entry_price) * 100
        alert("šŸŸ¢ Kar Alındı:\nFiyat: " + str.tostring(high) +
              "\nKar: %" + str.tostring(profit_percent), alert.freq_once_per_bar)
    else if stop_loss_hit
        in_position := false
        last_signal_bar := bar_index
        loss_percent = ((entry_price - low) / entry_price) * 100
        alert("šŸ”“ Stop Oldu:\nFiyat: " + str.tostring(low) +
              "\nZarar: %" + str.tostring(loss_percent), alert.freq_once_per_bar)

// Plotting signals
plotshape(longCondition, title="Long Entry", location=location.belowbar, color=color.blue, style=shape.triangleup, size=size.large, text="LONG")
plotshape(take_profit_hit, title="Take Profit", location=location.belowbar, color=color.green, style=shape.circle, size=size.normal, text="Take Profit")
plotshape(stop_loss_hit, title="Stop Loss", location=location.belowbar, color=color.red, style=shape.circle, size=size.normal, text="Stop LOSS")

// Plot target levels when in position
var line tp_line = na
var line sl_line = na

if in_position
    if na(tp_line) and na(sl_line)
        tp_line := line.new(bar_index, entry_price * (1 + take_profit_percent / 100), bar_index + 1, entry_price * (1 + take_profit_percent / 100), color=color.green, style=line.style_dashed)
        sl_line := line.new(bar_index, entry_price * (1 - stop_loss_percent / 100), bar_index + 1, entry_price * (1 - stop_loss_percent / 100), color=color.red, style=line.style_dashed)
    else
        line.set_x2(tp_line, bar_index + 1)
        line.set_x2(sl_line, bar_index + 1)
else
    if not na(tp_line) and not na(sl_line)
        line.delete(tp_line)
        line.delete(sl_line)
    tp_line := na
    sl_line := na

// Plot Supertrend lines
plot(supertrend_1, "Supertrend 1", color=direction_1 < 0 ? color.green : color.red)
plot(supertrend_2, "Supertrend 2", color=direction_2 < 0 ? color.lime : color.maroon)
plot(supertrend_3, "Supertrend 3", color=direction_3 < 0 ? color.aqua : color.orange)
Leave a Comment