March 22, 2018 at 2:48 am #45539
Divergences between the trend of prices and an indicator are often used as a signal for a change in price trend:
Positive (Bullish) Divergence: prices are falling but the indicator is rising
Negative (Bearish) Divergence: prices are rising but the indicator is falling
This example compares RSI values at their highs with the closing price of the stock at the time of those highs. If the RSI high is lower than the previous high but the price is higher between those points then it gives a signal for negative divergence.
This example uses a 10 bar pivot for the RSI(14) ie there are at least 10 lower days either side (this can be increased – the higher the number the more important the peak).12345678910111213141516//Negative RSI divergenceRSI1 = RSI(BARS=14);//calculate 10 pivot RSI highP1 = PIVOT(RSI1, MIN=10, TYPE=High);//get value of the RSI peakV1 = VALUEWHEN(RSI1, P1 <> 0);//Is RSI high < previous>?Sig1 = V1 < V1;//get stock value at RSI peakV2 = VALUEWHEN(Close(), P1 <> 0);//Is stock price higher than at previous RSI peak?Sig2 = V2 > V2;//Show when RSI has lower high & price higher lowSig1 and Sig2
For positive divergence:1234567891011//Positive RSI DivergenceRSI1 = RSI(BARS=14);P1 = PIVOT(RSI1, MIN=10, TYPE=Low);V1 = VALUEWHEN(RSI1, P1 <> 0);Sig1 = V1 > V1;V2 = VALUEWHEN(Close(), P1 <> 0);Sig2 = V2 < V2;//Show when RSI is higher low and price lower highSig1 and Sig2
As in this example, use the above in two separate Show View tools and drag one over the other to display the signals:
At point B the RSI peak is lower than A, but the share price is higher (negative divergence), whereas at point D the RSI low is higher than at C but the share price is lower (positive divergence).
May 5, 2018 at 12:26 pm #46779Luke
- This topic was modified 1 year ago by Darren.
- Topics: 3
- Replies: 3
- Posts: 6
Hi Darren, what show bar scripts are you using on the RSI indicator to create the arrows?May 8, 2018 at 7:11 pm #46815Luke
- Topics: 3
- Replies: 3
- Posts: 6
Also why does this script not return any results for a daily scan of last bar but shows results one day after? ThanksMay 9, 2018 at 2:37 am #46819
The scripts used are in the initial post.
Because the scripts use pivot levels we have to wait until the pivot is confirmed so there will always be a delay. Do you have an example?July 19, 2019 at 12:34 am #5407712345678910111213141516//Negative OBV divergenceOSC1 = OBV();//calculate 15 pivot OBV highP1 = PIVOT(OSC1, MIN=15, TYPE=High);//get value of the OBV peakV1 = VALUEWHEN(OSC1, P1 <> 0);//Is OBV high < previous?Sig1 = V1 < V1*0.96;//get stock high value at OBV peakV2 = VALUEWHEN(HIGH(), P1 <> 0);//Is stock high higher than at previous OBV peak?Sig2 = V2 > V2*1.04;//Show when OBV has lower high & price higher lowSig1 and Sig2April 11, 2020 at 3:26 pm #57607Karen
- Topics: 16
- Replies: 25
- Posts: 41
I’m trying to get the vertical green and red bars over the RSI indicator as opposed to having a separate show view for the Positive and Negative Divergences. Is this possible?
Please see attached workbook which shows that different result are obtained. Can you please assist with this.
You must be logged in to access attached files.April 11, 2020 at 9:46 pm #57625Mandeep
- Topics: 37
- Replies: 18
- Posts: 55
On the back of your signal test above – can you please confirm the Pivot() function is now ok to use to support signal / backtesting. Last time I checked I found that it looks ahead of time and cheats.
MandeepMay 6, 2020 at 8:21 pm #57989
You should not use the Pivot() function in any tests, because future data coming in can affect the position of previous labels, thus making the tests unrealistic.
- You must be logged in to reply to this topic.