<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kabir Atoyebi on Medium]]></title>
        <description><![CDATA[Stories by Kabir Atoyebi on Medium]]></description>
        <link>https://medium.com/@katoyebir?source=rss-9d925dbc577b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hyLsJh3chqROf-s7RoNsEA.jpeg</url>
            <title>Stories by Kabir Atoyebi on Medium</title>
            <link>https://medium.com/@katoyebir?source=rss-9d925dbc577b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:48:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@katoyebir/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Candlestick pattern detection technique]]></title>
            <link>https://medium.com/@katoyebir/candlestick-pattern-detection-technique-7d2cab87f9ea?source=rss-9d925dbc577b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d2cab87f9ea</guid>
            <category><![CDATA[candlestick-trading]]></category>
            <category><![CDATA[quantitative-strategies]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Kabir Atoyebi]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 16:34:16 GMT</pubDate>
            <atom:updated>2023-12-07T06:08:16.980Z</atom:updated>
            <content:encoded><![CDATA[<p>Candlestick patterns are an essential part of trading financial markets. They provide invaluable data on market sentiment.</p><p>Here is my approach to creating a candlestick pattern detection algorithm. A candlestick gives information about a currency pair or stock within a selected timeframe. By dividing the candlestick into 3 sections- The upper shadow, body, and lower shadow, in terms of the percentage of the overall candlestick length, it is easy to classify candlesticks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*loUmkIha_2oIXPvdfYE3tA.png" /><figcaption>Credit: The Candlestick Trading Bible</figcaption></figure><p>A long upper and lower shadow indicates strong buying and selling pressure which is iconic of the doji candlestick. Strong buying and selling pressure with a wider body is considered a spinning top candlestick.</p><p>Candlestick pattern detection can also be a valuable feature in training machine learning models as patterns tend to be bullish, bearish, or neutral. This introduces a feature of market sentiment into the machine learning model.</p><p>A single candlestick pattern detection model was used to test the algorithm, however it is easy to implement for multiple candlestick patterns by comparing relevant consecutive candles. Precision was prioritized over recall to reduce the number of false positives.</p><p>The length of the candlestick is first calculated by subtracting the high from the low of the candlestick. The distance between the regions are then used to take percentages of the candlestick length.</p><p>By comparing these percentages, the candlesticks can be classified. Below is a sample of the code in MQL5. The script scans the chart and highlights detected doji, gravestone doji, shooting star, and spinning top patterns.</p><pre>//Candle class to calculate candlestick data<br>class candle<br>{<br>  private:<br>  double top;<br>  double middle;<br>  double bottom;<br>  double size;<br>  datetime time;<br>  bool bull;<br>  double price;<br>  <br>  public:<br>  //constructor<br>  candle(double high, double open, double close, double low, datetime t){<br><br>  //for bearish candlesticks<br>  if (open &gt;= close)<br>  {<br>     size = high - low;<br>     top = (high - open) / size * 100;<br>     middle = (open - close) / size * 100;<br>     bottom = (close - low) / size * 100;<br>     bull = false;<br>  }<br>  //for bullish candlesticks<br>  else{<br>     size = high - low;<br>     top = (high - close) / size * 100;<br>     middle = (close - open) / size * 100;<br>     bottom = (open - low) / size * 100;<br>     bull = true;<br>     }<br>     price = high;<br>     time = t;<br>  }<br><br>  // Getter functions for all variables of Candle class<br>  double Gettop() const { return top; }<br>  double Getmiddle() const { return middle; }<br>  double Getbottom() const { return bottom; }<br>  double Getsize() const { return size; }<br>  datetime Gettime() const { return time; }<br>  bool Getbull() const { return bull;}<br>  double Getprice() const {return price;}<br>};<br><br>void OnStart()<br>  {<br>//---<br>   MqlRates rates[];<br><br>   int objno = 0;   <br>   int i;<br>   int copied;<br><br>   //assigns number of candlesticks to copied<br>   copied = Bars(NULL, PERIOD_CURRENT);<br>   // copies information on candlesticks to rates array<br>   copied = CopyRates(NULL, PERIOD_CURRENT, 0, copied, rates);   <br>   <br>      for (i = 0; i &lt; copied; i++)<br>   {<br>      candle current( rates[i].high, rates[i].open, rates[i].close, rates[i].low, rates[i].time);<br>      <br>        if ( <br><br>            // checks for if shooting star candlestick<br>            ( (current.Getbottom() &lt;= 7.0) &amp;&amp; (current.Getmiddle() &gt;= 13.0 &amp;&amp; current.Getmiddle() &lt;= 20.0) &amp;&amp; (current.Getbull() == false) ) ||<br>            //for doji<br>            ( (current.Gettop() &gt;= 46.0) &amp;&amp; (current.Getbottom() &gt;= 46.0))  ||<br>            //for spinning top<br>            ( (current.Gettop() &gt;= 39.0) &amp;&amp; (current.Getbottom() &gt;= 39.0) ) ||<br>            //gravestone doji<br>            ( (current.Getbottom() &lt;= 5.0) &amp;&amp; (current.Getmiddle() &lt;= 5.0) ) <br>        <br>            )<br>      {<br>               ObjectCreate( 0, objno++, OBJ_ARROW_SELL, 0, rates[i].time, rates[i].high + current.Getsize() );<br>      }<br>   }<br>   Print(&quot;Total number of classified candles - &quot;, objno);<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*YbaePnqwAo26eYftFLA62w.png" /><figcaption>Doji, gravestone doji, shooting star, and spinning top candlesticks respectively</figcaption></figure><p>Output of the code on the USDCHF 15-minute currency pair:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*ofiGK18a2hk1h4r4KAl_sA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*5ESFGmjF7zWvq7UBZJjKIQ.png" /><figcaption>False Positive</figcaption></figure><p>However, without accounting for length of the candlesticks, false positives like this are possible. Using average candlestick length or limiting size of detected candlesticks resolves this problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d2cab87f9ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>