Download MetaTrader 5

Virtual Trailing stop

To add comments, please log in or register
Ndumiso Mavuso
4556
Ndumiso Mavuso  

I want to replace my trailing stop to Virtual as I am about to change to a broker with 50 point stop level, However I completely have no idea where to start, Can someone enlighten me a little bit.

  //for starters I would start by writing what i know

  for (int i=0; i<OrdersTotal(); i++)
  {    
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  {
  if(OrderSymbol()==Symbol() && MagicNumber==OrderMagicNumber())
  { 
  OderStop = NormalizeDouble(OrderStopLoss(),Digits);
  OderOpen = NormalizeDouble(OrderOpenPrice(),Digits);
  
  
  if (OrderType()==OP_BUY)             
  {              
  if (TrailingStop!=0)
  {
  TrailStop = NormalizeDouble(Bid - TrailingStop*UsePoint,Digits);
   
  if (TrailStop>=OderOpen) SL = DoubleToStr(TrailStop,Digits);
  }           
  if (SL > OderStop)//Problem is here, with Modify the OderStop will be updated to new TrailStop, But if I use OrderClose the OderStop will always be the same, always < all TrailStop
  {
  //Modify here  
  }
  }

  }
  }
  } 

which method to use here?

Marco vd Heijden
Moderator
4802
Marco vd Heijden  

Replace OrderModify() with a double variable and instead of sending the new value to the server, store it in this double.

Then add additional code to close the order whenever price rises of falls above or below that double value.

Ndumiso Mavuso
4556
Ndumiso Mavuso  
Marco vd Heijden:

Replace OrderModify() with a double variable and instead of sending the new value to the server, store it in this double.

Then add additional code to close the order whenever price rises of falls above or below that double value.

Thank you for reply.

Just to make sure you get what my problem is. I need to store the value of SL as OderStop as I am not going to use OrderModify() anymore where OrderStopLoss() is easly available. If what you just explained is what I m saying, could you please explain with a hint of a code, the double variable part leave the OrderClose().

Also the double variable need to be filtering, Only use it if its value is > than the previous.

To add comments, please log in or register