SL Moving not correctly

 

Hello,

I need some help please for a function. I have an EA, and when the SL moves, it only moves at the bid or ask price, like you can see in picture.


Below, i part of the code concern by the stop loss :


Can you help me please for that the SL moves at for example 30 pips?


Thanks.


Best Regards,

SL Moving


bool orders_management()
{
  double pips=Point;
  if(Digits == 3 || Digits == 5) pips=Point*10;
  if(orders_total()>0){
  //Volumen setting for 20 and 80%
  for(int i=0;i<OrdersTotal();i++)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
    {
      if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && magic==OrderMagicNumber())
      {
        //30 pips
        if(MathAbs(OrderOpenPrice()-bid)>breakeven*pips && MathAbs(bid-stop_loss*pips)>OrderStopLoss())
        {
          if(!OrderClose(ticket,lot*0.2,OrderClosePrice(),slippage,clrRed))
          {
            Print("OrderClose() not modified with 80% of profits, error: "+GetLastError());
          }
          Print("Breakeven applied wit "+breakeven+" || trailing_stop active with trailing_stop: "+trailing_double+" pips");
          ObjectsDeleteAll(0,OBJ_LABEL);
          label_create("Breakeven applied"," || Breakeven applied || trailing_stop active with "+trailing_double+" pips",390,2,90,ys_label,clrBlue); //TimeHour(TimeCurrent())
          if(!OrderModify(OrderTicket(),OrderOpenPrice(),bid-stop_loss*pips,OrderTakeProfit(),0,clrGreenYellow))
          {
            Print("FUNCTION: "+__FUNCTION__+"() || buy´s order modified successfully. Trailing_stop active with: "+trailing_double+"pips");
          }
          else Print("FUNCTION: "+__FUNCTION__+"() || error: "+GetLastError());
        }
      }
      else if(OrderType()==OP_SELL && OrderMagicNumber()==magic && OrderSymbol()==Symbol())
      {
        //30 pips
        if(MathAbs(OrderOpenPrice()-ask)>breakeven*pips && (ask+stop_loss*pips)<OrderStopLoss())
        {
          if(!OrderClose(ticket,lot*0.2,OrderClosePrice(),slippage,clrRed))
          {
            Print("OrderClose() not modified with 80% of profits, error: "+GetLastError());
          }
          Print("Breakeven applied with "+breakeven+" || trailing_stop active with trailing_stop: "+trailing_double+" pips");
          ObjectsDeleteAll(0,OBJ_LABEL);
          label_create("Breakeven applied"," || Breakeven applied || trailing_stop active with "+trailing_double+" pips",390,2,90,ys_label,clrBlue);
          if(!OrderModify(OrderTicket(),OrderOpenPrice(),ask+stop_loss*pips,OrderTakeProfit(),0,clrGreenYellow))
          {
            Print("FUNCTION: "+__FUNCTION__+"() || sell´s order modified successfully. Trailing_stop active with: "+trailing_double+"pips");
          }
          else Print("FUNCTION: "+__FUNCTION__+"() || error: "+GetLastError());
        }        
      }
    }
  }
}
  return(true);
}
 
Nicolas Charles Christian Macary:

Hello,

I need some help please for a function. I have an EA, and when the SL moves, it only moves at the bid or ask price, like you can see in picture.


Below, i part of the code concern by the stop loss :


Can you help me please for that the SL moves at for example 30 pips?


Thanks.


Best Regards,



i attached a trailingstop code here

place this one instead

set amount for trailingstop variable for e.x. (30)

this code will change stoploss every 30 pips

Files:
1.mq4  1 kb
Reason: