Morning Star

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Morning Star
ÿþ//+------------------------------------------------------------------+

//|                                                 Morning Star.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

#property copyright "Copyright © 2020, Vladimir Karputov"

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

#property version   "1.002"

#property description "'Morning Star' candlestick pattern"



#property indicator_chart_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot Arrows

#property indicator_label1  "Morning Star"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrGreen

#property indicator_width1  1

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

//| 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 ENUM_PIPS_OR_POINTS  InpPipsOrPoints= points;   // Pips Or Points:

input bool                 InpGap         = true;     // Gap. 'true' -> gap is taken into account

input bool                 InpCandle2Type = true;     // Candle 2 type. 'true' -> type of candle 2 is taken into account

input bool                 InpCandleSizes = true;     // Candle sizes. 'true' -> candle sizes is taken into account

input uchar                InpArrowCode   = 74;       // Symbol InpArrowCode to draw in DRAW_ARROW

//--- An indicator buffer for the plot

double   ArrowsBuffer[];

double   m_distance=0.0;         // minimum size of gap

double   m_adjusted_point;       // point value adjusted for 3 or 5 points

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,ArrowsBuffer,INDICATOR_DATA);

//--- Define the symbol InpArrowCode for drawing in PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpArrowCode);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);

//--- Set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- revert access to array ArrowsBuffer[] - do it like in timeseries

   ArraySetAsSeries(ArrowsBuffer,true);

   ArrayInitialize(ArrowsBuffer,0.0);

//--- tuning for 3 or 5 digits

   int digits_adjust=1;

   if(Digits()==3 || Digits()==5)

      digits_adjust=10;

   m_adjusted_point=Point()*digits_adjust;

   if(InpPipsOrPoints==pips) // Pips (1.00045-1.00055=1 pips.)

      m_distance  = 1   * m_adjusted_point;

   else // Points (1.00045-1.00055=10 points)

      m_distance  = 1   * Point();

//---

   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

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

   /*

      "2"    "1"    "0"



       |

    O ---

      |||            |

      |||         C ---

      |||           | |

      |||           | |

      |||           | |

      |||           | |

    C ---           | |

       |          O ---

              |      |

           O ---

             |||

           C ---

              |

   */

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

      return(0);

   int limit=rates_total-1-3;

   if(prev_calculated==0)

      ArrayInitialize(ArrowsBuffer,0.0);

   else

      limit=rates_total-prev_calculated;

//---

   for(int i=limit; i>0; i--)

     {

      //--- OHLC

      //--- rough check: bar with the index "0" - bullish and bar with the index "2" - bearish

      if(open[i+0]<close[i+0] && open[i+2]>close[i+2]) //

        {

         if(InpCandleSizes) // Candle sizes

            if(MathAbs(open[i+0]-close[i+0])<MathAbs(open[i+1]-close[i+1]) || MathAbs(open[i+2]-close[i+2])<MathAbs(open[i+1]-close[i+1]))

              {

               ArrowsBuffer[i+1]=0.0;

               continue;

              }

         if(InpCandle2Type) // Candle 2 type

           {

            if(open[i+1]<close[i+1])

              {

               ArrowsBuffer[i+1]=0.0;

               continue;

              }

           }

         else

           {

            if(open[i+1]>close[i+1]) //

              {

               ArrowsBuffer[i+1]=0.0;

               continue;

              }

           }

         if(InpGap) // Gap !!!

            if(open[i+0]-open[i+1]<=m_distance || close[i+2]-open[i+1]<=m_distance)

              {

               ArrowsBuffer[i+1]=0.0;

               continue;

              }

         ArrowsBuffer[i+1]=low[i+1];

        }

     }

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

   return(rates_total);

  }

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

Comments