ATR take profit & stop + breakeven

Forums ProRealTime English forum ProBuilder support ATR take profit & stop + breakeven

Viewing 4 posts - 1 through 4 (of 4 total)
  • #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) * 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 🙂

    #203910

    Sorry, but do you need this as an indicator (plots signals entries/exit on chart) or a complete trading system?

    #203942

    Hi 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 🙂

     

     

    #203986

    Hi everybody,

     

    I found an easier way of doing the work with this TV script, which I can easily translate into PRT code:

    if goLong
        takeprofit := close + atr * tpATRMult
        stoploss := close – atr * slATRMult
        strategy.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 🙂
Viewing 4 posts - 1 through 4 (of 4 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login