my first personal ea open a lot of position

 

i'm not expert and i write my 1 ea , but when it run it open a lot of position and no only one 

the logic are that :

 

cheak for open condition or true => i use a while ( if  cheak are ok open) , but it open a lot of position a no only one 

 

 i use the total = order total()   if is < 2 open and it open if condition buy are ok 2 position 

 

i use that solution but not work :  while(A) ( if (cheak are true and condition A are true => open position, put A = false and put B = true t= time current 

 

B are from other while (b) where: ( T = count second (t) and if  T are> es 360 => put B= false (to interrup the cicle and put a true to have the possibility to open a new position )

 what i can do for that ? 

 
asaqaz:

i'm not expert and i write my 1 ea , but when it run it open a lot of position and no only one 

the logic are that :

 cheak for open condition or true => i use a while ( if  cheak are ok open) , but it open a lot of position a no only one 

 i use the total = order total()   if is < 2 open and it open if condition buy are ok 2 position 

This is MT5 not MT4,  when an Order is executed you have a Position,  if you open a new order on the same symbol and it is executed you will still have just one Position.  OrdersTotal() will return the number of currently open pending Orders . . .  did you read the documentation ?

This might help:  Orders, Positions and Deals in MetaTrader 5
 

try this way

 

  if(OrdersTotalMagicsell(Magicsell)<1)
      if(Stochastic && stok0<stok1&&stok1<zoneSELL)   
            {ticketsell =  OrderSend(Symbol(),OP_SELL,lotssell,Bid,3,sls,0,"Expert Stochastic"+Magicsell,Magicsell,0,Red);


 
ismail77:

try this way

 

  if(OrdersTotalMagicsell(Magicsell)<1)
      if(Stochastic && stok0<stok1&&stok1<zoneSELL)   
            {ticketsell =  OrderSend(Symbol(),OP_SELL,lotssell,Bid,3,sls,0,"Expert Stochastic"+Magicsell,Magicsell,0,Red);


This is the mql5 forum . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button. 

Reason: