MT4 buy and sell trailling stoploss MQL4

  

   

   if (Trade=="BUY")

   {

   if (Close[0]>=tsl_lv&&tsl_lv>0 )

   {

   

   for (int b = OrdersTotal()-1;b>=0;b--)

   {

   

   if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

   {

   if(OrderSymbol()==Symbol()&& OrderType()==OP_BUY)

   {

   sll=sll+(TSL*MyPoint);

   OrderModify(OrderTicket(),OrderOpenPrice(),sll,OrderTakeProfit(),0,clrNONE);

   tsl_lv=Close[0]+TSL*MyPoint;

   

   }      

   }

   }  

   }  

   }

   

   

   

    if (Trade=="SHORT")

   {

   if (Close[0]<=tsl_lv&&tsl_lv>0 )

   {

   

   for (int b = OrdersTotal()-1;b>=0;b--)

   {

   

   if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

   {

   if(OrderSymbol()==Symbol()&& OrderType()==OP_SELL)

   {

   sll=sll-(TSL*MyPoint);

   OrderModify(OrderTicket(),OrderOpenPrice(),sll,OrderTakeProfit(),0,clrNONE);

   tsl_lv=Close[0]-TSL*MyPoint;

   

   }      

   }

   }  

   }  

   }

  

Comments

Popular posts from this blog

MQL5 : Add time to current time in mins

MQL5 : Get current trading session