Just look at the Orders already placed and their OrderOpenTime() and then act accordingly.
Marius:
I have tried to do something with OrderCloseTime() but when I start the backtest there is no previous trades
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
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)
but using that makes it incompatible with the use of other EAs or manual trading.
Marius:
Order History sort by closing date - MQL4 forum
OK, but how to retrieve OrderCloseTime for the latest closed trade?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.