Trailing stop does not work on Sell position

mohammad gerami
46
mohammad gerami  

Hi, Everyone,

I'm getting error whenever I'm starting Strategy Tester. The problem is that Trailing stop works on Buy signals but it does not work on Sell signals. When I place TP and SL in sell OrderSend code everything is fine and automated system works. But I want to activate Trailing stop on it.

I deactivated buy OrderSend and run the code just for Sell and received this error:

TestGenerator: unmatched data error (volume limit 1164 at 2011.03.30 22:00 exceeded)


Here is my Trailing stop code

Thanks in advance


//Position Send
   Trail();
      if(SignalStatus()=="Buy" && Orders(1111)==0) 
      int tiketbuy=OrderSend(Symbol(),OP_BUY,lot,Ask,5,0,0,"Mohammad",1111,0,clrBlue);
      if(SignalStatus()=="Sell" && Orders(2222)==0)
      int tiketsell=OrderSend(Symbol(),OP_SELL,lot,Bid,5,0,0,"Mohammad",2222,0,clrRed);  
/////////////////////

void Trail()
{
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
    {
       if(OrderMagicNumber()==1111) // Buy Position
       {
           if((Bid-OrderOpenPrice())>100*Point)
           {
               if(OrderStopLoss()<(Bid-100*Point))
               {
               bool ordermb=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-100*Point,OrderTakeProfit(),0,clrYellow);
               }
           }
        }
       if(OrderMagicNumber()==2222) // Sell Position
        {
              if((OrderOpenPrice()-Ask)>100*Point)
              {
                  if(OrderStopLoss()>(Ask+100*Point))
                  {
                  bool orderms=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+100*Point,OrderTakeProfit(),0,clrYellow);
                  }
              } 
        }  
     }
   }
}

William Roeder
23727
William Roeder  
  1. bool orderms=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+100*Point,OrderTakeProfit(),0,clrYellow);

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014


  2.                   if(OrderStopLoss()>(Ask+100*Point))
    Your initial sell SL is zero (none) so your if will never be true. Add ||OrderStopLoss()==0 or set a SL on the OrderSend.
mohammad gerami
46
mohammad gerami  
William Roeder:
  1. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014


  2. Your initial sell SL is zero (none) so your if will never be true. Add ||OrderStopLoss()==0 or set a SL on the OrderSend.

Thanks a lot  ||OrderStopLoss()==0 works here