Limit of trades per 1H interval while backtest
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
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
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)
but using that makes it incompatible with the use of other EAs or manual trading.
OK, but how to retrieve OrderCloseTime for the latest closed trade?
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.