{"id":1625,"date":"2008-03-06T15:37:09","date_gmt":"2008-03-06T15:37:09","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2008\/03\/06\/candle-stick-evaluation-2\/"},"modified":"2008-04-30T22:16:24","modified_gmt":"2008-04-30T22:16:24","slug":"candle-stick-evaluation-2","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2008\/03\/06\/candle-stick-evaluation-2\/","title":{"rendered":"Candle-Stick Evaluation (v2)"},"content":{"rendered":"

This indicator formula allows you to select Candlestick patterns, mark their occurrence on the chart, display their frequency, and test their predictive value. Apply the code to an Indicator, open up the Param window, and drag the CandlePattern# slider left and right to change to a different pattern. The selected pattern is identified in the chart Title text and graphically on your chart by a upwards pointing Blue arrow. The white line on your chart represents the resulting equity (\u201cprofit plot\u201d in the Param window) for the pattern for the selected Profit Period. This line can be turned On or Off in the Param window. Entries (Buy or Short) are at the Close of the Pattern bar. Exits (Sell or Cover) are at the Open and can be delayed up to 10 bars with respect to the entry, as set in the Param window.<\/p>\n

This code was originally written many years ago and was revised to take advantage of newer AFL functions. Also, code has been added to allow you to Backtest and Optimize to find the best pattern, delay, and trading mode. Note that trading mode “1” in the optimizer report indicates Long trades, a “0” indicates Short trades. Red Arrows are either Sell or Short, Green Arrows are either Buy or Cover, depending on your Mode selection. The chart below shows how typical CandlePatterns are identified: <\/p>\n

 
\n\"\"<\/a>
\n<\/p>\n

Try different tickers; they will all behave differently. Only basic stats are provided in the chart Title, please add your own price patterns and metrics. <\/p>\n

<\/span>function <\/span>ParamOptimize<\/span>( <\/span>description<\/span>, <\/span>defaultVal<\/span>, <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>)\r{\r    return <\/span>Optimize<\/span>( <\/span>description<\/span>, <\/span>Param<\/span>( <\/span>description<\/span>, <\/span>defaultVal<\/span>, <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>), <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>);\r}\r \r<\/span>O1 <\/span>= <\/span>Ref<\/span>(<\/span>O<\/span>,-<\/span>1<\/span>);<\/span>O2 <\/span>= <\/span>Ref<\/span>(<\/span>O<\/span>,-<\/span>2<\/span>);  \r<\/span>H1 <\/span>= <\/span>Ref<\/span>(<\/span>H<\/span>,-<\/span>1<\/span>);<\/span>H2 <\/span>= <\/span>Ref<\/span>(<\/span>H<\/span>,-<\/span>2<\/span>);  \r<\/span>L1 <\/span>= <\/span>Ref<\/span>(<\/span>L<\/span>,-<\/span>1<\/span>);<\/span>L2 <\/span>= <\/span>Ref<\/span>(<\/span>L<\/span>,-<\/span>2<\/span>);  \r<\/span>C1 <\/span>= <\/span>Ref<\/span>(<\/span>C<\/span>,-<\/span>1<\/span>);<\/span>C2 <\/span>= <\/span>Ref<\/span>(<\/span>C<\/span>,-<\/span>2<\/span>);  \rfunction <\/span>CandlePattern<\/span>(<\/span>P<\/span>)  \r{  \rglobal <\/span>PatternName<\/span>;  \rif(<\/span>P <\/span>== <\/span>0<\/span>) { <\/span>PatternName <\/span>= <\/span>"NearDoji"<\/span>; <\/span>Pv <\/span>= (<\/span>abs<\/span>(<\/span>O<\/span>-<\/span>C<\/span>)<= ((<\/span>H<\/span>-<\/span>L<\/span>)*<\/span>0.1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>1<\/span>) { <\/span>PatternName <\/span>= <\/span>"BlackCandle"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>2<\/span>) { <\/span>PatternName <\/span>= <\/span>"LongBlackCandle"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C <\/span>AND (<\/span>O<\/span>-<\/span>C<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>.6<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>3<\/span>) { <\/span>PatternName <\/span>= <\/span>"SmallBlackCandle"<\/span>; <\/span>Pv <\/span>= ((<\/span>O<\/span>><\/span>C<\/span>) AND ((<\/span>H<\/span>-<\/span>L<\/span>)>(<\/span>3<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>)))); }  \relse if(<\/span>P <\/span>== <\/span>4<\/span>) { <\/span>PatternName <\/span>= <\/span>"WhiteCandle"<\/span>; <\/span>Pv <\/span>= (<\/span>C<\/span>><\/span>O<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>5<\/span>) { <\/span>PatternName <\/span>= <\/span>"LongWhiteCandle"<\/span>; <\/span>Pv <\/span>= ((<\/span>C<\/span>><\/span>O<\/span>) AND ((<\/span>C<\/span>-<\/span>O<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>.6<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>6<\/span>) { <\/span>PatternName <\/span>= <\/span>"SmallWhiteCandle"<\/span>; <\/span>Pv <\/span>= ((<\/span>C<\/span>><\/span>O<\/span>) AND ((<\/span>H<\/span>-<\/span>L<\/span>)>(<\/span>3<\/span>*(<\/span>C<\/span>-<\/span>O<\/span>)))); }  \relse if(<\/span>P <\/span>== <\/span>7<\/span>) { <\/span>PatternName <\/span>= <\/span>"BlackMaubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C <\/span>AND <\/span>H<\/span>==<\/span>O <\/span>AND <\/span>C<\/span>==<\/span>L<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>8<\/span>) { <\/span>PatternName <\/span>= <\/span>"WhiteMaubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>C<\/span>><\/span>O <\/span>AND <\/span>H<\/span>==<\/span>C <\/span>AND <\/span>O<\/span>==<\/span>L<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>9<\/span>) { <\/span>PatternName <\/span>= <\/span>"BlackClosingMarubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C <\/span>AND <\/span>C<\/span>==<\/span>L<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>10<\/span>) { <\/span>PatternName <\/span>= <\/span>"WhiteClosingMarubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>C<\/span>><\/span>O <\/span>AND <\/span>C<\/span>==<\/span>H<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>11<\/span>) { <\/span>PatternName <\/span>= <\/span>"BlackOpeningMarubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C <\/span>AND <\/span>O<\/span>==<\/span>H<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>12<\/span>) { <\/span>PatternName <\/span>= <\/span>"WhiteOpeningMarubozu"<\/span>; <\/span>Pv <\/span>= (<\/span>C<\/span>><\/span>O <\/span>AND <\/span>O<\/span>==<\/span>L<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>13<\/span>) { <\/span>PatternName <\/span>= <\/span>"HangingMan"<\/span>; <\/span>Pv <\/span>= (((<\/span>H<\/span>-<\/span>L<\/span>)><\/span>4<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>)) AND ((<\/span>C<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)>= <\/span>0.75<\/span>) AND ((<\/span>O<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)>= <\/span>0.75<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>14<\/span>) { <\/span>PatternName <\/span>= <\/span>"Hammer"<\/span>; <\/span>Pv <\/span>= (((<\/span>H<\/span>-<\/span>L<\/span>)><\/span>3<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>)) AND ((<\/span>C<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>0.6<\/span>) AND ((<\/span>O<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>0.6<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>15<\/span>) { <\/span>PatternName <\/span>= <\/span>"InvertedHammer"<\/span>; <\/span>Pv <\/span>= (((<\/span>H<\/span>-<\/span>L<\/span>)><\/span>3<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>)) AND ((<\/span>H<\/span>-<\/span>C<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>0.6<\/span>) AND ((<\/span>H<\/span>-<\/span>O<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)><\/span>0.6<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>16<\/span>) { <\/span>PatternName <\/span>= <\/span>"ShootingStar"<\/span>; <\/span>Pv <\/span>= (((<\/span>H<\/span>-<\/span>L<\/span>)><\/span>4<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>)) AND ((<\/span>H<\/span>-<\/span>C<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)>= <\/span>0.75<\/span>) AND ((<\/span>H<\/span>-<\/span>O<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>)>= <\/span>0.75<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>17<\/span>) { <\/span>PatternName <\/span>= <\/span>"BlackSpinningTop"<\/span>; <\/span>Pv <\/span>= ((<\/span>O<\/span>><\/span>C<\/span>) AND ((<\/span>H<\/span>-<\/span>L<\/span>)>(<\/span>3<\/span>*(<\/span>O<\/span>-<\/span>C<\/span>))) AND (((<\/span>H<\/span>-<\/span>O<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.4<\/span>) AND (((<\/span>C<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.4<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>18<\/span>) { <\/span>PatternName <\/span>= <\/span>"WhiteSpinningTop"<\/span>; <\/span>Pv <\/span>= ((<\/span>C<\/span>><\/span>O<\/span>) AND ((<\/span>H<\/span>-<\/span>L<\/span>)>(<\/span>3<\/span>*(<\/span>C<\/span>-<\/span>O<\/span>))) AND (((<\/span>H<\/span>-<\/span>C<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.4<\/span>) AND (((<\/span>O<\/span>-<\/span>L<\/span>)\/(<\/span>.001<\/span>+<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.4<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>19<\/span>) { <\/span>PatternName <\/span>= <\/span>"BearishAbandonedBaby"<\/span>; <\/span>Pv <\/span>= ((<\/span>C1 <\/span>== <\/span>O1<\/span>) AND (<\/span>C2<\/span>><\/span>O2<\/span>) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>L1<\/span>><\/span>H2<\/span>) AND (<\/span>L1<\/span>><\/span>H<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>20<\/span>) { <\/span>PatternName <\/span>= <\/span>"BearishEveningDojiStar"<\/span>; <\/span>Pv <\/span>= ((<\/span>C2<\/span>><\/span>O2<\/span>) AND ((<\/span>C2<\/span>-<\/span>O2<\/span>)\/(<\/span>.001<\/span>+<\/span>H2<\/span>-<\/span>L2<\/span>)><\/span>.6<\/span>) AND (<\/span>C2<\/span><<\/span>O1<\/span>) AND (<\/span>C1<\/span>><\/span>O1<\/span>) AND ((<\/span>H1<\/span>-<\/span>L1<\/span>)>(<\/span>3<\/span>*(<\/span>C1<\/span>-<\/span>O1<\/span>))) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>O<\/span><<\/span>O1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>21<\/span>) { <\/span>PatternName <\/span>= <\/span>"DarkCloudCover"<\/span>; <\/span>Pv <\/span>= (<\/span>C1<\/span>><\/span>O1 <\/span>AND ((<\/span>C1<\/span>+<\/span>O1<\/span>)\/<\/span>2<\/span>)><\/span>C <\/span>AND <\/span>O<\/span>><\/span>C <\/span>AND <\/span>O<\/span>><\/span>C1 <\/span>AND <\/span>C<\/span>><\/span>O1 <\/span>AND (<\/span>O<\/span>-<\/span>C<\/span>)\/(<\/span>.001<\/span>+(<\/span>H<\/span>-<\/span>L<\/span>)><\/span>0.6<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>22<\/span>) { <\/span>PatternName <\/span>= <\/span>"BearishEngulfing"<\/span>; <\/span>Pv <\/span>= ((<\/span>C1<\/span>><\/span>O1<\/span>) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>O<\/span>>= <\/span>C1<\/span>) AND (<\/span>O1<\/span>>= <\/span>C<\/span>) AND ((<\/span>O<\/span>-<\/span>C<\/span>)>(<\/span>C1<\/span>-<\/span>O1<\/span>))); }  \relse if(<\/span>P <\/span>== <\/span>23<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeOutsideDownPattern"<\/span>; <\/span>Pv <\/span>= ((<\/span>C2<\/span>><\/span>O2<\/span>) AND (<\/span>O1<\/span>><\/span>C1<\/span>) AND (<\/span>O1<\/span>>= <\/span>C2<\/span>) AND (<\/span>O2<\/span>>= <\/span>C1<\/span>) AND ((<\/span>O1<\/span>-<\/span>C1<\/span>)>(<\/span>C2<\/span>-<\/span>O2<\/span>)) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>C<\/span><<\/span>C1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>24<\/span>) { <\/span>PatternName <\/span>= <\/span>"BullishAbandonedBaby"<\/span>; <\/span>Pv <\/span>= ((<\/span>C1 <\/span>== <\/span>O1<\/span>) AND (<\/span>O2<\/span>><\/span>C2<\/span>) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>L2<\/span>><\/span>H1<\/span>) AND (<\/span>L<\/span>><\/span>H1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>25<\/span>) { <\/span>PatternName <\/span>= <\/span>"BullishMorningDojiStar"<\/span>; <\/span>Pv <\/span>= ((<\/span>O2<\/span>><\/span>C2<\/span>) AND ((<\/span>O2<\/span>-<\/span>C2<\/span>)\/(<\/span>.001<\/span>+<\/span>H2<\/span>-<\/span>L2<\/span>)><\/span>.6<\/span>) AND (<\/span>C2<\/span>><\/span>O1<\/span>) AND (<\/span>O1<\/span>><\/span>C1<\/span>) AND ((<\/span>H1<\/span>-<\/span>L1<\/span>)>(<\/span>3<\/span>*(<\/span>C1<\/span>-<\/span>O1<\/span>))) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>O<\/span>><\/span>O1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>26<\/span>) { <\/span>PatternName <\/span>= <\/span>"BullishEngulfing"<\/span>; <\/span>Pv <\/span>= ((<\/span>O1<\/span>><\/span>C1<\/span>) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>C<\/span>>= <\/span>O1<\/span>) AND (<\/span>C1<\/span>>= <\/span>O<\/span>) AND ((<\/span>C<\/span>-<\/span>O<\/span>)>(<\/span>O1<\/span>-<\/span>C1<\/span>))); }  \relse if(<\/span>P <\/span>== <\/span>27<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeOutsideUpPattern"<\/span>; <\/span>Pv <\/span>= ((<\/span>O2<\/span>><\/span>C2<\/span>) AND (<\/span>C1<\/span>><\/span>O1<\/span>) AND (<\/span>C1<\/span>>= <\/span>O2<\/span>) AND (<\/span>C2<\/span>>= <\/span>O1<\/span>) AND ((<\/span>C1<\/span>-<\/span>O1<\/span>)>(<\/span>O2<\/span>-<\/span>C2<\/span>)) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>C<\/span>><\/span>C1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>28<\/span>) { <\/span>PatternName <\/span>= <\/span>"BullishHarami"<\/span>; <\/span>Pv <\/span>= ((<\/span>O1<\/span>><\/span>C1<\/span>) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>C<\/span><= <\/span>O1<\/span>) AND (<\/span>C1<\/span><= <\/span>O<\/span>) AND ((<\/span>C<\/span>-<\/span>O<\/span>)<(<\/span>O1<\/span>-<\/span>C1<\/span>))); }  \relse if(<\/span>P <\/span>== <\/span>29<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeInsideUpPattern"<\/span>; <\/span>Pv <\/span>= ((<\/span>O2<\/span>><\/span>C2<\/span>) AND (<\/span>C1<\/span>><\/span>O1<\/span>) AND (<\/span>C1<\/span><= <\/span>O2<\/span>) AND (<\/span>C2<\/span><= <\/span>O1<\/span>) AND ((<\/span>C1<\/span>-<\/span>O1<\/span>)<(<\/span>O2<\/span>-<\/span>C2<\/span>)) AND (<\/span>C<\/span>><\/span>O<\/span>) AND (<\/span>C<\/span>><\/span>C1<\/span>) AND (<\/span>O<\/span>><\/span>O1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>30<\/span>) { <\/span>PatternName <\/span>= <\/span>"PiercingLine"<\/span>; <\/span>Pv <\/span>= ((<\/span>C1<\/span><<\/span>O1<\/span>) AND (((<\/span>O1<\/span>+<\/span>C1<\/span>)\/<\/span>2<\/span>)<<\/span>C<\/span>) AND (<\/span>O<\/span><<\/span>C<\/span>) AND (<\/span>O<\/span><<\/span>C1<\/span>) AND (<\/span>C<\/span><<\/span>O1<\/span>) AND ((<\/span>C<\/span>-<\/span>O<\/span>)\/(<\/span>.001<\/span>+(<\/span>H<\/span>-<\/span>L<\/span>))><\/span>0.6<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>31<\/span>) { <\/span>PatternName <\/span>= <\/span>"BearishHarami"<\/span>; <\/span>Pv <\/span>= ((<\/span>C1<\/span>><\/span>O1<\/span>) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>O<\/span><= <\/span>C1<\/span>) AND (<\/span>O1<\/span><= <\/span>C<\/span>) AND ((<\/span>O<\/span>-<\/span>C<\/span>)<(<\/span>C1<\/span>-<\/span>O1<\/span>))); }  \relse if(<\/span>P <\/span>== <\/span>32<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeInsideDownPattern"<\/span>; <\/span>Pv <\/span>= ((<\/span>C2<\/span>><\/span>O2<\/span>) AND (<\/span>O1<\/span>><\/span>C1<\/span>) AND (<\/span>O1<\/span><= <\/span>C2<\/span>) AND (<\/span>O2<\/span><= <\/span>C1<\/span>) AND ((<\/span>O1<\/span>-<\/span>C1<\/span>)<(<\/span>C2<\/span>-<\/span>O2<\/span>)) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>C<\/span><<\/span>C1<\/span>) AND (<\/span>O<\/span><<\/span>O1<\/span>)); }  \relse if(<\/span>P <\/span>== <\/span>33<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeWhiteSoldiers"<\/span>; <\/span>Pv <\/span>= (<\/span>C<\/span>><\/span>O<\/span>*<\/span>1.01<\/span>) AND (<\/span>C1<\/span>><\/span>O1<\/span>*<\/span>1.01<\/span>) AND (<\/span>C2<\/span>><\/span>O2<\/span>*<\/span>1.01<\/span>) AND (<\/span>C<\/span>><\/span>C1<\/span>) AND (<\/span>C1<\/span>><\/span>C2<\/span>) AND (<\/span>O<\/span><<\/span>C1<\/span>) AND (<\/span>O<\/span>><\/span>O1<\/span>) AND (<\/span>O1<\/span><<\/span>C2<\/span>) AND (<\/span>O1<\/span>><\/span>O2<\/span>) AND (((<\/span>H<\/span>-<\/span>C<\/span>)\/(<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.2<\/span>) AND (((<\/span>H1<\/span>-<\/span>C1<\/span>)\/(<\/span>H1<\/span>-<\/span>L1<\/span>))<<\/span>.2<\/span>) AND (((<\/span>H2<\/span>-<\/span>C2<\/span>)\/(<\/span>H2<\/span>-<\/span>L2<\/span>))<<\/span>.2<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>34<\/span>) { <\/span>PatternName <\/span>= <\/span>"DarkCloudCover"<\/span>; <\/span>Pv <\/span>= (<\/span>C1<\/span>><\/span>O1<\/span>*<\/span>1.01<\/span>) AND (<\/span>O<\/span>><\/span>C<\/span>) AND (<\/span>O<\/span>><\/span>H1<\/span>) AND (<\/span>C<\/span>><\/span>O1<\/span>) AND (((<\/span>C1<\/span>+<\/span>O1<\/span>)\/<\/span>2<\/span>)><\/span>C<\/span>) AND (<\/span>C<\/span>><\/span>O1<\/span>) AND (<\/span>MA<\/span>(<\/span>C<\/span>,<\/span>13<\/span>)-<\/span>Ref<\/span>(<\/span>MA<\/span>(<\/span>C<\/span>,<\/span>13<\/span>),-<\/span>4<\/span>)><\/span>0<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>35<\/span>) { <\/span>PatternName <\/span>= <\/span>"ThreeBlackCrows"<\/span>; <\/span>Pv <\/span>= (<\/span>O<\/span>><\/span>C<\/span>*<\/span>1.01<\/span>) AND (<\/span>O1<\/span>><\/span>C1<\/span>*<\/span>1.01<\/span>) AND (<\/span>O2<\/span>><\/span>C2<\/span>*<\/span>1.01<\/span>) AND (<\/span>C<\/span><<\/span>C1<\/span>) AND (<\/span>C1<\/span><<\/span>C2<\/span>) AND (<\/span>O<\/span>><\/span>C1<\/span>) AND (<\/span>O<\/span><<\/span>O1<\/span>) AND (<\/span>O1<\/span>><\/span>C2<\/span>) AND (<\/span>O1<\/span><<\/span>O2<\/span>) AND (((<\/span>C<\/span>-<\/span>L<\/span>)\/(<\/span>H<\/span>-<\/span>L<\/span>))<<\/span>.2<\/span>) AND (((<\/span>C1<\/span>-<\/span>L1<\/span>)\/(<\/span>H1<\/span>-<\/span>L1<\/span>))<<\/span>.2<\/span>) AND (((<\/span>C2<\/span>-<\/span>L2<\/span>)\/(<\/span>H2<\/span>-<\/span>L2<\/span>))<<\/span>.2<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>36<\/span>) { <\/span>PatternName <\/span>= <\/span>"doji"<\/span>; <\/span>Pv <\/span>= (<\/span>O <\/span>== <\/span>C<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>37<\/span>) { <\/span>PatternName <\/span>= <\/span>"GapUp"<\/span>; <\/span>Pv <\/span>= <\/span>GapUp<\/span>(); }  \relse if(<\/span>P <\/span>== <\/span>38<\/span>) { <\/span>PatternName <\/span>= <\/span>"GapDown"<\/span>; <\/span>Pv <\/span>= <\/span>GapDown<\/span>(); }  \relse if(<\/span>P <\/span>== <\/span>39<\/span>) { <\/span>PatternName <\/span>= <\/span>"BigGapUp"<\/span>; <\/span>Pv <\/span>= <\/span>L<\/span>><\/span>1.01<\/span>*<\/span>H1<\/span>; }  \relse if(<\/span>P <\/span>== <\/span>40<\/span>) { <\/span>PatternName <\/span>= <\/span>"BigGapDown"<\/span>; <\/span>Pv <\/span>= <\/span>H<\/span><<\/span>0.99<\/span>*<\/span>L1<\/span>; }  \relse if(<\/span>P <\/span>== <\/span>41<\/span>) { <\/span>PatternName <\/span>= <\/span>"HugeGapUp"<\/span>; <\/span>Pv <\/span>= <\/span>L<\/span>><\/span>1.02<\/span>*<\/span>H1<\/span>; }  \relse if(<\/span>P <\/span>== <\/span>42<\/span>) { <\/span>PatternName <\/span>= <\/span>"HugeGapDown"<\/span>; <\/span>Pv <\/span>= <\/span>H<\/span><<\/span>0.98<\/span>*<\/span>L1<\/span>; }  \relse if(<\/span>P <\/span>== <\/span>43<\/span>) { <\/span>PatternName <\/span>= <\/span>"DoubleGapUp"<\/span>; <\/span>Pv <\/span>= <\/span>GapUp<\/span>() AND <\/span>Ref<\/span>(<\/span>GapUp<\/span>(),-<\/span>1<\/span>); }  \relse if(<\/span>P <\/span>== <\/span>44<\/span>) { <\/span>PatternName <\/span>= <\/span>"DoubleGapDown"<\/span>; <\/span>Pv <\/span>= <\/span>GapDown<\/span>() AND <\/span>Ref<\/span>(<\/span>GapDown<\/span>(),-<\/span>1<\/span>); }  \rreturn <\/span>Pv<\/span>;  \r}  \r<\/span>SetTradeDelays<\/span>(<\/span>0<\/span>,<\/span>0<\/span>,<\/span>0<\/span>,<\/span>0<\/span>);\r<\/span>SetOption<\/span>(<\/span>"AllowSameBarExit"<\/span>,<\/span>False<\/span>);\r \r \r<\/span>P <\/span>= <\/span>ParamOptimize<\/span>(<\/span>"CandlePattern#"<\/span>,<\/span>20<\/span>,<\/span>0<\/span>,<\/span>44<\/span>,<\/span>1<\/span>);\r<\/span>PlotProfit <\/span>= <\/span>ParamToggle<\/span>(<\/span>"Profit Plot"<\/span>,<\/span>"HIDE|SHOW"<\/span>,<\/span>0<\/span>);  \r<\/span>PP <\/span>= <\/span>paramOptimize<\/span>(<\/span>"Profit period (bars)"<\/span>,<\/span>1<\/span>,<\/span>1<\/span>,<\/span>10<\/span>,<\/span>1<\/span>);  \r<\/span>CandlePatternTrue <\/span>= <\/span>CandlePattern<\/span>(<\/span>P<\/span>);  \r<\/span>Mode <\/span>= <\/span>Paramoptimize<\/span>(<\/span>"Mode: Long=0, Short=1"<\/span>,<\/span>1<\/span>,<\/span>0<\/span>,<\/span>1<\/span>,<\/span>1<\/span>);\r\rif ( <\/span>Mode <\/span>== <\/span>1 <\/span>)\r{\r    <\/span>Short <\/span>= <\/span>Cover <\/span>= <\/span>0<\/span>;\r    <\/span>Buy <\/span>= <\/span>CandlePatternTrue<\/span>;\r    <\/span>BuyPrice <\/span>= <\/span>C<\/span>;\r    <\/span>Sell <\/span>= <\/span>Ref<\/span>( <\/span>Buy<\/span>, -<\/span>PP <\/span>);\r    <\/span>SellPrice <\/span>= <\/span>O<\/span>;\r}\relse\r{\r    <\/span>Buy <\/span>= <\/span>Sell <\/span>= <\/span>0<\/span>;\r    <\/span>Short <\/span>= <\/span>CandlePatternTrue<\/span>;\r    <\/span>ShortPrice <\/span>= <\/span>C<\/span>;\r    <\/span>Cover <\/span>= <\/span>Ref<\/span>( <\/span>Short<\/span>, -<\/span>PP <\/span>);\r    <\/span>CoverPrice <\/span>= <\/span>O<\/span>;\r}\r \r<\/span>E                 <\/span>= <\/span>Equity<\/span>(<\/span>1<\/span>);\r<\/span>Profit         <\/span>= <\/span>E<\/span>-<\/span>GetOption<\/span>(<\/span>"InitialEquity"<\/span>);  \r<\/span>Upday         <\/span>= <\/span>IIf<\/span>(<\/span>Ref<\/span>(<\/span>CandlePatternTrue<\/span>,-<\/span>1<\/span>), <\/span>C<\/span>><\/span>O<\/span>,<\/span>0<\/span>);  \r<\/span>downDay         <\/span>= <\/span>IIf<\/span>(<\/span>Ref<\/span>(<\/span>CandlePatternTrue<\/span>,-<\/span>1<\/span>), <\/span>C<\/span><<\/span>O<\/span>,<\/span>0<\/span>);  \r<\/span>PatternColor<\/span>= <\/span>IIf<\/span>(<\/span>CandlePatternTrue<\/span>,<\/span>2<\/span>,<\/span>1<\/span>);  \r<\/span>NumUpDays     <\/span>= <\/span>LastValue<\/span>(<\/span>Cum<\/span>(<\/span>UpDay<\/span>));  \r<\/span>NumDownDays <\/span>= <\/span>LastValue<\/span>(<\/span>Cum<\/span>(<\/span>downDay<\/span>));  \r<\/span>NumPatterns <\/span>= <\/span>LastValue<\/span>(<\/span>Cum<\/span>(<\/span>CandlePatternTrue <\/span>));  \r \r<\/span>GraphXSpace <\/span>= <\/span>10<\/span>;\r<\/span>Plot<\/span>(<\/span>C<\/span>,<\/span>"Close"<\/span>,<\/span>colorBlack<\/span>,<\/span>64<\/span>);  \rif( <\/span>PlotProfit <\/span>) <\/span>Plot<\/span>(<\/span>E<\/span>,<\/span>""<\/span>,<\/span>2<\/span>,<\/span>styleStaircase<\/span>|<\/span>styleOwnScale<\/span>);  \r<\/span>Pointer <\/span>= <\/span>IIf<\/span>( <\/span>CandlePatternTrue<\/span>, <\/span>0.97<\/span>*<\/span>L<\/span>,<\/span>0<\/span>);\r<\/span>\/\/PlotOHLC(0,0,Pointer ,0,\"\",6,styleCloud|styleNoLabel);\r<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>(<\/span>Pointer<\/span>,<\/span>shapeUpArrow<\/span>,<\/span>shapeNone<\/span>),<\/span>colorBlue<\/span>,<\/span>0<\/span>,<\/span>0.99<\/span>*<\/span>L<\/span>,<\/span>0<\/span>);  \r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Buy <\/span>OR <\/span>Cover<\/span>,<\/span>shapeUpTriangle<\/span>,<\/span>shapeNone<\/span>),<\/span>colorBrightGreen<\/span>,<\/span>0<\/span>,<\/span>C<\/span>,<\/span>0<\/span>);  \r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Sell <\/span>OR <\/span>Short<\/span>,<\/span>shapeDownTriangle<\/span>,<\/span>shapeNone<\/span>),<\/span>colorRed<\/span>,<\/span>0<\/span>,<\/span>O<\/span>,<\/span>0<\/span>);\r \r<\/span>Title <\/span>= <\/span>"\\nCANDLE PATTERN ANALYSIS, Ticker: "<\/span>+ <\/span>Name<\/span>()+<\/span>"\\n\\n"<\/span>+  \r<\/span>" Candle Pattern: "<\/span>+<\/span>PatternName<\/span>+<\/span>"\\n"<\/span>+\r<\/span>"#Patterns found: "<\/span>+<\/span>NumToStr<\/span>(<\/span>NumPatterns <\/span>,<\/span>1.0<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>"   Next #Updays: "<\/span>+<\/span>NumToStr<\/span>(<\/span>NumUpDays<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+  \r<\/span>" ["<\/span>+<\/span>NumToStr<\/span>(<\/span>Nz<\/span>(<\/span>NumUpDays<\/span>\/<\/span>NumPatterns<\/span>*<\/span>100<\/span>),<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"%]\\n"<\/span>+  \r<\/span>" Next #DownDays: "<\/span>+<\/span>NumToStr<\/span>(<\/span>NumDownDays<\/span>,<\/span>1.0<\/span>,<\/span>False<\/span>)+  \r<\/span>" ["<\/span>+<\/span>NumToStr<\/span>(<\/span>Nz<\/span>(<\/span>NumDownDays<\/span>\/<\/span>numpatterns<\/span>*<\/span>100<\/span>),<\/span>1.0<\/span>,<\/span>False<\/span>)+<\/span>"%]\\n\\n"<\/span>+  \r<\/span>"  Profit at cursor: $"<\/span>+<\/span>NumToStr<\/span>(<\/span>Profit<\/span>,<\/span>1.2<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>"Ave.Profit\/Pattern: $"<\/span>+<\/span>NumToStr<\/span>(<\/span>Nz<\/span>(<\/span>Profit<\/span>\/<\/span>NumPatterns<\/span>),<\/span>1.2<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>"      Final Profit: $"<\/span>+<\/span>NumToStr<\/span>(<\/span>LastValue<\/span>(<\/span>Profit<\/span>),<\/span>1.2<\/span>)+<\/span>"\\n\\n"<\/span>+\r<\/span>" Open: "<\/span>+<\/span>NumToStr<\/span>(<\/span>O<\/span>,<\/span>1.2<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>" High: "<\/span>+<\/span>NumToStr<\/span>(<\/span>H<\/span>,<\/span>1.2<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>"  Low: "<\/span>+<\/span>NumToStr<\/span>(<\/span>L<\/span>,<\/span>1.2<\/span>)+<\/span>"\\n"<\/span>+  \r<\/span>"Close: "<\/span>+<\/span>NumToStr<\/span>(<\/span>C<\/span>,<\/span>1.2<\/span>);  <\/span><\/pre>\n

Edited by Al Venosa.<\/p>\n","protected":false},"excerpt":{"rendered":"

This indicator formula allows you to select Candlestick patterns, mark their occurrence on the chart, display their frequency, and test their predictive value. Apply the code to an Indicator, open up the Param window, and drag the CandlePattern# slider left and right to change to a different pattern. The selected pattern is identified in the […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[66],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1625"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1625"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1625\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1625"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}