Traduzione codice da pinescript a prorealcode

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #237939 quote
    RubbinRubbin02
    Participant
    New

    Buongiorno, è possibile tradurre questo indicatore di divergenze RSI di tradingview da pinescript a prorealcode?

    Ecco il codice:

    indicator(title=”RSI Divergence Indicator”, format=format.price, timeframe=””, timeframe_gaps=true)
    len = input.int(title=”RSI Period”, minval=1, defval=14)
    src = input(title=”RSI Source”, defval=close)
    lbR = input(title=”Pivot Lookback Right”, defval=5, display = display.data_window)
    lbL = input(title=”Pivot Lookback Left”, defval=5, display = display.data_window)
    rangeUpper = input(title=”Max of Lookback Range”, defval=60, display = display.data_window)
    rangeLower = input(title=”Min of Lookback Range”, defval=5, display = display.data_window)
    plotBull = input(title=”Plot Bullish”, defval=true, display = display.data_window)
    plotHiddenBull = input(title=”Plot Hidden Bullish”, defval=false, display = display.data_window)
    plotBear = input(title=”Plot Bearish”, defval=true, display = display.data_window)
    plotHiddenBear = input(title=”Plot Hidden Bearish”, defval=false, display = display.data_window)
    bearColor = color.red
    bullColor = color.green
    hiddenBullColor = color.new(color.green, 80)
    hiddenBearColor = color.new(color.red, 80)
    textColor = color.white
    noneColor = color.new(color.white, 100)
    osc = ta.rsi(src, len)
    plot(osc, title=”RSI”, linewidth=2, color=#2962FF)
    hline(50, title=”Middle Line”, color=#787B86, linestyle=hline.style_dotted)
    obLevel = hline(70, title=”Overbought”, color=#787B86, linestyle=hline.style_dotted)
    osLevel = hline(30, title=”Oversold”, color=#787B86, linestyle=hline.style_dotted)
    fill(obLevel, osLevel, title=”Background”, color=color.rgb(33, 150, 243, 90))
    plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
    phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
    _inRange(cond) =>
        bars = ta.barssince(cond == true)
        rangeLower <= bars and bars <= rangeUpper
    //——————————————————————————
    // Regular Bullish
    // Osc: Higher Low
    oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
    // Price: Lower Low
    priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
    bullCondAlert = priceLL and oscHL and plFound
    bullCond = plotBull and bullCondAlert
    plot(
         plFound ? osc[lbR] : na,
         offset=-lbR,
         title=”Regular Bullish”,
         linewidth=2,
         color=(bullCond ? bullColor : noneColor),
         display = display.pane
         )
    plotshape(
         bullCond ? osc[lbR] : na,
         offset=-lbR,
         title=”Regular Bullish Label”,
         text=” Bull “,
         style=shape.labelup,
         location=location.absolute,
         color=bullColor,
         textcolor=textColor
         )
    //——————————————————————————
    // Hidden Bullish
    // Osc: Lower Low
    oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
    // Price: Higher Low
    priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
    hiddenBullCondAlert = priceHL and oscLL and plFound
    hiddenBullCond = plotHiddenBull and hiddenBullCondAlert
    plot(
         plFound ? osc[lbR] : na,
         offset=-lbR,
         title=”Hidden Bullish”,
         linewidth=2,
         color=(hiddenBullCond ? hiddenBullColor : noneColor),
         display = display.pane
         )
    plotshape(
         hiddenBullCond ? osc[lbR] : na,
         offset=-lbR,
         title=”Hidden Bullish Label”,
         text=” H Bull “,
         style=shape.labelup,
         location=location.absolute,
         color=bullColor,
         textcolor=textColor
         )
    //——————————————————————————
    // Regular Bearish
    // Osc: Lower High
    oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
    // Price: Higher High
    priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
    bearCondAlert = priceHH and oscLH and phFound
    bearCond = plotBear and bearCondAlert
    plot(
         phFound ? osc[lbR] : na,
         offset=-lbR,
         title=”Regular Bearish”,
         linewidth=2,
         color=(bearCond ? bearColor : noneColor),
         display = display.pane
         )
    plotshape(
         bearCond ? osc[lbR] : na,
         offset=-lbR,
         title=”Regular Bearish Label”,
         text=” Bear “,
         style=shape.labeldown,
         location=location.absolute,
         color=bearColor,
         textcolor=textColor
         )
    //——————————————————————————
    // Hidden Bearish
    // Osc: Higher High
    oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
    // Price: Lower High
    priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
    hiddenBearCondAlert = priceLH and oscHH and phFound
    hiddenBearCond = plotHiddenBear and hiddenBearCondAlert
    plot(
         phFound ? osc[lbR] : na,
         offset=-lbR,
         title=”Hidden Bearish”,
         linewidth=2,
         color=(hiddenBearCond ? hiddenBearColor : noneColor),
         display = display.pane
         )
    plotshape(
         hiddenBearCond ? osc[lbR] : na,
         offset=-lbR,
         title=”Hidden Bearish Label”,
         text=” H Bear “,
         style=shape.labeldown,
         location=location.absolute,
         color=bearColor,
         textcolor=textColor
         )
    alertcondition(bullCondAlert, title=’Regular Bullish Divergence’, message=”Found a new Regular Bullish Divergence, Pivot Lookback Right number of bars to the left of the current bar”)
    alertcondition(hiddenBullCondAlert, title=’Hidden Bullish Divergence’, message=’Found a new Hidden Bullish Divergence, Pivot Lookback Right number of bars to the left of the current bar’)
    alertcondition(bearCondAlert, title=’Regular Bearish Divergence’, message=’Found a new Regular Bearish Divergence, Pivot Lookback Right number of bars to the left of the current bar’)
    alertcondition(hiddenBearCondAlert, title=’Hidden Bearish Divergence’, message=’Found a new Hidden Bearish Divergence, Pivot Lookback Right number of bars to the left of the current bar’)
    Grazie in anticipo
    #237965 quote
    Iván González
    Moderator
    Master

    Ecco qui:

    //----------------------------------------------//
    //PRC_RSI Divergence Indicator
    //version = 0
    //24.09.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //----------------------------------------------//
    //-----Inputs-----------------------------------//
    //----------------------------------------------//
    len=14 //RSI Length
    src=close
    lbr=5 //pivot lookback Right
    lbl=5 //pivot lookback Left
    rangeUpper=60 //Max lookback range
    rangeLower=5 //Min lookback range
    plotBull=1
    plotHiddenBull=1
    plotBear=1
    plotHiddenBear=1
    //----------------------------------------------//
    //-----RSI Calculation--------------------------//
    //----------------------------------------------//
    osc=rsi[len](src)
    midlevel=50
    obLevel=70
    osLevel=30
    colorbetween(obLevel,osLevel,33,150,243,50)
    //----------------------------------------------//
    //-----Pivots High and Low----------------------//
    //----------------------------------------------//
    //---Pivots low
    if osc > osc[lbr] and lowest[lbr](osc) > osc[lbr] and osc[lbr] < lowest[lbl](osc)[lbr+1] then
    $ply[z+1] = osc[lbr]
    $plx[z+1] = barindex[lbr]
    $pricel[z+1] = low[lbr]
    drawpoint(barindex[lbr],osc[lbr],2)coloured("red",80)
    z = z + 1
    endif
    //---Pivots high
    if osc < osc[lbr] and highest[lbr](osc)<osc[lbr] and osc[lbr]>highest[lbl](osc)[lbr+1] then
    $phy[t+1]=osc[lbr]
    $phx[t+1]=barindex[lbr]
    $priceH[t+1]=high[lbr]
    drawpoint(barindex[lbr],osc[lbr],2)coloured("blue",80)
    t=t+1
    endif
    //---Pivot detection
    if z<>z[1] then
    plFound=1
    elsif t<>t[1] then
    phFound=1
    else
    plFound=0
    phFound=0
    endif
    
    barsPL=barssince(plFound[1])
    inrangePL=rangelower<=barsPL and barsPL<=rangeupper
    barsPH=barssince(pHFound[1])
    inrangePH=rangelower<=barsPH and barsPH<=rangeupper
    
    //----------------------------------------------//
    //-----Regular Bullish--------------------------//
    //----------------------------------------------//
    oscHL=osc[lbr]>$ply[max(0,z-1)] and inrangePL
    priceLL=low[lbr]<$pricel[max(0,z-1)]
    bullCondAlert=priceLL and oscHL and plFound
    bullCond=plotBull and bullCondalert
    
    if plFound  and bullCond then
    drawsegment($plx[max(0,z-1)],$ply[max(0,z-1)],$plx[z],$ply[z])coloured("green")style(line,2)
    endif
    //----------------------------------------------//
    //-----Hidden Bullish---------------------------//
    //----------------------------------------------//
    oscLL=osc[lbr]<$ply[max(0,z-1)] and inrangePL
    priceHL=low[lbr]>$pricel[max(0,z-1)]
    hiddenBullCondAlert=priceHL and oscLL and plFound
    hiddenBullCond=hiddenBullCondAlert and plotHiddenBull
    
    if plFound and hiddenBullCond then
    drawsegment($plx[max(0,z-1)],$ply[max(0,z-1)],$plx[z],$ply[z])coloured("green",80)style(line,2)
    endif
    //----------------------------------------------//
    //-----Regular Bearish--------------------------//
    //----------------------------------------------//
    oscLH=osc[lbr]<$phy[max(0,t-1)] and inrangePH
    priceHH=high[lbr]>$priceH[max(0,t-1)]
    bearCondAlert=priceHH and oscLH and pHFound
    bearCond=plotBear and bearCondalert
    
    if pHFound  and bearCond then
    drawsegment($phx[max(0,t-1)],$phy[max(0,t-1)],$phx[t],$phy[t])coloured("red")style(line,2)
    endif
    //----------------------------------------------//
    //-----Hidden Bearish---------------------------//
    //----------------------------------------------//
    oscHH=osc[lbr]>$phy[max(0,t-1)] and inrangePH
    priceLH=high[lbr]<$priceh[max(0,t-1)]
    hiddenBearCondAlert=priceLH and oscHH and phFound
    hiddenBearCond=hiddenBearCondAlert and plotHiddenBear
    
    if pHFound and hiddenBearCond then
    drawsegment($phx[max(0,t-1)],$phy[max(0,t-1)],$phx[t],$phy[t])coloured("red",80)style(line,2)
    endif
    //----------------------------------------------//
    return osc as "RSI"coloured("blue")style(line,2), midlevel as "MidLevel"coloured("grey")style(dottedline,1),obLevel as "obLevel"coloured("grey")style(dottedline,1),osLevel as "osLevel"coloured("grey")style(dottedline,1)
    
    RubbinRubbin02 thanked this post
    #238254 quote
    RubbinRubbin02
    Participant
    New

    Grazie mille Ivan!

    Posso chiederti solo una piccola modifica? Vorrei se possibile poter cambiare il colore del mio RSI e fare in modo che sia possibile settare un allarme quando viene rilevata una divergenza classica. E’ possibile?

    Grazie mille in anticipo

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

Traduzione codice da pinescript a prorealcode


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by RubbinRubbin02
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 09/23/2024
Status: Active
Attachments: No files
Logo Logo
Loading...