Download MetaTrader 5
To add comments, please log in or register
Interested in MetaTrader 5 features? Learn more about them!
jon
449
jon 2016.10.28 01:28 

Need some idea (MT5): 

How to allow opening of a new order only after the last order has be opened for at least more than one day?

Fstrifoerr8
36
Fstrifoerr8 2016.10.28 22:53  
jon:

Need some idea (MT5): 

How to allow opening of a new order only after the last order has be opened for at least more than one day?

 1) Create global variable(or static) like bool new_trade=false;

2) Select last order

3) Chek current time-time of order. If it is more than 24*60*60 new_trade=true; else new_trade=false;  

Mary Clark
120
Mary Clark 2016.10.29 01:07  

Do you also want to check a closed order ? If so 

 

datetime lastOrderClose = 0;

for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--)
    if (  OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
    &&  OrderMagicNumber()  == Magic.Number             // my magic number
    &&  OrderSymbol()       == Symbol()             // and my pair.
    &&  OrderCloseTime() > lastOrderClose)
        lastOrderClose = OrderCloseTime();
if (TimeCurrent()-lastOrderClose > 24*60*60)
    new_trade = true;
else new_trade = false;
/
To add comments, please log in or register