Excuse me, how do we trade in the time stipulated every day?

 

I want to make the daily transaction time: 02:00-23:30, close all orders before 23:30 every day. How should I write?


void OnTick()
  {
     if( 02:00<OrderOpenTime && OrderOpenTime<23:30)
       {
         OrderSend(Symbol(),OP_BUY,1,Ask,10,Ask-100*Point,Ask+500*Point,"BUY" ,12345,Red)
       }
     
     if (OrderCloseTime<23:30 )
       {
         OrderClose(OrderTicket(),OrderLots(),Bid,0,Red)
       }
   
  }
I want to make the daily transaction time: 02:00-23:30, close all orders before 23:30 every day. How should I write?
 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. if( 02:00<OrderOpenTime
    
    if (OrderCloseTime<23:30 )
    
    OrderClose(OrderTicket(),OrderLots(),Bid,0,Red)
    You can not use any Trade Functions until you first select an order.

  3. if (OrderCloseTime<23:30 )
    If the order is open, it has no close time.

  4. Stop thinking trade functions, think current time.
    1. If the current time is at or after 02:00 but before 23:00 and there is no open order, open one.
    2. If the current time is not at or after 02:00 but before 23:00, close any existing one.
    #define HR0200  7200 
    #define HR2300 82800
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 and MetaTrader 4 - MQL4 programming forum

 
whroeder1:

Thank you very much! I don't know the rules. I simply think that the code is generic, in MT4 or MT5 didn't expect that there are difference.


Reason: