Bearish Bullish Harami

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Bearish Bullish Harami
ÿþ//+------------------------------------------------------------------+

//|                                       Bearish Bullish Harami.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

#property copyright "Copyright © 2020, Vladimir Karputov"

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

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot BearishHarami

#property indicator_label1  "Bearish Harami"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot BullishHarami

#property indicator_label2  "Bullish Harami"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uchar    InputBearishCode  = 159;      // Arrow code for Bearish Harami (font Wingdings)

input uchar    InputBullishCode  = 159;      // Arrow code for Bullish Harami (font Wingdings)

//--- indicator buffers

double   BearishHaramiBuffer[];

double   BullishHaramiBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BearishHaramiBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BullishHaramiBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InputBearishCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InputBullishCode);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-5);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   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[])

  {

//---

   if(rates_total<9)

      return(0);

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      BearishHaramiBuffer[0]=0.0;

      BullishHaramiBuffer[0]=0.0;

      limit=1;

     }

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

     {

      BearishHaramiBuffer[i]=0.0;

      BullishHaramiBuffer[i]=0.0;

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

         if(open[i]>close[i])

            if(high[i-1]>high[i] && low[i-1]<low[i])

               BearishHaramiBuffer[i]=low[i];



      if(open[i-1]>close[i-1])

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

            if(high[i-1]>high[i] && low[i-1]<low[i])

               BullishHaramiBuffer[i]=high[i];

     }

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

   return(rates_total);

  }

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

Comments