Divergence on RSI with Bollinger Band
Forums › ProRealTime English forum › ProBuilder support › Divergence on RSI with Bollinger Band
- This topic has 16 replies, 4 voices, and was last updated 4 years ago by Nicolas.
Tagged: bands, Bollinger, divergences, drawarrowdown, drawarrowup, drawsegment
-
-
07/22/2019 at 2:43 PM #103117
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).
Divergence required to be printed123456789ZMYR = RSI[21](close)ZSR = RSI[2](ZMYR)-50M=wilderAVERAGE[18](ZSR)SD=STD[18](ZSR)UB=M+1.2*SDLB=M-1.2*SDReturn zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"07/31/2019 at 1:07 PM #103876Hello,
Anyone up for the challenge?
Regards,
07/31/2019 at 4:58 PM #103900I think that your description is upside down.. Or is it me? Well, here is the code I made from what I understood from it:
12345678910111213141516171819202122232425262728293031323334353637ZMYR = RSI[21](close)ZSR = RSI[2](ZMYR)-50M=wilderAVERAGE[18](ZSR)SD=STD[18](ZSR)UB=M+1.2*SDLB=M-1.2*SD//troughtrough=zsr>zsr[1] and zsr[1]<zsr[2]////osc reset//if zsr>lb then//oscLL=1000//endif//oscillator belowif zsr[1]<lb thenif trough and zsr[1]<oscll thenoscll=zsr[1]oscbar=barindex[1]endifendif//osc above lbbif zsr>lb then//troughif trough thenif low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 thendrawarrowup(barindex[1],zsr[1]) coloured(0,255,0)oscbar=0oscll=1000endifendifendifReturn zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"08/01/2019 at 5:27 AM #103919Many 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,
08/01/2019 at 7:45 AM #103931You 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.
123456789101112131415161718192021222324252627282930313233343536373839ZMYR = RSI[21](close)ZSR = RSI[2](ZMYR)-50M=wilderAVERAGE[18](ZSR)SD=STD[18](ZSR)UB=M+1.2*SDLB=M-1.2*SD//troughtrough=zsr>zsr[1] and zsr[1]<zsr[2]//reset on new crossif zsr crosses under lb thenoscbar=0oscll=1000endif//oscillator belowif zsr[1]<lb thenif trough and zsr[1]<=oscll thenoscll=zsr[1]oscbar=barindex[1]endifendif//osc above lbbif zsr>lb then//troughif trough thenif low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 thendrawarrowup(barindex[1],zsr[1]) coloured(0,255,0)drawsegment(oscbar,oscll,barindex[1],zsr[1]) coloured(0,255,0)oscbar=0oscll=1000endifendifendifReturn zsr as "MOMENTUM", ub as "OverBought", lb as "OverSold"08/02/2019 at 7:26 AM #104009Hello 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,
08/02/2019 at 8:19 AM #104013Here is the complete version that include the bullish and bearish divergences.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071ZMYR = RSI[21](close)ZSR = RSI[2](ZMYR)-50M=wilderAVERAGE[18](ZSR)SD=STD[18](ZSR)UB=M+1.2*SDLB=M-1.2*SD//bullish divergences//troughtrough=zsr>zsr[1] and zsr[1]<zsr[2]//reset on new crossif zsr crosses under lb thenoscbar=0oscll=1000endif//oscillator belowif zsr[1]<lb thenif trough and zsr[1]<=oscll thenoscll=zsr[1]oscbar=barindex[1]endifendif//osc above lbbif zsr>lb then//troughif trough thenif low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 thendrawarrowup(barindex[1],zsr[1]) coloured(69,139,116)drawsegment(oscbar,oscll,barindex[1],zsr[1]) coloured(69,139,116)oscbar=0oscll=1000endifendifendif//bearish divergences//peakpeak=zsr<zsr[1] and zsr[1]>zsr[2]//reset on new crossif zsr crosses over UB thenoscbarr=0oschh=0endif//oscillator aboveif zsr[1]>UB thenif peak and zsr[1]>=oschh thenoschh=zsr[1]oscbarr=barindex[1]endifendif//osc below ubif zsr<ub then//peakif peak thenif high[1]>high[barindex-oscbarr] and zsr[1]<oscHH and oscbarr>0 thendrawarrowdown(barindex[1],zsr[1]) coloured(255,0,0)drawsegment(oscbarr,oschh,barindex[1],zsr[1]) coloured(255,0,0)oscbarr=0oschh=0endifendifendifReturn 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"08/02/2019 at 10:32 AM #104023Many many thanks dear Nicolas.
Much appreciate your fast and reliable response, as always.
Its all fine now.
Best regards,
08/02/2019 at 1:25 PM #104044Hello 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,
08/02/2019 at 2:02 PM #104048Try this. It returns a 1 for a buy signal and a -1 for a sell signal.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071ZMYR = RSI[21](close)ZSR = RSI[2](ZMYR)-50M=wilderAVERAGE[18](ZSR)SD=STD[18](ZSR)UB=M+1.2*SDLB=M-1.2*SDresult = 0//bullish divergences//troughtrough=zsr>zsr[1] and zsr[1]<zsr[2]//reset on new crossif zsr crosses under lb thenoscbar=0oscll=1000endif//oscillator belowif zsr[1]<lb thenif trough and zsr[1]<=oscll thenoscll=zsr[1]oscbar=barindex[1]endifendif//osc above lbbif zsr>lb then//troughif trough thenif low[1]<low[barindex-oscbar] and zsr[1]>oscLL and oscbar>0 thenresult = 1oscbar=0oscll=1000endifendifendif//bearish divergences//peakpeak=zsr<zsr[1] and zsr[1]>zsr[2]//reset on new crossif zsr crosses over UB thenoscbarr=0oschh=0endif//oscillator aboveif zsr[1]>UB thenif peak and zsr[1]>=oschh thenoschh=zsr[1]oscbarr=barindex[1]endifendif//osc below ubif zsr<ub then//peakif peak thenif high[1]>high[barindex-oscbarr] and zsr[1]<oscHH and oscbarr>0 thenresult = -1oscbarr=0oschh=0endifendifendifReturn result08/02/2019 at 2:37 PM #104050Hello 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,
08/02/2019 at 2:48 PM #10405308/02/2019 at 2:48 PM #10405408/03/2019 at 7:02 AM #104072Many thanks Vonasi.
Much appreciate your time, effort and helping attitude.
Thank you again for your prompt response.
Regards,
08/03/2019 at 7:02 AM #104073Yes Nicolas. You are correct.
-
AuthorPosts
Find exclusive trading pro-tools on