ATR Trailing Stop Chandelier Exit

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #204511 quote
    Alex72
    Participant
    New

    Hi, thank you for sharing this.
    Can someone help me to figure out what have I to change to get the same signals like the original script in TradingView for Chandelier exit
    Settings : p=1 and mult= 2

    I always have some delay in prorealtime , when TV gives a signal, PRT give it one bar later but not always.
    I attach the TV script.
    i changed Nicola’s code to have arrows(see attachement)
    Thank you

    Nicolas ATR Trailing Stop Code

    //PRC_Another ATR trailing stop | indicator
    //24.09.2019
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    
    // --- settings
    p=14 //ATR period
    mult=2 //multiplier
    mode=1 //trailing stop mode (0=straight line
    // --- end of settings
    
    atr = AverageTrueRange[p](close) * mult
    
    once trend=1
    
    
    
    if trend=1 then
    hh=max(hh,close)
    ll=hh
    if atr<atr[1] then
    hhlevel=hh-atr
    if hhlevel>ts then
    ts=hhlevel
    endif
    endif
    r=0
    g=168
    else
    ll=min(ll,close)
    hh=ll
    if atr<atr[1] then
    lllevel=ll+atr
    if lllevel<ts then
    ts=lllevel
    endif
    endif
    r=255
    g=0
    endif
    
    if close crosses over ts then
    trend=1
    if mode>0 then
    ts=ll
    drawarrowup(barindex,low-atr/2) coloured("green")
    endif
    elsif close crosses under ts then
    trend=-1
    if mode>0 then
    ts=hh
    drawarrowdown(barindex,high+atr/2) coloured("red")
    endif
    endif
    
    
    return // ts coloured(r,g,0) style(line,3)
    

    and here is the Tradingview Code

    //@version=4
    // Copyright (c) 2019-present, Alex Orekhov (everget)
    // Chandelier Exit script may be freely distributed under the terms of the GPL-3.0 license.
    study("Chandelier Exit", shorttitle="CE", overlay=true)
    
    length = input(title="ATR Period", type=input.integer, defval=22)
    mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
    showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
    useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)
    highlightState = input(title="Highlight State ?", type=input.bool, defval=true)
    
    atr = mult * atr(length)
    
    longStop = (useClose ? highest(close, length) : highest(length)) - atr
    longStopPrev = nz(longStop[1], longStop) 
    longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
    
    shortStop = (useClose ? lowest(close, length) : lowest(length)) + atr
    shortStopPrev = nz(shortStop[1], shortStop)
    shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
    
    var int dir = 1
    dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
    
    var color longColor = color.green
    var color shortColor = color.red
    
    longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
    buySignal = dir == 1 and dir[1] == -1
    plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
    plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
    
    shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
    sellSignal = dir == -1 and dir[1] == 1
    plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
    plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
    
    midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)
    
    longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
    shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
    fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
    fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)
    
    changeCond = dir != dir[1]
    alertcondition(changeCond, title="Alert: CE Direction Change", message="Chandelier Exit has changed direction!")
    alertcondition(buySignal, title="Alert: CE Buy", message="Chandelier Exit Buy!")
    alertcondition(sellSignal, title="Alert: CE Sell", message="Chandelier Exit Sell!")
    
    PRT-Code-CE.png PRT-Code-CE.png TV-Code-CE.png TV-Code-CE.png PRC_Another-ATR-trailing-stop-Arrows.itf
    #204596 quote
    Nicolas
    Keymaster
    Legend

    are you sure the data are the same between the 2 platforms ? It could obviously leads to different calculation and therefore different signals.

    #204762 quote
    Alex72
    Participant
    New

    Hi, thank you for your answer, of sure the price displayed is different between them but i think it doesnt affect the signal, no?

    #204796 quote
    Nicolas
    Keymaster
    Legend

    Indicators are calculated with price data. If that data serie is different, how their results could be the same?! 🙄

    However in the settings of the TV indicator, I see that you can use High/Low instead of Close with “useClose” setting, is it set to true or false?

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

ATR Trailing Stop Chandelier Exit


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Alex72 @alex72 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nicolas
3 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/20/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...