Rgd My Trail Stop Code need some modification

 

Rgd My Trail Stop Code need some modification

Hi guys, thanks for reading.

I have this following trail stop code which working perfectly. But i need some changes, basically what I need is assume I am setting Trail stop to be 10 Points. But I want the profit to be at least +N pips from open price.

That is ..

If i buy eur/usd at 1.3010, the price now is 1.3020, by right if I set 10 points for trail.

My s/l will be modified to 1.3010 (which is my open price). Is it possible to modify the code below so that it will only set trail stop when price is 1.3022 and s/l will be 10 points + N gap (which in this case I set as 2), prefer N to be a variable.

So when price is 1.3020, although I set 10 points, it will not set S/L to 1.3010 but wait till 10 Points + N Points (where in this case N is 2), means at least 1.3022 then It start set the trail stop to 1.3012

Thanks

extern int TrailingStop=10;
extern double StopLoss = 0; 

   double PointValue;
  for (int i = 0; i < OrdersTotal(); i++) 
  {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      //Calculate the point value in case there are extra digits in the quotes
      if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001;
      else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01;
      else PointValue = MarketInfo(OrderSymbol(), MODE_POINT);
      //Normalize trailing stop value to the point value
      double TSTP = TrailingStop * PointValue;
 
      if (OrderType() == OP_BUY)
      {
         if (Bid - OrderOpenPrice() > TSTP)
         {
            if (OrderStopLoss() < Bid - TSTP)
            {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TSTP, OrderTakeProfit(), Red))
                  Print("Error setting Buy trailing stop: ", GetLastError());
            }
         }
         else if ((OrderStopLoss() != Bid - StopLoss * PointValue) && (StopLoss != 0))
            if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - StopLoss * PointValue, OrderTakeProfit(), Red))
               Print("Error setting Buy stop-loss: ", GetLastError());
      }
      else if (OrderType() == OP_SELL)
      {
         if (OrderOpenPrice() - Ask > TSTP)
         {
            if ((OrderStopLoss() > Ask + TSTP) || (OrderStopLoss() == 0))
            {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TSTP, OrderTakeProfit(), Red))
                  Print("Error setting Sell trailing stop: ", GetLastError());
            }
         }
         else if ((OrderStopLoss() != Ask + StopLoss * PointValue) && (StopLoss != 0))
            if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + StopLoss * PointValue, OrderTakeProfit(), Red))
               Print("Error setting Sell stop-loss: ", GetLastError());
      }
        }   
 
Sounds like a job request to me. Here.