Download MetaTrader 5

time specific code

To add comments, please log in or register
Do you keep a blog? Place a link to MQL5.community there and make money!
tan pang hua
122
tan pang hua 2012.09.10 19:21 

hi,

  does anyone know how to enter trade at specific time? Thanks in advance. 

onewithzachy
2271
onewithzachy 2012.09.10 19:41  
thezen:

hi,

  does anyone know how to enter trade at specific time? Thanks in advance. 

Hi thezen,

I think there's plenty of that in the forum if you willing to search. This code below is just an example

input int Open_Hour=3;
input int Open_Minute=7;
input bool Use_Broker_Time = false;
//+------------------------------------------------------------------+
//|  program start function                                          |
//+------------------------------------------------------------------+
void OnStart()
  {
  datetime    open_time;
  MqlDateTime struc_time;
  
  if (Use_Broker_Time == true)
    open_time = TimeCurrent();
    else
    open_time = TimeLocal();
    
  TimeToStruct(open_time,struc_time);
  
  if (struc_time.hour >= Open_Hour && struc_time.min >= Open_Minute)
    {
    // open business here
    
    }
  }

 

tan pang hua
122
tan pang hua 2012.09.14 07:29  
onewithzachy:

Hi thezen,

I think there's plenty of that in the forum if you willing to search. This code below is just an example

 

Thanks onewithzachy! Pardon for my ignorance, how could I open a position within the bracket?  Thanks for helping a newbie!
kaloian kaloianov
445
kaloian kaloianov 2012.09.14 09:27  

of course you can but i think you should also restrict the time from the upside

onewithzachy
2271
onewithzachy 2012.09.14 10:59  
thezen 2012.09.14 07:29 
Thanks onewithzachy! Pardon for my ignorance, how could I open a position within the bracket?  Thanks for helping a newbie!

Hi thezen, 

I don't understand your question there ("how could I open a position within the bracket? "), of course you could. However if you meant some open position code, there's a lot example around.

Like this script to open buy and to open sell (click that) and my previous code https://www.mql5.com/en/forum/6666#comment_192901 please read the entire thread starting from there.

And you should set the upper time like onlysolo suggest. 

 

To add comments, please log in or register