How to calculate positive and negative divergences

Optuma Forums Optuma Scripting How to calculate positive and negative divergences

This topic contains 5 replies, has 3 voices, and was last updated by  Steve 1 month, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45539
    Darren
    Darren
    • Topics: 23
    • Replies: 94
    • Posts: 117

    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).

    //Negative RSI divergence
    RSI1 = RSI(BARS=14);
    //calculate 10 pivot RSI high
    P1 = PIVOT(RSI1, MIN=10, TYPE=High);
    //get value of the RSI peak
    V1 = VALUEWHEN(RSI1, P1 <> 0);
    //Is RSI high < previous>?
    Sig1 = V1 < V1[1];
    //get stock value at RSI peak
    V2 = VALUEWHEN(Close(), P1 <> 0);
    //Is stock price higher than at previous RSI peak?
    Sig2 = V2 > V2[1];
    //Show when both conditions are true
    Sig1 and Sig2

    For positive divergence:

    //Positive RSI Divergence
    RSI1 = RSI(BARS=14);
    P1 = PIVOT(RSI1, MIN=10, TYPE=Low);
    V1 = VALUEWHEN(RSI1, P1 <> 0);
    Sig1 = V1 > V1[1];
    V2 = VALUEWHEN(Close(), P1 <> 0);
    Sig2 = V2 < V2[1];
    Sig1 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:

    Capture

    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).

     

     

    #46779

    Luke
    • Topics: 0
    • Replies: 3
    • Posts: 3

    Hi Darren, what show bar scripts are you using on the RSI indicator to create the arrows?

    #46815

    Luke
    • Topics: 0
    • Replies: 3
    • Posts: 3

    Also why does this script not return any results for a daily scan of last bar but shows results one day after? Thanks

    #46819
    Darren
    Darren
    • Topics: 23
    • Replies: 94
    • Posts: 117

    Hi Luke,

    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?

    #46827

    Luke
    • Topics: 0
    • Replies: 3
    • Posts: 3

    Hi Darren

    When I scan last bar at EOD or following day the scan produces nil results. But when I scan a couple of days later with a larger range results appear for the original last bar date. 

    Thanks

    #46839

    Steve
    • Topics: 0
    • Replies: 1
    • Posts: 1

    I’ve been trying to apply this technique to show divergence between price and the non lag inverse fisher transform of RSX.

    I’ve altered the code as follows:

    //Negative NLRSX divergence
    NL1 = NLRSX(BARS=13, NLBARS=8);
    //calculate 10 pivot NLRSX high
    P1 = PIVOT(NL1, MIN=10, TYPE=High);
    //get value of the NLRSX peak
    V1 = VALUEWHEN(NL1, P1 <> 0);
    //Is NLRSX high < previous>?
    Sig1 = V1 < V1[1];
    //get stock value at NLRSX peak
    V2 = VALUEWHEN(Close(), P1 <> 0);
    //Is stock price higher than at previous NLRSX peak?
    Sig2 = V2 > V2[1];
    //Show when both conditions are true
    Sig1 and Sig2

    On the attached chart, I’m getting a result for divergences between A and B and also C and D, but not that between B and C.

    However when I alter the pivot line to a value of 6, divergence A to B, and B to C is shown, but not C to D.

    What do I need to do in order to have divergences A to B, B to C and C to D show up?

     

    Steve

     

    Attachments:
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

Share This

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close