ATR take profit & stop + breakeven
Forums › ProRealTime English forum › ProBuilder support › ATR take profit & stop + breakeven
- This topic has 3 replies, 2 voices, and was last updated 2 years ago by lilo789.
-
-
11/09/2022 at 7:46 PM #203875
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) * mp1 = 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 variablex_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 variableactivate_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 reachedactivate_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 reachedif 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 🙂
11/10/2022 at 8:50 AM #20391011/10/2022 at 1:34 PM #203942Hi I needed that as a trading system that has any trade entry condition for longs and shorts (could be a simple RSI or MA Crossover) with ATR TP/SL and breakeven, based on the last part of the TV strat, which is the most interesting part to me.
The complete TV system / strategy is attached as .txt document and the part with the ATR TP/SL and the breakeven is in the body of the post.
Kind Regards 🙂
11/11/2022 at 3:41 PM #203986Hi everybody,
I found an easier way of doing the work with this TV script, which I can easily translate into PRT code:
if goLongtakeprofit := close + atr * tpATRMultstoploss := close – atr * slATRMultstrategy.entry(“Long”, strategy.long, when = goLong)strategy.exit(“TP/SL”, “Long”, stop=stoploss, limit=takeprofit)Now I just wonder about the updating TP/SL in ProRealTime.Have a nice day 🙂 -
AuthorPosts
Find exclusive trading pro-tools on