Breakdown OHLC 2

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

//|                                             Breakdown OHLC 2.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   "2.000"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_plots   1

//--- plot Crossing

#property indicator_label1  "Breakdown"

#property indicator_type1   DRAW_COLOR_ARROW

#property indicator_color1  clrRoyalBlue,clrOrangeRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input uchar    InpCode  = 174;         // Arrow code for style DRAW_ARROW (font Wingdings)

//--- indicator buffers

double   BreakdownBuffer[];

double   BreakdownColors[];

double   arrow_shift=0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BreakdownBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,BreakdownColors,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpCode);

//--- an empty value for plotting, for which there is no drawing

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   arrow_shift=Point()*3.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<3)

      return(0);

//--- main loop

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      BreakdownBuffer[0]=0.0;

      BreakdownColors[0]=0.0;

      limit=1;

     }

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

     {

      BreakdownBuffer[i]=0.0;

      BreakdownColors[i]=0.0;

      //---

      MqlRates rates_M1[];

      datetime start_time=time[i];  // start date and time

      datetime stop_time=0;         // end date and time

      if(i+1>=rates_total)

         stop_time=TimeCurrent();

      else

         stop_time=time[i+1];

      int count=CopyRates(Symbol(),PERIOD_M1,start_time,stop_time,rates_M1);

      if(count<1)

         return(0);

      datetime time_high   = 0;  // "0" -> D'1970.01.01 00:00';

      datetime time_low    = 0;  // "0" -> D'1970.01.01 00:00';

      double   price_high  = DBL_MIN;

      double   price_low   = DBL_MAX;

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

        {

         if(rates_M1[j].close>high[i-1])

           {

            BreakdownBuffer[i]=high[i]+arrow_shift;

            BreakdownColors[i]=0.0;

            break;

           }

         if(rates_M1[j].close<low[i-1])

           {

            BreakdownBuffer[i]=low[i]-arrow_shift;

            BreakdownColors[i]=1.0;

            break;

           }

        }

     }

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

   return(rates_total);

  }

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

Comments