HELP ANY IDEA

 

hello I'm going to try to color-code this to make this easier to understand, hope this help. IF ANY IDEA PLEASE SHARE! THANK YOU


I'm trying to add "CheckTrailingStop" this to "trade.Buy" in the S top-Loss Price Place

is there away to only have the  CheckTrailingStop  And NOT Ask-1000 or 0




if (signal =="buy" && PositionsTotal()<1)

       trade.Buy(0.10,NULL,Ask,Ask-1000,Ask+1000,NULL);


OR


if (signal =="buy" && PositionsTotal()<1)

       trade.Buy(0.10,NULL,Ask,0,Ask+1000,NULL);


I'm running out of idea how to do this, there the CheckTrailingStop  code 


Thank you



if (signal =="buy" && PositionsTotal()<1)
       trade.Buy(0.10,NULL,Ask,Ask-1000,Ask+1000,NULL);
      
      Comment ("The signal is now: ",signal); 
      
      CheckTrailingStop(Ask);
  }
  
void  CheckTrailingStop(double Ask)
  {
  
      double SL=NormalizeDouble(Ask-150,_Digits);
      
      for(int i=PositionsTotal()-1; i>=0; i--)
      {
      
         string symbol=PositionGetSymbol(i);
         
         if (_Symbol==symbol)
        
         {
            ulong PositionTicket=PositionGetInteger(POSITION_TICKET);
            
            double CurrentStopLoss=PositionGetDouble(POSITION_SL);
            
            if (CurrentStopLoss<SL)
            
            {
            trade.PositionModify(PositionTicket,(CurrentStopLoss+10),0);
            }
         }
      }
      
  
  
  }


if (signal =="buy" && PositionsTotal()<1)
       trade.Buy(0.10,NULL,Ask,0,Ask+1000,NULL);
      
      Comment ("The signal is now: ",signal); 
      
      CheckTrailingStop(Ask);
  }
  
void  CheckTrailingStop(double Ask)
  {
  
      double SL=NormalizeDouble(Ask-150,_Digits);
      
      for(int i=PositionsTotal()-1; i>=0; i--)
      {
      
         string symbol=PositionGetSymbol(i);
         
         if (_Symbol==symbol)
        
         {
            ulong PositionTicket=PositionGetInteger(POSITION_TICKET);
            
            double CurrentStopLoss=PositionGetDouble(POSITION_SL);
            
            if (CurrentStopLoss<SL)
            
            {
            trade.PositionModify(PositionTicket,(CurrentStopLoss+10),0);
            }
         }
      }
      
  
  
  }
 

Hi and good morning,

I took a quick look at your code. One Problem is you are not working with points.

   double SL=NormalizeDouble(Ask - (150 * _Point), _Digits);


I hope, this helps you.

Best regards

 
Another problem is, you are using NormalizeDouble. It does not take into account the step size of the price value.