you need to fix at least this:
int MyTotalOrdersCount() { int count=0; for(int i=OrdersTotal()-1;i>=0;i--) // always back to front { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; // an OrderSelect might fail!!! if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber) count++; // only my magic and my symbol } return count; }
Hello, I have an EMas crossover EA, one of 5 periods and another of 100. when ema 5 crosses the long ema and is 500 points away from ema 100 an operation is opened. but if the price goes against the tp and crosses the ema in the opposite direction, another operation opens in the direction of the trend without closing the previous operation.
The problem is the following:
The first operation that opens works well, either buy or sell. but when it goes against and crosses the ema 100 in the opposite direction, the other operation opens but many operations begin to open at the same time. I just want only one to open in that direction, and it will go in I want another one to open again, but without closing the previous one, but for a single operation to be opened every time the ema 100 is crossed.
What I want is that every time the ema crosses in a direction before the tp of the open operation is reached, a new operation is opened, either a purchase or a sale without closing the previous operations that are open. and that each new order has a lot and a higher tp that covers the losses of all the operations opened up to that moment.
Heres my code:
Hello,
should be replace start() function with OnTick() function.
OnStart() function run once time.
OnTick() function run every tick.

- www.mql5.com
try my version of the 'MyTotalOrdersCount'
int MyTotalOrdersCount() { int count=0; for(int i=OrdersTotal()-1; i>=0; i--) // always back to front { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; // an OrderSelect might fail!!! if(OrderSymbol()!=_Symbol && OrderMagicNumber()!=MagicNumber) continue; if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber) if(OrderType() == OP_SELL || OrderType() == OP_BUY) count++; // only my magic and my symbol } return(count); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I have an EMas crossover EA, one of 5 periods and another of 100. when ema 5 crosses the long ema and is 500 points away from ema 100 an operation is opened. but if the price goes against the tp and crosses the ema in the opposite direction, another operation opens in the direction of the trend without closing the previous operation.
The problem is the following:
The first operation that opens works well, either buy or sell. but when it goes against and crosses the ema 100 in the opposite direction, the other operation opens but many operations begin to open at the same time. I just want only one to open in that direction, and it will go in I want another one to open again, but without closing the previous one, but for a single operation to be opened every time the ema 100 is crossed.
What I want is that every time the ema crosses in a direction before the tp of the open operation is reached, a new operation is opened, either a purchase or a sale without closing the previous operations that are open. and that each new order has a lot and a higher tp that covers the losses of all the operations opened up to that moment.
Heres my code: