Three White Soldiers Three Black Crows

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Three White Soldiers Three Black Crows
ÿþ//+------------------------------------------------------------------+

//|                       Three White Soldiers Three Black Crows.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.000"

#property description "'Three White Soldiers' candlestick pattern"

#property description "'Three Black Crows' candlestick pattern"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot Arrows

#property indicator_label1  "Three White Soldiers"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrBlue

#property indicator_width1  3

#property indicator_label2  "Three Black Crows"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrRed

#property indicator_width2  3

//+------------------------------------------------------------------+

//| Enum Pips Or Points                                              |

//+------------------------------------------------------------------+

enum ENUM_PIPS_OR_POINTS

  {

   pips=0,     // Pips (1.00045-1.00055=1 pips)

   points=1,   // Points (1.00045-1.00055=10 points)

  };

//--- input parameters

input group             "Arrow"

input uchar                InpSoldiersCode   = 228;   // Soldiers: code (font Wingdings)

input int                  InpSoldiersShift  = 5;     // Soldiers: vertical shift of arrows in pixels

input uchar                InpCrowsCode      = 230;   // Crows: code (font Wingdings)

input int                  InpCrowsShift     = 5;     // Crows: vertical shift of arrows in pixels

//--- An indicator buffer for the plot

double   SoldiersBuffer[];

double   CrowsBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,SoldiersBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,CrowsBuffer,INDICATOR_DATA);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpSoldiersCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpCrowsCode);

//--- set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-InpSoldiersShift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,InpCrowsShift);

//--- set as an empty value 0.0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//--- digits

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//--- revert access to arrays - do it like in timeseries

   if(rates_total<10) // it isn't enough data: exit

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      limit=2;

      for(int j=0; j<=limit; j++)

        {

         SoldiersBuffer[j]=EMPTY_VALUE;

         CrowsBuffer[j]=EMPTY_VALUE;

        }

     }

//--- main loop

   for(int i=limit; i<rates_total; i++)

     {

      //--- 'Three White Soldiers'

      if(open[i]<close[i]) // bar 'i' - Soldier -> it makes sense to go deeper as long as the condition 'open<close' is satisfied

        {

         int j=i,counter_soldier=0;

         while(open[j]<close[j] && j>=0)

           {

            j--;

            counter_soldier++;

           }

         if(counter_soldier>2)

            for(int k=j+1; k<=i; k++)

               SoldiersBuffer[k]=high[k];

        }

      else

        {

         SoldiersBuffer[i]=EMPTY_VALUE;

         int j=i-1,counter_soldier=0;

         while(open[j]<close[j] && j>=0)

           {

            j--;

            counter_soldier++;

           }

         if(counter_soldier<=2)

            for(int k=j+1; k<=i; k++)

               SoldiersBuffer[k]=EMPTY_VALUE;

        }

      //--- 'Three Black Crows'

      if(open[i]>close[i]) // bar 'i' - Crow -> it makes sense to go deeper as long as the condition 'open>close' is satisfied

        {

         int j=i,counter_crow=0;

         if(j>=0) // defense: 'j' cannot be less than zero

           {

            while(open[j]>close[j] && j>=0)

              {

               j--;

               counter_crow++;

               if(j<0) // defense: 'j' cannot be less than zero

                  break;

              }

           }

         if(counter_crow>2)

            for(int k=j+1; k<=i; k++)

               CrowsBuffer[k]=low[k];

        }

      else

        {

         CrowsBuffer[i]=EMPTY_VALUE;

         int j=i-1,counter_crow=0; // 2KE>4 70 ?@545;K <0AA820

         if(j>=0) // defense: 'j' cannot be less than zero

           {

            while(open[j]>close[j])

              {

               j--;

               counter_crow++;

               if(j<0) // defense: 'j' cannot be less than zero

                  break;

              }

           }

         if(counter_crow<=2)

            for(int k=j+1; k<=i; k++)

               CrowsBuffer[k]=EMPTY_VALUE;

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---