Help me fix my ea

 

Hello

the idea is this :

only 1 trade per symbol allowed.

i use to do it like this:

int total = OrdersTotal();

if(total != 0 )

{

return(0); // dont trade

}

else

trade

but the problem is that i have other open position from manual trades\other EA

i need that the ea will open only 1 trade per symbol.

please help, thanks!

Files:
boo01.mq4  6 kb
 

Use MagicNumber to identify the trades placed by your EAs. Read up on Magicnumber by our gracious Coder's Guru and you will have a very good idea on what to do.

Good luck.

 

where can i read about it?

 

ok, i have 666 as magic number to trades that open in the ea

is this code any good?

if(OrderSelect(ticket, SELECT_BY_TICKET) == true) // open trades

{

if(OrderMagicNumber() == 666){

return(0);} // no trades

}

else

trade

 

Again, do a search, I am sure you will find Coder's Guru's lessons. There is nothing better than learning how to do it right.

I am providing you with a subroutine that will count the number of trades for a given symbol and a given magicnumber. You can call that to find the number of trades, and if it is equal to or less than a certain number, you can place your trades.

int CountTrades(int MagicNumber)

{

int count=0;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber)

continue;

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

count++;

}//for

return(count);

}

 

maji, thank you very much!!

I got it now.

Reason: