Hi guy please I need help with this . "i'm Beginner in coding"
the code suppose to open only one position buy but it keeps opening unlimited buy positions at the same time I don't know what's wrong . I did break the loop after openbuy();
all I need is that the expert works only on it's trades with MagicN so if there is manually open Position ignore them and open buy position
the buy position will have a MaginN which I did gave in Void OrderSend() of openbuy();
inside your Openbuy() method you have put the OrderSend() within a " for loop ".
Remove that OrderSend from the " for loop" or remove that " for loop " in side your Openbuy() method and it should be fine.
inside your Openbuy() method you have put the OrderSend() within a " for loop ".
Remove that OrderSend from the " for loop" and it should be fine.
The OrderSend() is out side any "for loop" like this .
after the end of Void OnTick ()
I wrote this.
void OnTick() { //--- int total= OrdersTotal (); for ( int A= 0 ;A<total;A++) { if ( OrderSelect (A, SELECT_BY_POS , MODE_TRADES )) if (total> 0 && OrderMagicNumber ()!=MagicN) { openbuy(); break ; printf("if there is open trades"); } } } //+------------------------------------------------------------------+ //| openbuy | //+------------------------------------------------------------------+ void openbuy() { if(OrderSend(Symbol(),OP_BUY,lot1,Ask,3,Bid-StopLoss*Point,Bid+TakeProfit*Point,NULL,MagicN,0,clrBlue)){printf("Order 01");} }
is This true or there some thing wrong and I didn't got it.
The OrderSend() is out side any "for loop" like this .
after the end of Void OnTick ()
I wrote this.
is This true or there some thing wrong and I didn't got it.
int total=OrdersTotal(); // Open a position if there's none if (total==0) { openbuy(); } // Else check for opened positions else { // Loop thru the whole position pool for (int A=0;A<total;A++) { if (OrderSelect (A, SELECT_BY_POS , MODE_TRADES )) if (OrderMagicNumber ()!=MagicN) // <--- this will select only position opened by another ea { // If there's a position perform some action } if (OrderMagicNumber()==MagicN) { } // <--- this will select only positions opened with the same magic number (ea) if (OrderSymbol() == Symbol()) { } // <--- this will select only positions with the same symbol name of the chart the ea is attached too ................. .................... // <--- anything you want - example basic martingale if ((OrderSymbol() == Symbol()) && (OrderProfit() >= 1*AccountBalance()/100)) { openbuy(); } // <---- open a new buy if symbol is the same and profit of the opened position is 1% the account balance } }
There's no error in your code but you're confuse.
The OrderSend() is out side any "for loop" like this .
after the end of Void OnTick ()
I wrote this.
is This true or there some thing wrong and I didn't got it.
it is wrong, cause your " for loop " in the OnTick() method, what you wrote is:
1) you are getting the total orders if there is any order which are open. Then you wrote a " for loop " with an initial of 0 starting.
now let assume that when the EA start to run, there are no open trades right!
NB! Now the for loop is checking if 0 is less than 0, how can it proceed or how can 0 be less than 0 ?
The for loop will not execute any thing.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guy please I need help with this . "i'm Beginner in coding"
the code suppose to open only one position buy but it keeps opening unlimited buy positions at the same time I don't know what's wrong . I did break the loop after openbuy();
all I need is that the expert works only on it's trades with MagicN so if there is manually open Position ignore them and open buy position
the buy position will have a MaginN which I did gave in Void OrderSend() of openbuy();