Open Opposite Order immediately after Stop Loss hit

 

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...
 
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
 
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

 
AhmedMorra:

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

What do you mean? 
 
nicholishen:
What do you mean? 

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

 
nicholi shen:
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
how can you go about coding that?
 
AhmedMorra: i am gonna close the pending order at the SL ?

You don't close pending order anywhere. They are pending, you delete them.

 
nicholi shen: 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

This fails on US brokers because of no hedging. The open price must be far enough that the original SL has triggered.

Reason: