Convert indicator SuperTrend from the TradingView platform

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #229195 quote
    ZAZI
    Participant
    New

    hello guys,

    Would it be possible to help me with converting the  SuperTrend  indicator from TradingViiew to ProRealTime code? It would be greatly appreciated.

    study("Supertrend", overlay = true, format=format.price, precision=2, resolution="")
    Periods = input(title="ATR Period", type=input.integer, defval=10)
    Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
    changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
    showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
    highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
    atr= atr(Periods)
    up=high-(Multiplier*atr)
    up1 = nz(up[1],up)
    up := close[1] > up1 ? max(up,up1) : up
    dn=low+(Multiplier*atr)
    dn1 = nz(dn[1], dn)
    dn := close[1] < dn1 ? min(dn, dn1) : dn
    trend = 1
    trend := nz(trend[1], trend)
    trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
    upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
    buySignal = trend == 1 and trend[1] == -1
    plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
    plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
    dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
    sellSignal = trend == -1 and trend[1] == 1
    plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
    plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
    mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
    longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
    shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
    fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
    fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
    alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
    alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
    changeCond = trend != trend[1]
    alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")
    #229200 quote
    JS
    Participant
    Veteran

    Hi ZAZI,

    When you search the library, you will find a number of different SuperTrends including the “TradingView” version…

    ZAZI thanked this post
    #229201 quote
    ZAZI
    Participant
    New
    Thanks, but i need exactly this code, because i made some changes.
    #229242 quote
    robertogozzi
    Moderator
    Master
    @ZAZI I deleted a couple of empty post (actually they were not empty, just an almost invisible character).
    ZAZI thanked this post
    #229276 quote
    Iván González
    Moderator
    Master
    hi Here it is  
    //inputs
    periods = 10 //ATR period
    multiplier = 3 //ATR multiplier
    changeATR = 1 //Change ATR Calculation Method ?
    Showsignals = 1 //Show Buy/Sell Signals ?
    highlighting = 1 //Highlighter On/Off
    ///////////////////
    atr = averagetruerange[periods](close)
    up = high - multiplier*atr
    up1 = up[1]
    if close[1] > up1 then
    up = max(up,up1)
    else
    up = up
    endif
    
    dn = low + multiplier*atr
    dn1 = dn[1]
    if close[1] < dn1 then
    dn = min(dn,dn1)
    else
    dn = dn
    endif
    
    once trend = 1
    
    if trend = -1 and close > dn1 then
    trend = 1
    elsif trend = 1 and close < up1 then
    trend = -1
    else
    trend = trend
    endif
    
    if trend = 1 then
    mysupertrend = up
    r=0
    g=255
    b=0
    else
    mysupertrend = dn
    r=255
    g=0
    b=0
    endif
    
    buysignal = trend=1 and trend[1]=-1
    sellsignal = trend=-1 and trend[1]=1
    
    if buysignal then
    drawtext("▲",barindex,mysupertrend)coloured("green")
    drawtext("Buy",barindex,mysupertrend-0.3*tr)coloured("green")
    elsif sellsignal then
    drawtext("▼",barindex,mysupertrend)coloured("red")
    drawtext("Sell",barindex,mysupertrend+0.3*tr)coloured("red")
    endif
    
    mplot = (open+close+high+low)/4
    
    colorbetween(mplot,mysupertrend,r,g,b,40)
    
    return mysupertrend coloured(r,g,b)style(line,2)
    ZAZI and Nicolas thanked this post
    #229286 quote
    ZAZI
    Participant
    New
    @Iván
    Moderator
    THANK YOU FOR CONVERT THIS CODE, BUT AT CHART AT TRADINGWIUV THER NOT HAVE LINE WHEN CLOSE CROSS OVER RED LINE AND STARTING BUY ICON AND STARTING LONG GREEN LINE .
    AND SAME IN THE OPPOSITE DIRECTION WHEN CLOSE CROSS DOWN GREEN LINE AND STARTING SELL ICON AND STARTING SHORT RED LINE.
    #229287 quote
    ZAZI
    Participant
    New
    #229290 quote
    robertogozzi
    Moderator
    Master
    What is to be deleted and why?
    #229291 quote
    ZAZI
    Participant
    New
    I PUT A LINK BY MISTAKE ON 05/03/2024 AT 7:50 AM I SAW IT NOW THANKS IN ADVANCE
    #229311 quote
    robertogozzi
    Moderator
    Master
    Please do not use ALL capital letters, as this is not considered polite according to netiquette. Thanks 🙂
    #229312 quote
    robertogozzi
    Moderator
    Master
    It must have already been deleted as I can’t find that post any longer.
    #229313 quote
    PeterSt
    Participant
    Master
    It was still there early this morning. Now it’s gone indeed.
    #229314 quote
    ZAZI
    Participant
    New
    @robertogozzi Ok,thank you very much now i will know
    #229550 quote
    ZAZI
    Participant
    New
    Hello , i need help, how i can poot at  definition of variables periods and multiplier ? Thanks in advance.
    #229551 quote
    JS
    Participant
    Veteran
    Hi,

    What do you mean exactly, can you give a little more context?

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

Convert indicator SuperTrend from the TradingView platform


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ZAZI @zazi Participant
Summary

This topic contains 22 replies,
has 5 voices, and was last updated by ZAZI
2 years ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/04/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...