High Low Bars

Author: Copyright © 2019, Vladimir Karputov
1 Views
0 Downloads
0 Favorites
High Low Bars
ÿþ//+------------------------------------------------------------------+

//|                                                High Low Bars.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot High

#property indicator_label1  "High"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrFuchsia

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Low

#property indicator_label2  "Low"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrTomato

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uchar    InpCode        = 174;   // Code from the "Wingdings"

//--- indicator buffers

double         HighBuffer[];

double         LowBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,LowBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpCode);

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

  {

   /*

   time[rates_total-1]  -> the rightmost bar on the chart

   time[0]              -> the leftmost bar on the chart

   */



   if(rates_total<3)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      HighBuffer[0]=0.0;

      LowBuffer[0]=0.0;

      limit=1;

     }

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

     {

      HighBuffer[i]=0.0;

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

         HighBuffer[i]=high[i];

      //---

      LowBuffer[i]=0.0;

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

         LowBuffer[i]=low[i];

     }

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

   return(rates_total);

  }

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

Comments