Help with trailing stop !!

Back to topics list To post a new topic, please log in or register
avatar
34
Stan4o1 2016.03.29 09:30
 

Hi all,

I have a problem with my EA, i created a trailing stop function, it works but in the tester is says "Order modify error 1" - i suppose this is for modifying the already modified order, but i need help for solving the problem - How can i make my function modify only once? Thanks in advance

     void trailingstop ()
    {
    bool modify = false;
  if(UseTrailingStop)
  {
    for(int i =0;i<OrdersTotal();i++)
    {
    if(!OrderSelect(i,SELECT_BY_POS))
    continue;
    if(  OrderMagicNumber()==magic &&  OrderType()==OP_BUY && Ask-OrderOpenPrice()>trailingcriteria*point && Ask>OrderOpenPrice())
    {
  modify =  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+trailingstopsize*point,OrderTakeProfit(),0,clrAliceBlue);
  
    }
  else if ( OrderMagicNumber()==magic && OrderType()==OP_SELL &&  OrderOpenPrice()-Bid>trailingcriteria*point && Bid<OrderOpenPrice()) 
  {
    modify =  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-trailingstopsize*point,OrderTakeProfit(),0,clrAliceBlue);  
   
  }
  }
  //------------
  if(modify)
  {
  Print("TRAILING STOP initialized!!!");
  }
  }
  //--------------
   return ;
    } 

 

avatar
Moderator
3404
GumRai 2016.03.29 10:29 #
 

Use bid when calculating TS for a buy, ask for a sell.

Before modifying the stop, check that the new stop will be higher than the existing stop (for a buy)

avatar
34
Stan4o1 2016.03.29 14:14 #
 
Thanks
Back to topics list  

To add comments, please log in or register