Divergence on RSI with Bollinger Band

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #103117 quote
    Partha Banerjee
    Participant
    Junior

    Hello, below mentioned (in the code section) is the code for a RSI and its related Bollinger Band (BB). Help is needed for plotting divergence (defined by (1) ZSR (defined in the PRT code) touching LB (defined in the PRT code) and then price going down to make a lower low but ZSR staying above LBB, (2) ZSR touching UB and then price going up to make a higher high but ZSR staying below UBB).

    ZMYR = RSI[21](close)
    ZSR = RSI[2](ZMYR)-50
    
    M=wilderAVERAGE[18](ZSR)
    SD=STD[18](ZSR)
    UB=M+1.2*SD
    LB=M-1.2*SD
    
    Return zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"
    Divergence-required-to-be-printed.jpg Divergence-required-to-be-printed.jpg
    #103876 quote
    Partha Banerjee
    Participant
    Junior

    Hello,

    Anyone up for the challenge?

    Regards,

    #103900 quote
    Nicolas
    Keymaster
    Master

    I think that your description is upside down.. Or is it me? Well, here is the code I made from what I understood from it:

    ZMYR = RSI[21](close)
    ZSR = RSI[2](ZMYR)-50
    
    M=wilderAVERAGE[18](ZSR)
    SD=STD[18](ZSR)
    UB=M+1.2*SD
    LB=M-1.2*SD
    
    //trough
    trough=zsr>zsr[1] and zsr[1]<zsr[2]
    
    ////osc reset
    //if zsr>lb then 
    //oscLL=1000
    //endif
    
    //oscillator below
    if zsr[1]<lb then 
    if trough and zsr[1]<oscll then 
    oscll=zsr[1]
    oscbar=barindex[1]
    endif
    endif
    
    //osc above lbb
    if zsr>lb then 
    //trough
    if trough then 
    if low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 then 
    drawarrowup(barindex[1],zsr[1]) coloured(0,255,0)
    oscbar=0
    oscll=1000
    endif
    endif
    endif
    
    Return zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"
    
    #103919 quote
    Partha Banerjee
    Participant
    Junior

    Many thanks Nicolas. Your time and effort is really appreciated.

    The code is only printing UP arrow for (1) Bullish divergence, however it is not printing DOWN red arrow for (2) Bearish divergence as shown with dates for EURUSD daily chart.

    Also some of the UP Arrows are missing on valid setup as shown with dates for EURUSD daily chart.

    Appreciate the corrected code please.

    Thank you again.

    Best regards,

    Divergence-required-to-be-printed-2.jpg Divergence-required-to-be-printed-2.jpg
    #103931 quote
    Nicolas
    Keymaster
    Master

    You did not mention anything about bearish divergences, that’s why I did not code it..

    Here is a version with some fixes, please confirm bullish version is ok.

    ZMYR = RSI[21](close)
    ZSR = RSI[2](ZMYR)-50
    
    M=wilderAVERAGE[18](ZSR)
    SD=STD[18](ZSR)
    UB=M+1.2*SD
    LB=M-1.2*SD
    
    //trough
    trough=zsr>zsr[1] and zsr[1]<zsr[2]
    
    //reset on new cross
    if zsr crosses under lb then 
    oscbar=0
    oscll=1000
    endif
    
    //oscillator below
    if zsr[1]<lb then
    if trough and zsr[1]<=oscll then
    oscll=zsr[1]
    oscbar=barindex[1]
    endif
    endif
    
    //osc above lbb
    if zsr>lb then
    //trough
    if trough then
    if low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 then
    drawarrowup(barindex[1],zsr[1]) coloured(0,255,0)
    drawsegment(oscbar,oscll,barindex[1],zsr[1]) coloured(0,255,0)
    oscbar=0
    oscll=1000
    endif
    endif
    endif
    
    Return zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"
    
    #104009 quote
    Partha Banerjee
    Participant
    Junior

    Hello Nicolas, many thanks for the fix. the bullish divergence is working fine now.

    I actually mentioned initially for the bearish divergence, although in brief, keeping in mind your coding knowledge level as very high, as well, as, ” (2) ZSR touching UB and then price going up to make a higher high but ZSR staying below UBB). ”

    Appreciate if you can incorporate the the code for bearish divergence please.

    Many thanks.

    Best regards,

    #104013 quote
    Nicolas
    Keymaster
    Master

    Here is the complete version that include the bullish and bearish divergences.

    ZMYR = RSI[21](close)
    ZSR = RSI[2](ZMYR)-50
    
    M=wilderAVERAGE[18](ZSR)
    SD=STD[18](ZSR)
    UB=M+1.2*SD
    LB=M-1.2*SD
    
    //bullish divergences
    //trough
    trough=zsr>zsr[1] and zsr[1]<zsr[2]
    
    //reset on new cross
    if zsr crosses under lb then
    oscbar=0
    oscll=1000
    endif
    
    //oscillator below
    if zsr[1]<lb then
    if trough and zsr[1]<=oscll then
    oscll=zsr[1]
    oscbar=barindex[1]
    endif
    endif
    
    //osc above lbb
    if zsr>lb then
    //trough
    if trough then
    if low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 then
    drawarrowup(barindex[1],zsr[1]) coloured(69,139,116)
    drawsegment(oscbar,oscll,barindex[1],zsr[1]) coloured(69,139,116)
    oscbar=0
    oscll=1000
    endif
    endif
    endif
    
    //bearish divergences
    //peak
    peak=zsr<zsr[1] and zsr[1]>zsr[2]
    
    //reset on new cross
    if zsr crosses over UB then
    oscbarr=0
    oschh=0
    endif
    
    //oscillator above
    if zsr[1]>UB then
    if peak and zsr[1]>=oschh then
    oschh=zsr[1]
    oscbarr=barindex[1]
    endif
    endif
    
    //osc below ub
    if zsr<ub then
    //peak
    if peak then
    if high[1]>high[barindex-oscbarr] and zsr[1]<oscHH and oscbarr>0 then
    drawarrowdown(barindex[1],zsr[1]) coloured(255,0,0)
    drawsegment(oscbarr,oschh,barindex[1],zsr[1]) coloured(255,0,0)
    oscbarr=0
    oschh=0
    endif
    endif
    endif
    
    Return zsr style(line,3) as "MOMENTUM", ub coloured(190,190,190) style(dottedline,2) as "OverBought" , lb coloured(190,190,190) style(dottedline,2) as "OverSold"
    
    divergences-on-rsi-with-bollinger-bands.png divergences-on-rsi-with-bollinger-bands.png
    #104023 quote
    Partha Banerjee
    Participant
    Junior

    Many many thanks dear Nicolas.

    Much appreciate your fast and reliable response, as always.

    Its all fine now.

    Best regards,

    #104044 quote
    Partha Banerjee
    Participant
    Junior

    Hello Nicolas,

    I can not create Alert on this divergence. Is it possible to plot the divergence as value return so that Alert can be set please.

    Your help is much appreciated, Nicolas.

    Best regards,

    #104048 quote
    Vonasi
    Moderator
    Master

    Try this. It returns a 1 for a buy signal and a -1 for a sell signal.

    ZMYR = RSI[21](close)
    ZSR = RSI[2](ZMYR)-50
    
    M=wilderAVERAGE[18](ZSR)
    SD=STD[18](ZSR)
    UB=M+1.2*SD
    LB=M-1.2*SD
    
    result = 0
    
    //bullish divergences
    //trough
    trough=zsr>zsr[1] and zsr[1]<zsr[2]
    
    //reset on new cross
    if zsr crosses under lb then
    oscbar=0
    oscll=1000
    endif
    
    //oscillator below
    if zsr[1]<lb then
    if trough and zsr[1]<=oscll then
    oscll=zsr[1]
    oscbar=barindex[1]
    endif
    endif
    
    //osc above lbb
    if zsr>lb then
    //trough
    if trough then
    if low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 then
    result = 1
    oscbar=0
    oscll=1000
    endif
    endif
    endif
    
    //bearish divergences
    //peak
    peak=zsr<zsr[1] and zsr[1]>zsr[2]
    
    //reset on new cross
    if zsr crosses over UB then
    oscbarr=0
    oschh=0
    endif
    
    //oscillator above
    if zsr[1]>UB then
    if peak and zsr[1]>=oschh then
    oschh=zsr[1]
    oscbarr=barindex[1]
    endif
    endif
    
    //osc below ub
    if zsr<ub then
    //peak
    if peak then
    if high[1]>high[barindex-oscbarr] and zsr[1]<oscHH and oscbarr>0 then
    result = -1
    oscbarr=0
    oschh=0
    endif
    endif
    endif
    
    Return result
    #104050 quote
    Partha Banerjee
    Participant
    Junior

    Hello Vonashi,

    Thank you for your prompt response, however your code is not after Nicolas’s last post which was recent. We have to build an alert on that.

    Your code is not running and giving the enclosed error.

    Regards,

    Div-Alert.jpg Div-Alert.jpg
    #104053 quote
    Vonasi
    Moderator
    Master

    You must have done a bad copy and paste because it works just fine for me. Use the button in the top right of the PRT code window to highlight it all and then hit CTRL+C.

    #104054 quote
    Nicolas
    Keymaster
    Master

    if they are unused, then delete all their references in code, simple as 1.2.3. 😆

    #104072 quote
    Partha Banerjee
    Participant
    Junior

    Many thanks Vonasi.

    Much appreciate your time, effort and helping attitude.

    Thank you again for your prompt response.

    Regards,

    #104073 quote
    Partha Banerjee
    Participant
    Junior

    Yes Nicolas. You are correct.

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

Divergence on RSI with Bollinger Band


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 16 replies,
has 4 voices, and was last updated by Nicolas
5 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/22/2019
Status: Active
Attachments: 4 files
Logo Logo
Loading...