Limit of trades per 1H interval while backtest

 
Hi,

Is it possible to put a limit of trades per 1H period while backtest?
For example if the last trade was at 11:56 then the next trade can be send at 12:00.

I have tried to do something with sleep() but this function doesn't work while backtest mode.
 
Just look at the Orders already placed and their OrderOpenTime() and then act accordingly.
 
I have tried to do something with OrderCloseTime() but when I start the backtest there is no previous trades
 
Marius:
I have tried to do something with OrderCloseTime() but when I start the backtest there is no previous trades

Then the EA is allowed to open a new trade
 
I'll check it, but I have one more question. How to convert UNIX to hour (without minutes) in MQL4 - something like this https://docs.mql4.com/dateandtime/Hour
 

Thanks.


Why this test code opens only one trade (blue):

extern double StopLoss = 120.0;
extern double TakeProfit = 90.0;
extern double Max_Slippage = 3.0;
extern double Spread = 20.0;


int start() {
int ticket_long;
                     
if (OrdersTotal() < 1) {

if (OrdersHistoryTotal() < 1) {
ticket_long = OrderSend(Symbol(), OP_BUY, 1, Ask, Max_Slippage, Ask - StopLoss * Point, Ask + TakeProfit * Point, "", 1, 0, Blue);               
} //OrdersHistoryTotal 
else


     if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)==true)
       {
        int prevtime=OrderCloseTime();
        int curenttime=TimeCurrent();
        if(prevtime + 3600 < curenttime )     
        ticket_long = OrderSend(Symbol(), OP_BUY, 1, Ask, Max_Slippage, Ask - StopLoss * Point, Ask + TakeProfit * Point, "", 1, 0, Yellow);               
        } //OrderSelect

     
return (0);  
} //OrdersTotal 
 

return(0);
} //start
 
Marius:

Why this test code opens only one trade (blue):

The first position in the Order History is 0 not 1 . . . but don't you want the last, most recent position ?

 

OK, but how to retrieve OrderCloseTime for the latest closed trade?

What should I use here:

OrderSelect(XXXXX,SELECT_BY_POS,MODE_HISTORY)
 

OrderHistoryTotal() - 1

but using that makes it incompatible with the use of other EAs or manual trading.

 
Marius:

OK, but how to retrieve OrderCloseTime for the latest closed trade?

Order History sort by closing date - MQL4 forum