{"id":40,"date":"2007-07-17T18:54:44","date_gmt":"2007-07-17T23:54:44","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2007\/07\/17\/how-to-detect-the-divergences\/"},"modified":"2014-12-04T08:30:43","modified_gmt":"2014-12-04T13:30:43","slug":"how-to-detect-the-divergences","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2007\/07\/17\/how-to-detect-the-divergences\/","title":{"rendered":"How to detect the divergences"},"content":{"rendered":"

There are many different ways to check for divergences. One of the simplest is to use Rate of change<\/strong> indicator and EXPLORATION<\/strong> feature of Automatic Analysis window:<\/p>

– Analysis -> Formula Editor
– enter:
\u00a0
<\/span>\/\/ 5 day rate of change of close
<\/span>PriceUp <\/span>= <\/span>ROC<\/span>( <\/span>C<\/span>, <\/span>5 <\/span>) > <\/span>0 <\/span>;
<\/span>\/\/ 5 day rate of change of MACD histogram
<\/span>MacdUP <\/span>= <\/span>ROC<\/span>( <\/span>MACD<\/span>() - <\/span>Signal<\/span>(), <\/span>5 <\/span>) > <\/span>0<\/span>;
<\/span>BullishDiv <\/span>= <\/span>NOT PriceUP <\/span>AND <\/span>MACDUp<\/span>;
<\/span>BearishDiv <\/span>= <\/span>PriceUP <\/span>AND <\/span>NOT MACDUp<\/span>;
<\/span>Filter <\/span>= <\/span>BullishDiv <\/span>OR <\/span>BearishDiv<\/span>;
<\/span>AddColumn<\/span>( <\/span>BullishDiv<\/span>, <\/span>"Bullish Divergence"<\/span>, <\/span>1.0<\/span>,
       <\/span>colorDefault<\/span>, <\/span>IIf<\/span>(<\/span>BullishDiv<\/span>, <\/span>colorGreen<\/span>, <\/span>colorDefault <\/span>) );<\/span>\u00a0
AddColumn<\/span>( <\/span>BearishDiv <\/span>, <\/span>"Bearish Divergence"<\/span>, <\/span>1.0<\/span>,
       <\/span>colorDefault<\/span>, <\/span>IIf<\/span>(<\/span>BearishDiv <\/span>, <\/span>colorRed<\/span>, <\/span>colorDefault<\/span>) )<\/code>

– Tools -> Send to Auto-analysis
– Apply to: All Symbols, N last quotations = 1
– press EXPLORE<\/p>

Tools -> Send to Auto-analysis- Apply to: All Symbols, N last quotations = 1- press EXPLORE<\/p>

A different approach can use linear regression instead:
\u00a0
<\/span>\/\/ 10 day linear regression slope of close
<\/span>PriceUp <\/span>= <\/span>LinRegSlope<\/span>( <\/span>C<\/span>, <\/span>10 <\/span>) > <\/span>0 <\/span>;
<\/span>\/\/ 10 day linear regression slope of MACD histogram
<\/span>MacdUP <\/span>= <\/span>LinRegSlope<\/span>( <\/span>MACD<\/span>() - <\/span>Signal<\/span>(), <\/span>10 <\/span>); <\/code>

\u00a0<\/p>","protected":false},"excerpt":{"rendered":"

There are many different ways to check for divergences. One of the simplest is to use Rate of change indicator and EXPLORATION feature of Automatic Analysis window:– Analysis -> Formula Editor– enter:\u00a0\/\/ 5 day rate of change of closePriceUp = ROC( C, 5 ) > 0 ;\/\/ 5 day rate of change of MACD histogramMacdUP = ROC( MACD() – Signal(), 5 ) > 0;BullishDiv = NOT PriceUP AND MACDUp;BearishDiv = PriceUP AND NOT MACDUp;Filter = BullishDiv OR BearishDiv;AddColumn( BullishDiv, "Bullish Divergence", 1.0,       colorDefault, IIf(BullishDiv, colorGreen, colorDefault ) );\u00a0AddColumn( BearishDiv , "Bearish Divergence", 1.0,       colorDefault, IIf(BearishDiv , colorRed, colorDefault) )– Tools -> Send to Auto-analysis– Apply to: All Symbols, N last quotations = 1– press EXPLORETools -> Send to Auto-analysis- Apply to: All […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[53,55],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/40"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":808,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/40\/revisions\/808"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}