change pending order to market

 

Hi

How i can change the login here to make the EA open market order trades instead of submitting pending orders.:

 

  if(UseBUYSTOP){ 

           if(StopLoss == 0){Sloss = 0;} else{

           Sloss = Lopen4 - StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{ 

           Tprof = Lopen4 + TakeProfit * point;} 

           int Tiketb = OrderSend(Symbol(),OP_BUYSTOP,lots*(MultiplierLot*4),Lopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrBlue);

           }

         if(UseSELLSTOP){  

           if(StopLoss == 0){Sloss = 0;}else{ 

           Sloss = Sopen4 + StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{  

           Tprof = Sopen4 - TakeProfit * point;} 

           int Tikets = OrderSend(Symbol(),OP_SELLSTOP,lots*(MultiplierLot*4),Sopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrRed);

           }}  

 

Thank you in advance 

 
  if(UseBUYSTOP){ 

           if(StopLoss == 0){Sloss = 0;} else{

           Sloss = Lopen4 - StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{ 

           Tprof = Lopen4 + TakeProfit * point;} 

           int Tiketb = OrderSend(Symbol(),OP_BUY,lots*(MultiplierLot*4),Lopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrBlue);

           }

         if(UseSELLSTOP){  

           if(StopLoss == 0){Sloss = 0;}else{ 

           Sloss = Sopen4 + StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{  

           Tprof = Sopen4 - TakeProfit * point;} 

           int Tikets = OrderSend(Symbol(),OP_SELL,lots*(MultiplierLot*4),Sopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrRed);

           }}  
 
Marco vd Heijden:

Thanks,

but that now created another issue. loop of the trade every time reach that point where the trade must be executed.

how i can make it to only and only trade once? 

Thank you 

 
Sarmad Daneshmand:

Thanks,

but that now created another issue. loop of the trade every time reach that point where the trade must be executed.

how i can make it to only and only trade once? 

Thank you

  if(UseBUYSTOP){ 

           if(StopLoss == 0){Sloss = 0;} else{

           Sloss = Lopen4 - StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{ 

           Tprof = Lopen4 + TakeProfit * point;} 

           if(OrdersTotal()==0){int Tiketb = OrderSend(Symbol(),OP_BUY,lots*(MultiplierLot*4),Lopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrBlue);}

           }

         if(UseSELLSTOP){  

           if(StopLoss == 0){Sloss = 0;}else{ 

           Sloss = Sopen4 + StopLoss * point;}

           if(TakeProfit == 0){Tprof = 0;}else{  

           Tprof = Sopen4 - TakeProfit * point;} 

           if(OrdersTotal()==0){int Tikets = OrderSend(Symbol(),OP_SELL,lots*(MultiplierLot*4),Sopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrRed);}

           }} 
 

As pending orders need to open pips above/down the current price, while market orders are opened at specific price (Lopen4 and Sopen4),

then, orders must opened at Lopen4 and Sopen4 for both buy and sell orders respectively ...

The code must be as follows ... 

if(UseBuyOrder && Ask>=Lopen4){
   if(StopLoss == 0){Sloss = 0;} else{Sloss = Bid - StopLoss * point;}
   if(TakeProfit == 0){Tprof = 0;}else{Tprof = Ask + TakeProfit * point;} 
   int Tiketb = OrderSend(Symbol(),OP_BUY,lots*(MultiplierLot*4),Ask,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrBlue);
}

if(UseSellOrder && Bid<=Sopen4){  
   if(StopLoss == 0){Sloss = 0;}else{Sloss = Ask + StopLoss * point;}
   if(TakeProfit == 0){Tprof = 0;}else{Tprof = Bid - TakeProfit * point;} 
   int Tikets = OrderSend(Symbol(),OP_SELL,lots*(MultiplierLot*4),Sopen4,Slippage*Pip,Sloss,Tprof,EAComment,MagicNumber,0,clrRed);
}  

 You have to make minor changes to make it work the way like you want ...

Change,

UseBUYSTOP >>> UseBuyOrder

UseSELLSTOP >>> UseSellOrder 

...