I want my EA to avoid doing any transactions within a period after the last transaction closed.
Something strange is happening. My variable that records the closing time for the last transaction "LastOrder" is set back to zero for one iteration when a transaction closes and the bool variable that I use to stop a new transaction to take place within a certain period called "TradeTime" stays false all the time, but for the one iteration when a transaction closes, which allows the unwanted transaction to take place. Here is the data from the Journal.
The answer is in your code . . . make the assumption that your code is always wrong, then your task is simple, find where it is wrong . . .
for (Count = 0; Count <= OrdersTotal() -1; Count++) { if(OrderSelect(Count,SELECT_BY_POS, MODE_HISTORY )
why OrdersTotal() when you are looking through the History pool ? why not OrdersHistoryTotal() ?
Of Course! Stupid me!
Thanks a lot man!
Ernest.
Of Course! Stupid me!
Thanks a lot man!
![](https://c.mql5.com/mql4/forum/2013/07/yes_2.gif)
I want my EA to avoid doing any transactions within a period after the last transaction closed.
bool TradeTime = true; for (Count = 0; Count <= OrdersTotal()-1; Count++) //OrdersHistoryTotal() for(int Count=0;i<OrdersHistoryTotal();Count++) { //or take habit for(int Count=OrdersHistoryTotal()-1;Count>=0;Count--)
if(OrderSelect(Count,SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderCloseTime()!=0 && OrdersTotal() != 0) { datetime LastOrder = OrderCloseTime(); if ((TimeCurrent() - LastOrder) < 100000) TradeTime = false; } } Print("Lastorder is ", LastOrder); Print("Current Time is ", TimeCurrent()); Print("TradeTime is ", TradeTime);
Closed trades you check at OrdersHistoryTotal()
See also other topic you had today
making this function not checking other closed trades if found TradeTime = false;
insert
if(TradeTime == false)break;
for that a loop counting down is faster
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want my EA to avoid doing any transactions within a period after the last transaction closed.
Something strange is happening. My variable that records the closing time for the last transaction "LastOrder" is set back to zero for one iteration when a transaction closes and the bool variable that I use to stop a new transaction to take place within a certain period called "TradeTime" stays false all the time, but for the one iteration when a transaction closes, which allows the unwanted transaction to take place. Here is the data from the Journal.
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: TradeTime is 0
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Hour is 11
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Lastorder is 1363104434
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Time is 1363175883
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: TradeTime is 0
22:41:50 2013.03.13 11:58 Tester: stop loss #3 at 1.30181 (1.30181 / 1.30187)
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Hour is 11
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Lastorder is 0
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Time is 1363175883
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: TradeTime is 1
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: open #4 sell 1.89 EURUSD at 1.30181 sl: 1.30488 tp: 1.29681 ok
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Hour is 11
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Lastorder is 1363104434
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: Current Time is 1363175884
22:41:50 2013.03.13 11:58 MorningSystem EURUSD,H1: TradeTime is 0
Oh! And I just noticed that my LastOrder closing time stays the same in spite of many transactions that are closed, so there must be a problem with my code.
I thought that the loop will continue to find all the closed transactions and overwrite the old data ending with the last closed order's data.
(I did not want to use "Sleep", since the Tester does not recognize it)
Here is the snippet of applicable code. Please help me!