- Close all open orders when first order TP hit
- 'Close all'/'Open' tools
- How to open a trade when price touches a object?
You can simply use Sleep(15000); but this will not allow you to test in the Strategy Tester. A better method would be to use a variable to save the time hen the order was closed and then on each tick check if 15 seconds have elapsed, the issue with this is that if you have no tick for 30 seconds you will wait 30 seconds not 15, but at least you would be able to perform a more valid test in the Strategy Tester.
Post-Script: There seems to be a possibility by selecting the trade in history mode, however, that seems to be possible in 'select by position'. I am not clear how to imagine positions. Plus I am not sure whether a trade which just closed would be available to be selected from the history.
Post-Script: There seems to be a possibility by selecting the trade in history mode, however, that seems to be possible in 'select by position'. I am not clear how to imagine positions. Plus I am not sure whether a trade which just closed would be available to be selected from the history.
Yes you can do that, use a for loop to loop through the closed orders to find the most recently closed order and check how long ago it was closed using OrderCloseTime()
The closed trades are in the MODE_HISTORY pool and run from positions 0 to OrdersHistoryTotal() - 1
Yes you can do that, use a for loop to loop through the closed orders to find the most recently closed order and check how long ago it was closed using OrderCloseTime()
The closed trades are in the MODE_HISTORY pool and run from positions 0 to OrdersHistoryTotal() - 1
You can go either way, counting up or counting down.
It matters if you are counting through the open orders and are deleting/closing orders as the numbers of orders in the pool will change when you delete/close one.
Every time OrdersHistoryTotal() is changed up you take
static datetime timelastclosedtrade; if (OrdersHistoryTotal() != numberofclosedtrades) { timelastclosedtrade = TimeCurrent(); numberofclosedtrades = OrdersHistoryTotal(); }
You only have to check the last trade in History if
timelastclosedtrade + 15 > TimeCurrent()
when the EA does get to try open a new trade
Every time OrdersHistoryTotal() is changed up you take
You only have to check the last trade in History if
when the EA does get to try open a new trade
Or if the last closed trade is manually placed or belongs to a different EA or maybe a different symbol/timeframe. ;-)
Or if the last closed trade is manually placed or belongs to a different EA or maybe a different symbol/timeframe. ;-)
That's what I wrote also but you only have to do this if other conditions are true for the EA to open a new trade
if you have a huge ordershistoryfile to check everytime a trade has closed or only when it is needed makes a big difference
So if .....
timelastclosedtrade + 15 < TimeCurrent()
then there is no need for checking last closed trade
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use