-
for(int index = OrdersTotal() - 1; index >= 0; index--) if ( ( OrderSelect(index, SELECT_BY_POS) && OrderMagicNumber() == 34567 ) || ( true && OrderSymbol() == Symbol() ) ) static datetime newAllowed; newAllowed = TimeCurrent() + 20 * 1; // No new trade until this one closes 20 sec * min if (TimeCurrent() < newAllowed) return(0); // No new trades yet.
Rewrote your code to Precedence Rules. - True is non-zero. Your if selects magic number 34567 on any chart or any trade on the current symbol.
- The body of the for and if does nothing.
- NewAllowed is always set to the future each tick and you never trade.
-
total=OrdersTotal(); if(total<1) { // no opened orders identified if(AccountFreeMargin()<(3*Lots)) … if(OrdersTotal()>0){ for(i=1; i<=OrdersTotal(); i++)
When will the last if and for ever run? -
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
PositionClose is not working - MQL5 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi,
I am trying to put a 20 sec delay after STOP LOSS hits and wrote some code about it but it fails, where am i wrong, any help please?
Orange highlighted area is the part where i am trying to put some delay