Hello all, I would like to know how to solve following problem.
1. One EA working on 20 Pair. EA open position with EAMagicNumber=5000. EA open only one position on lifetime. For example, If EA open one position ( EAMagicNumber=5000 ) on XAUUSD, then other pair can't open position with EAMagicNumber=5000. EA don't allow open position on other pair.
I attach following code. But that code doesn't work. How do I solve that problem?
is this a separate function that returns the notAllow ?
No, I think notAllow is public variable. So it doesn't require return value.
void FirstPositions() { //Alert(StringFind(OrderComment(),"Martingale",0)); for(int i=OrdersHistoryTotal()-1;i>=0;i--) { int chkA=OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if(OrderMagicNumber()==EAMagicNumber) { notAllow=true; } } for(int j=OrdersTotal()-1;j>=0;j--) { int chkB=OrderSelect(j, SELECT_BY_POS,MODE_TRADES); if(OrderMagicNumber()==EAMagicNumber) { notAllow=true; } } }
So, once the global variable is set to true, it remains so forever.
this .
try
void FirstPositions() { static bool Allow=true; //Alert(StringFind(OrderComment(),"Martingale",0)); //note : does OrdersHistoryTotal return entire history ? for(int i=OrdersHistoryTotal()-1;i>=0;i--) { bool select=OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if(select){ if(OrderMagicNumber()==EAMagicNumber) { Allow=false; } } } for(int j=OrdersTotal()-1;j>=0;j--) { bool select=OrderSelect(j, SELECT_BY_POS,MODE_TRADES); if(select){ if(OrderMagicNumber()==EAMagicNumber) { Allow=false; } } } }for note : https://docs.mql4.com/trading/ordershistorytotal
- docs.mql4.com
- Same thing; once the static is set to false, it remains that way forever. The static is internal to the function and can't ever be seen, thus is useless.
- Delete the static and make the function return the result.
indeed .
I did not know that .
The fact i could not use it outside its function should have given me a hint .
Thanks
indeed .
I did not know that .
The fact i could not use it outside its function should have given me a hint .
Thanks
You search orders in history :)
so you can Just open One order with this magic number.
you have to search magic number in your opening orders/positions
for ( int i = OrdersTotal() - 1; i >= 0; i--) { ... ...
You search orders in history :)
so you can Just open One order with this magic number.
you have to search magic number in your opening orders/positions
one loop ?
- 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 all, I would like to know how to solve following problem.
1. One EA working on 20 Pair. EA open position with EAMagicNumber=5000. EA open only one position on lifetime. For example, If EA open one position ( EAMagicNumber=5000 ) on XAUUSD, then other pair can't open position with EAMagicNumber=5000. EA don't allow open position on other pair.
I attach following code. But that code doesn't work. How do I solve that problem?