Trailing Stop in Money Instead of Pip

 

Hello lovely people,

I would want to code a trailing stop in money instead of in pips. I will gracefully appreciate any help on how to achieve it correctly. Below is my attempt at it.


input double TrailingStop   = 8;
input double TrailingStep   = 2; 
input double TrailingStart  = 2;
bool res;

void Trailing_inMoney()
  {
   int res;
   double TSL=0;
   double Current_SL=(OrderStopLoss()!=0)?OrderStopLoss():OrderOpenPrice();


   double tick_size=SymbolInfoDouble(OrderSymbol(),SYMBOL_TRADE_TICK_SIZE);
   double pnt=SymbolInfoDouble(OrderSymbol(),SYMBOL_POINT);
   double minfromcurrentprice=SymbolInfoInteger(OrderSymbol(),SYMBOL_TRADE_STOPS_LEVEL)*pnt;
   double loss_for_1_lot=SymbolInfoDouble(OrderSymbol(),SYMBOL_TRADE_TICK_VALUE);  //Loss/Gain for a 1 tick move with 1 lot
   double loss_for_lot_size_this_trade=loss_for_1_lot*OrderLots();    //Loss/Gain for a 1 tick move with trade lot size
   double TP_ticks=TrailingStart/loss_for_lot_size_this_trade; //Trailing start
   double TP_points=MathFloor(TP_ticks*tick_size/pnt)*pnt; //TP_start

   double Max_tp_in_Money_ticks=TrailingStop/loss_for_lot_size_this_trade; // Trailing stop
   double Max_tp_in_Money_points=MathFloor(Max_tp_in_Money_ticks*tick_size/pnt)*pnt; 


   double Step_tp_in_Money_ticks=TrailingStep/loss_for_lot_size_this_trade; //Trailing step
   double Step_tp_in_Money_points=MathFloor(Step_tp_in_Money_ticks*tick_size/pnt)*pnt;      
//   Print("CurrentSL ", Current_SL);

   for(int i = OrdersTotal()-1; i >= 0; i--) //Check this properly
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

           {
           // Max_tp_in_Money_points = Max_tp_in_Money_points + (int)MarketInfo(OrderSymbol(),MODE_STOPLEVEL);
            
            if(OrderType()==OP_BUY && (Bid-OrderOpenPrice()>TP_points))
              {


               if(TP_points>0)
                 {
                  RefreshRates();
                  if(Current_SL<OrderOpenPrice())
                     Current_SL=OrderOpenPrice();

                  if(OrderStopLoss()< (Bid-(Max_tp_in_Money_points + Step_tp_in_Money_points)) ||
                     (Bid-Current_SL)>=Max_tp_in_Money_points)


                    {

                           TSL=NormalizeDouble(Bid-Max_tp_in_Money_points,(int)Digits());

                     res = OrderModify(OrderTicket(),OrderOpenPrice(),TSL,OrderTakeProfit(),0,clrGreen);
                    }
                 }
              }

            else
               if(OrderType()==OP_SELL && (OrderOpenPrice()-Ask>TP_points))
                 {

                  if(TP_points>0)
                    {
                     RefreshRates();
                     if(Current_SL>OrderOpenPrice())
                        Current_SL=OrderOpenPrice();

                     if((OrderStopLoss()>(Ask+Max_tp_in_Money_points+Step_tp_in_Money_points)) ||
                        (Current_SL-Ask)>=Max_tp_in_Money_points)
                       {


                              TSL=NormalizeDouble(Ask+Max_tp_in_Money_points,(int)Digits());


                        res = OrderModify(OrderTicket(),OrderOpenPrice(),TSL,OrderTakeProfit(),0,clrRed);
                       }
                    }
                 }
           }
        }
     }
  }
 

To trade in money instead of pips will require you to do a number of conversations.

1. Find the value per pip per lot size.  Look at the change in price per pip.   ie:  EURUSD  1 pip/ 0.9967 price =  1.003 eur

2. Multiply by the number of unts you have 10 units   = trade value is 10.03

3. multiply this by your trading currency.     EUR to GBP   10.03 X 0.8431 = 8.74 GBP