Download MetaTrader 5

Sleep EA during a fix time of the day

To add comments, please log in or register
wiptheman
378
wiptheman 2013.02.23 12:03 

Hi All,

Doing some back test I realised that there are some hours where the EA does not perform well.  See below Chart.

First I was wondering is this chart from the MQL5 strategy tester based on the opening Hour of the deal or closing hour of the deal? I guess opening but not sure.

 

 

So basically I would like to have the EA "pause" when between 15h and 18h. How could I do that?

Should I take DST into consideration or is there a way to use the "Market Watch" that is, I guess, automatically adjusted to DST ?

 Thanks for your help!

W. 

wiptheman
378
wiptheman 2013.02.23 14:24  

Ok so I've been doing some testing and came up with the below code that also checks if there is a trade open as the EA should not "sleep" if there is a trade opened"

What I miss is how I get the Hour as an integer out of TimeCurrent. Tried the below but it returns 0 

 

input int      NapStartHour=15;           // Starts Naping
input int      NapStopHour=18;            // Waking Up
int h;                                    // Hour Integer
int m_hour;                               // Hour of the day

  

MqlDateTime mdt;
datetime t=TimeCurrent(mdt);
m_hour=h;
 
   
   if((Buy_opened)||(Sell_opened)) {                                       // Is there an opened position?
      
      nap="Trading";}                                                      // There is a trade so no nap                                            
      
      else{
      if((m_hour > NapStartHour)||(m_hour < NapStopHour)) {      	// Are we between Nap Start and Stop Hour ?
      
      nap="Taking a Nap";                                                  // We are so Taking a Nap
      return;  }
      
      else{
      nap="Trading";}                                                      // Out of Nap Hours Trading Continues                                                                   
     }

 

wiptheman
378
wiptheman 2013.02.23 18:55  

Ok I cracked it here it is :

MqlDateTime mdt;
TimeCurrent(mdt);
Print("Hour =",mdt.hour);

 

Miguelito Yap
640
Miguelito Yap 2013.02.23 19:18  

m_hour = mdt.hour;

nap should be if( m_hour >= NapStartHour && m_hour <= NapStopHour)  , This will nap 15th thru 18 hour.  Your code above will nap all the time.

 

wiptheman
378
wiptheman 2013.02.23 20:19  

Hey yes you are right I corrected that in the meantime.

This being said it does not really help because the above chart is on the closing hours as I feared and not the opening hours...

 Thanks for you help ! 

phi nuts
2184
phi nuts 2013.02.24 14:27  
fxyekim:

m_hour = mdt.hour;

nap should be if( m_hour >= NapStartHour && m_hour <= NapStopHour)  , This will nap 15th thru 18 hour.  Your code above will nap all the time.

 

Yep, and during nap time, the EA does not have to "return", just do "don't open new position", so the EA can still close any current position during nap time.


To add comments, please log in or register