Download MetaTrader 5

help with step in the trailing SL & TP in MQL5

To add comments, please log in or register
vivek visale
703
vivek visale  

hi guys, I appreciate that you took time to read this.


the problem is that i am new in mql5 coding, i know a lot in mql4, but in mql5 i am not able to make the SL trailing, I have an EA which works on mql5, the EA does trail SL for loosing trade as well as profiting trade, but i cannot change the step...so can you please help me with it


the below code has a step i guess, but it is very high i guess, because if the trade is in profit of 70 pips, then also the SL is trailed to its half only

for(i=0;i<PositionsTotal();i++)
     {
      if(Symbol()==PositionGetSymbol(i))
        {
             if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
               {
               if(SL>0)  //start of if
                  {                 
                     if(Bid-PositionGetDouble(POSITION_SL)>_Point*SL)
                     {
                        if(PositionGetDouble(POSITION_SL)<Bid-_Point*SL)
                        {
                              request.action = TRADE_ACTION_SLTP;
                              request.symbol = _Symbol;
                              request.sl = Ask - SL*_Point;
                              request.tp = PositionGetDouble(POSITION_TP);
                              OrderSend(request, result);
                              return;
                        }
                     }
                  } //end of if sl>0
                  
                  
                  if(TP>0)  //start of if
                  {                 
                     if(Bid-PositionGetDouble(POSITION_SL)>_Point*SL)
                     {
                        if(PositionGetDouble(POSITION_SL)<Bid-_Point*SL)
                        {
                              request.action = TRADE_ACTION_SLTP;
                              request.symbol = _Symbol;
                              request.sl = Ask - SL*_Point;
                              request.tp = PositionGetDouble(POSITION_TP);
                              OrderSend(request, result);
                              return;
                        }
                     }
                  } //end of if TP>0
                                                    
               }
            
              if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
               {
                  if(SL>0)  
                  {                 
                  if((PositionGetDouble(POSITION_SL)-Ask)>(_Point*SL))
                     {
                        if((PositionGetDouble(POSITION_SL)>(Ask+_Point*SL)) || (PositionGetDouble(POSITION_SL)==0))
                        {
                           request.action = TRADE_ACTION_SLTP;
                           request.symbol = _Symbol;
                           request.sl = Bid + SL*_Point;
                           request.tp = PositionGetDouble(POSITION_TP);
                           OrderSend(request, result);
                           return;
                        }
                     }
                  }
                  
                  
                  if(TP>0)  
                  {                 
                  if((PositionGetDouble(POSITION_SL)-Ask)>(_Point*SL))
                     {
                        if((PositionGetDouble(POSITION_SL)>(Ask+_Point*SL)) || (PositionGetDouble(POSITION_SL)==0))
                        {
                           request.action = TRADE_ACTION_SLTP;
                           request.symbol = _Symbol;
                           request.sl = Bid + SL*_Point;
                           request.tp = PositionGetDouble(POSITION_TP);
                           OrderSend(request, result);
                           return;
                        }
                     }
                  }
               }
         }
      }


so as i said above, the SL is trailed to only the half...while i want the SL to trail for 10 pips with every 25 pip movement, please help me with this


thanks

To add comments, please log in or register