Slope issues with divergence indicator

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #201969 quote
    tabarrington
    Participant
    New

    Hello,

    I am having a few issues trying to code an indicator. It will be a divergence indicator when its done but at the moment I am just trying to have the indicator plot a slope so I can find the value of this slope at any given point in time. All I am focusing on in the code below at the moment is when prices have made a lower high and RSI has made a higher high.

    As youll see in the screenshots Im not having an issue drawing a segment when these conditions are true but I am having trouble plotting my slope line, I can only get it to plot this line AFTER the event has occurred as you can see in the red lines which have been shaded grey. The blue lines are my drawsegment lines which are working well.

    The reason I want my slope lines is so I can make sure no other RSI has crossed over these line during the time they are active….

    Im sure my coding clunky and inefficient to look at for anyone to look at but with my very limited experience its the best I’ve managed to do.

    Any advice would be greatly appreciated so I can learn how to do this better.

    Thanks in advance!

    DEFPARAM CalculateOnLastBars = 1000
    //DEFPARAM DrawOnLastBarOnly   = true
    myrsi = rsi[14](close)
    PivotBAR    = 2
    LookBack    = 4
    BarLookBack = PivotBAR + 1
    //IF myrsi[PivotBAR] < lowest[LookBack](myrsi)[BarLookBack] THEN
    //IF myrsi[PivotBAR] = lowest[BarLookBack](myrsi) THEN
    //PrevSupp3       = PrevSupp2
    //PrevSuppRSI3  = PrevSuppRSI2
    //PrevSupp2       = PrevSupp1
    //PrevSuppRSI2  = PrevSuppRSI1
    //PrevSupp1       = PrevSupp
    //PrevSuppRSI1  = PrevSuppRSI
    //PrevSupp        = MySupport
    //PrevSuppRSI   = SupportRSI
    //MySupport       = BarIndex - PivotBAR
    //SupportRSI    = myrsi[PivotBAR]
    //ENDIF
    //ENDIF
    IF myrsi[PivotBAR] > highest[LookBack](myrsi)[BarLookBack] and myrsi[PivotBar]>48 THEN
    IF myrsi[PivotBAR]  = highest[BarLookBack](myrsi) THEN
    Index4              = Index3
    RSI4                  = RSI3
    Pricepoint4           =Pricepoint3
    
    
    Index3              = Index2
    RSI3                  = RSI2
    Pricepoint3           =Pricepoint2
    
    
    Index2              = Index1
    RSI2                  = RSI1
    Pricepoint2           =Pricepoint1
    
    Index1               = Index0
    RSI1                  = RSI0
    Pricepoint1           = Pricepoint0
    
    Index0          = BarIndex - PivotBAR
    RSI0                  = myrsi[PivotBAR]
    Pricepoint0           = high[PivotBAR]
    
    
    
    //Slope = (PrevResRSI-RSI0)/(Index0-PrevRes)
    //y = PrevResRSI-((barindex-PrevRes)*Slope)
    
    ENDIF
    endif
    
    
    If Pricepoint0<Pricepoint1 and RSI0>RSI1 and ya then
    DRAWSEGMENT(Index1,RSI1,Index0,RSI0) COLOURED(0,0,255) //Diagonal frm 1-0
    Slope = (RSI0-RSI1)/(Index0-Index1)
    y = RSI1+((barindex-Index1)*Slope)
    else
    y=0
    endif
    
    if Pricepoint0<Pricepoint2 and RSI0>RSI2 and yb then
    DRAWSEGMENT(Index2,RSI2,Index0,RSI0) COLOURED(0,0,255)//Diagonal from 2-0
    Slope2 = (RSI0-RSI2)/(Index0-Index2)
    y2 = RSI2+((barindex-Index2)*Slope2)
    else
    y2=0
    endif
    
    if Pricepoint0<Pricepoint3 and RSI0>RSI3 and yc then
    DRAWSEGMENT(Index3,RSI3,Index0,RSI0) COLOURED(0,0,255)//Diagonal from 3-0
    Slope3 = (RSI0-RSI3)/(Index0-Index3)
    y3 = RSI3+((barindex-Index3)*Slope3)
    else
    y3 = 0
    endif
    
    if Pricepoint0<Pricepoint4 and RSI0>RSI4 and yd then
    DRAWSEGMENT(Index4,RSI4,Index0,RSI0) COLOURED(0,0,255)//Diagonal from 4-0
    Slope4 = (RSI0-RSI4)/(Index0-Index4)
    y4 = RSI4+((barindex-Index4)*Slope4)
    else
    y4=0
    endif
    
    RETURN Slope2 as "slope", y2 as "y" style(line,1)COLOURED(255,0,0)//y as "ya", y2 as "yb", y3 as "yc", y4 as "yd"
    
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Slope issues with divergence indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 voice and has 0 replies.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/06/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...