Download MetaTrader 5

Open Opposite Order immediately after Stop Loss hit

To add comments, please log in or register
AhmedMorra
50
AhmedMorra  

Hello 

I need to Open a new Opposite order immediately after stop loss hit

if i have a buy order and the Stop loss hit immediately open a sell order with a stop loss at the open price of the previous order and a take profit target 2 times the SL

and if i have a sell order and the stop loss hit immediately open a buy order with a stop loss at the open price of the previous order and a take profit target 2 times the SL

here is my code

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
datetime Time0 = 0;
void OnTick()
  {
//---
   if (Time0 != Time[0])
  {
  
  
  double cc = iCCI(NULL,0,14,PRICE_TYPICAL,1);
  
  //buy
  if(cc < -100 &&
     Close[1] > Open[2] &&
     Close[1] > Open[1] &&
     Close[2] < Open[2]
     ){
     OrderSend(NULL,OP_BUY,(AccountBalance()/100)/(100000*((Close[1]-Low[1])*1)),Ask,3,Low[1],Close[1]+((Close[1]-Low[1])*2),NULL);
     }
   //sell
   if(cc > 100 &&
      Close[1] < Open[2] &&
      Close[1] < Open[1] &&
      Close[2] > Open[2]
      ){
      OrderSend(NULL,OP_SELL,(AccountBalance()/100)/(100000*((High[1]-Close[1])*1)),Bid,3,High[1],Close[1]-((High[1]-Close[1])*2),NULL);
      }  

     Time0 = Time[0];
  }
  }
//+------------------------------------------------------------------+

I searched in the forum and tried to use the code in this post https://www.mql5.com/en/forum/155948#comment_3801295

but it didn't work even if i didn't use the last open order price as a stop loss and used a normal distance of pips stop loss

Open Order immediately after last Oder hit Stop Loss
Open Order immediately after last Oder hit Stop Loss
  • 2015.06.19
  • www.mql5.com
Hello everyone, I have a question. Can anyone help me coding the following thing...
nicholishen
1528
nicholishen  
AhmedMorra:

Hello 

I need to Open a new Opposite order immediately after stop loss hit

if i have a buy order and the Stop loss hit immediately open a sell order with a stop loss at the open price of the previous order and a take profit target 2 times the SL

and if i have a sell order and the stop loss hit immediately open a buy order with a stop loss at the open price of the previous order and a take profit target 2 times the SL

here is my code

I searched in the forum and tried to use the code in this post https://www.mql5.com/en/forum/155948#comment_3801295

but it didn't work even if i didn't use the last open order price as a stop loss and used a normal distance of pips stop loss

It would be better to open an opposite stop-order at your stop loss so you wouldn't have to worry about network latency causing more slippage
AhmedMorra
50
AhmedMorra  
nicholishen:
It would be better to open an opposite stop-order at your stop loss so you wouldn't have to worry about network latency causing more slippage

but then i have to deal with the expiration of the order, i prefer market orders

nicholishen
1528
nicholishen  
AhmedMorra:

but then i have to deal with the expiration of the order, i prefer market orders

What do you mean? 
AhmedMorra
50
AhmedMorra  
nicholishen:
What do you mean? 

if the first position reached TP target then how i am gonna close the pending order at the SL ?

To add comments, please log in or register