Please use this to post code . . . it makes it easier to read.
Not sure why you need the flags . . why not just do . .
if(TimeCurrent() > locktime){ if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); }
RaptorUK:
Please use this to post code . . . it makes it easier to read.
Not sure why you need the flags . . why not just do . .
And how is locktime calculated? I think there has to be some kind of flag/lock (what ever you call it) to prevent the locktime from changing all the time. You want the locktime to be the same all the time, you want to wait until the locktime before you enter the next trade.
OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY); if(OrderProfit()<0){ if(flag!=2){ timelock=0; flag=2; ctm=TimeCurrent(); locktime=ctm+3600; } currenttime=TimeCurrent(); if(currenttime>locktime){ timelock=1; flag=1; } } else timelock=1; if(timelock!=0){ if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); }
OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
This selects the last order closed (failure is never tested for) not the last order closed on this chart by this EA.
time lock should be calculated from the close of the last order.
datetime timelock; for(int pos= OrdersHistoryTotal()-1; pos >= 0; pos--) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360 ){ if(OrderProfit()<0){ timeLock = OrderCloseTime() + 3600; // Delay one hour } break; // Found my last order } if (TimeCurrent() > timeLock) // OK to trade...
WHRoeder:
This selects the last order closed (failure is never tested for) not the last order closed on this chart by this EA.
time lock should be calculated from the close of the last order.
Used orderclosed before but it didn´t show the correct day, but now it´s correct. Thanks.
Please help me how to protec active bounds at ea with time and date
- Don't hijack someone's unrelated thread
- I have no idea what your asking.
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
I trie to create a time lock with this code but it doesn´t work all the time. Less trades are created, but when looking at the result I can se that there are two losses occuring within a smaller timeframe than the coded time lock should accept. Code explanation: If orderprofit is less than 0 I catch the current time and set a flag, the flag is unlocked and the timelock is set to ok then the current time is more than the time I catched previously. The problem maybe is where in the startloop you place the time lock, or what is wrong? Maybee there is an easier way to code the same functionality.
OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
if(OrderProfit()<0){
if(flag!=2){
timelock=0;
flag=2;
ctm=TimeCurrent();
locktime=ctm+3600;
}
currenttime=TimeCurrent();
if(currenttime>locktime){
timelock=1;
flag=1;
}
}
else timelock=1;
if(timelock!=0){
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
}