First five minutes

Author: Copyright 2020, MetaQuotes Software Corp.
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
First five minutes
ÿþ//+------------------------------------------------------------------+

//|                                           First five minutes.mq5 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2020, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot FirstFiveMinutes

#property indicator_label1  "FirstFiveMinutes"

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  clrLavender,clrLimeGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3

//--- input parameters

input int   Input1   = 9;

//--- indicator buffers

double   FirstFiveMinutesBuffer[];

double   FirstFiveMinutesColors[];

//---

bool     m_init_error               = false;    // error on InInit

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,FirstFiveMinutesBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,FirstFiveMinutesColors,INDICATOR_COLOR_INDEX);

//--- set maximum and minimum for subwindow

   IndicatorSetDouble(INDICATOR_MINIMUM,-1.0);

   IndicatorSetDouble(INDICATOR_MAXIMUM,1.0);

//---

   if(Period()!=PERIOD_D1)

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      ""09<D@59< 4>;65= 1KBL B>;L:> 'D1'!":

                      "The timeframe should only be 'D1'!";

      if(MQLInfoInteger(MQL_TESTER)) // when testing, we will only output to the log about incorrect input parameters

         Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      else // if the Expert Advisor is run on the chart, tell the user about the error

         Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      //---

      m_init_error=true;

      return(INIT_SUCCEEDED);

     }

//---

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

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

//--- main loop

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

     {

      MqlRates rates_m5[];

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

      datetime stop_time=(i<rates_total-1)?time[i+1]:TimeCurrent();//+PeriodSeconds(PERIOD_M5)+PeriodSeconds(PERIOD_M5)/2;         // end date and time

      if(CopyRates(Symbol(),PERIOD_M5,start_time,stop_time,rates_m5)<1)

         return(0);

      if(ArraySize(rates_m5)>1)

         int d=0;

      if(time[i]==D'2020.12.17 00:00')

         int d=0;

      if(rates_m5[0].open<rates_m5[0].close)

        {

         FirstFiveMinutesBuffer[i]

            =1.0;

         FirstFiveMinutesColors[i]=0.0;

        }

      else

        {

         FirstFiveMinutesBuffer[i]=-1.0;

         FirstFiveMinutesColors[i]=1.0;

        }

     }

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

   return(rates_total);

  }

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

Comments