Download MetaTrader 5

change pending order to market

To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
Sarmad Daneshmand
5008
Sarmad Daneshmand 2016.05.13 15:32 

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 

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.05.13 16:19  
  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);

           }}  
Sarmad Daneshmand
5008
Sarmad Daneshmand 2016.05.13 18:18  
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 

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.05.13 18:38  
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);}

           }} 
Osama Shaban
1448
Osama Shaban 2016.05.13 22:04  

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 

...

To add comments, please log in or register