Trader sammie123567858 — Trading Ideas & Charts — TradingView
Hi everybody,
I found this really nice ATR TP/SL strat on TV.
It is a complicated multi indicator entry condition but has this amazing TPSL fonctionality.
The breakeven also helps reducing a lot the max DD.
ma_function(source, length) => //can be simplified to having only a SMA based ATR
if smoothing == “RMA”
ta.rma(source, length)
else
if smoothing == “SMA”
ta.sma(source, length)
else
if smoothing == “EMA”
ta.ema(source, length)
else
ta.wma(source, length)
a = ma_function(ta.tr(true), length) * m //can be simplified to having only a SMA based ATR
x = ma_function(ta.tr(true), length) * m + src1
x2 = src2 – ma_function(ta.tr(true), length) * m
p1 = plot(x, title = “ATR Short Stop Loss”, color=color.blue)
p2 = plot(x2, title = “ATR Long Stop Loss”, color= color.blue)
///////////////////////////////////////////////////////////////////////////////////////////////
shortCondition = high < ema and direction == 1 and smooth_k > 80 or (ema_condition == false and direction == 1 and smooth_k > 80)
if (shortCondition) and strategy.position_size == 0
strategy.entry(“sell”, strategy.short)
longCondition = low > ema and direction == -1 and smooth_k < 20 or (ema_condition == false and direction == -1 and smooth_k < 20)
if (longCondition) and strategy.position_size == 0
strategy.entry(“buy”, strategy.long)
x2_val = x2[bar_index – strategy.opentrades.entry_bar_index(0)]
g = (strategy.opentrades.entry_price(0) – x2_val) * 2 // tp for buy , factor = 2 can be changed to a variable
x_val = x[bar_index – strategy.opentrades.entry_bar_index(0)]
k = (x_val – strategy.opentrades.entry_price(0)) * 2 //tp for sell , factor = 2 can be changed to a variable
activate_breakeven_sl_price = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) – x2_val) //price to activate sl for buy
sl_breakeven_price_activated = ta.highest(high, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index – strategy.opentrades.entry_bar_index(0)) > activate_breakeven_sl_price ? true:false //checks if 1:1 ratio has been reached
activate_breakeven_sl_price1 = strategy.opentrades.entry_price(0) – (x_val – strategy.opentrades.entry_price(0)) //price to activate sl for buy
sl_breakeven_price_activated1 = ta.lowest(high, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index – strategy.opentrades.entry_bar_index(0)) < activate_breakeven_sl_price1 ? true:false //checks if 1:1 ratio has been reached
if strategy.position_size > 0
strategy.exit(id=”buy exit”, from_entry=”buy”,limit=strategy.opentrades.entry_price(0) + g, stop=sl_breakeven_price_activated ? strategy.opentrades.entry_price(0):x2_val)
if strategy.position_size < 0
strategy.exit(id=”sell exit”, from_entry=”sell”,limit=strategy.opentrades.entry_price(0) – k, stop=sl_breakeven_price_activated1 ? strategy.opentrades.entry_price(0):x_val)
Can anybody please help with the translation to ProRealTime?
It would be much appreciated
Kind Regards 🙂