Download MetaTrader 5
To add comments, please log in or register
Your broker does not support mobile MetaTrader 5? Ask him to buy them!
mpfx
32
mpfx 2016.07.22 23:38 

Greetings All,

 Looking for a code to find a candle high and low based on the candle formation time. Eg.  9:00

 

Any help greatly appreciated...

 

GT..  mpfx 

Ernst Van Der Merwe
4474
Ernst Van Der Merwe 2016.07.23 08:19  
MqlDateTime dt;
string name1,name2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   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 begin=rates_total-prev_calculated;
   if(prev_calculated<1)
      begin--;
   for(int i=begin;i>=0;i--)
     {
//---Alternative 1
      TimeToStruct(time[i],dt);
      if(dt.hour==9 && dt.min==0)
        {
         name1="high"+(string)time[i];
         name2="low"+(string)time[i];
         ObjectCreate(0,name1,OBJ_ARROW,0,time[i],high[i]);
         ObjectSetInteger(0,name1,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name1,OBJPROP_COLOR,clrBlue);
         ObjectCreate(0,name2,OBJ_ARROW,0,time[i],low[i]);
         ObjectSetInteger(0,name2,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name2,OBJPROP_COLOR,clrRed);
        }
//---Alternative 2
      if(TimeHour(time[i])==9 && TimeMinute(time[i])==0)
        {
         name1="high"+(string)time[i];
         name2="low"+(string)time[i];
         ObjectCreate(0,name1,OBJ_ARROW,0,time[i],high[i]);
         ObjectSetInteger(0,name1,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name1,OBJPROP_COLOR,clrBlue);
         ObjectCreate(0,name2,OBJ_ARROW,0,time[i],low[i]);
         ObjectSetInteger(0,name2,OBJPROP_ARROWCODE,217);
         ObjectSetInteger(0,name2,OBJPROP_COLOR,clrRed);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
mpfx
32
mpfx 2016.07.28 22:32  
Ernst Van Der Merwe:
Thank you Ernst..  Very much appreciated..   GT...
/
To add comments, please log in or register