Download MetaTrader 5

Problem for draw arrows only in specific times

To add comments, please log in or register
Gabriel Viali
205
Gabriel Viali 2015.04.04 23:32 

Hello guys! I'm having some dificulties trying to make an indicator plots its arrow buffers only in specific times. 

For example, I would like the indicator only draws its arrows from  GMT 8:00 AM to 02:00 PM.

 I tryed doing this, but its not working.

extern int starthour = 8;
extern int endhour = 14;
extern int LondonTZ = 0;


int start()
{

//this is the part where i've tried

int dst=1;
int GMT_SHIFT=GlobalVariableGet("GMT_SHIFT"+WindowHandle(Symbol(),Period())+Symbol()+Period());
datetime GMT = TimeLocal() - GMT_SHIFT * 60;
  
datetime london = GMT + (LondonTZ + (dst*60 - 1*60)) * 60;

////-----

    if(TimeHour(london)>=starthour && TimeHour(london)<=endhour)
      {
                
      if(buy rules here)
         
         {ArrowUPBuffer[i]=Low[i]-5*Point;
            if(alertas && Time0 != Time[0])
            {Time0 = Time[0];
               Alert("BUY em: ",Symbol(),",",Period());
               }
            up[i]=1;
            }
      else
         ArrowUPBuffer[i]=0;
      
      if(sell rules here)
            
         {ArrowDownBuffer[i]=High[i]+5*Point;            
            if(alertas && Time0 != Time[0])
            {Time0 = Time[0];
               Alert("SELL em: ",Symbol(),",",Period());
               }
            dw[i]=1;   
            }
      else
         ArrowDownBuffer[i]=0;
      }
    }

 

Someone to give me some light on this task? 

 

Thanks in avance. 

Drazen Penic
2574
Drazen Penic 2015.04.10 17:45  

You can simplify your code (and make it easier to catch a bug) if you use standard time and date functions: Date and Time

Use TimeGMT() function to obtain current GMT time.

Date and Time - MQL4 Documentation
  • docs.mql4.com
Date and Time - MQL4 Documentation
To add comments, please log in or register