EA Not sending TP orders

 

I've written an EA that seems to be working as anticipated when I backtest or run in Visual Mode. When I first started trading on live data, I was plagued by "Order Off Quotes" errors. After much reading on the forums, I modified my code and was able to get this issue resolved. However, it is still not placing my TP orders properly. My logs show that the the modification is being sent properly, but the orders never adjust to they new prices (they maintain a value of 0). The SL orders are modified properly, so I am not sure what I am doing wrong. Any pointers would be appreciated.

bool PlaceLongEntries()
{
   if (InitialStopType==0)
      sv = InitialStopLoss*Point;
   else
      sv = -iATR(NULL,ATRTimeValue,ATRLength,1)*InitialStopLoss;
               
   for (x=0;x<4;x++)
   {
      if (longTicket[x]==-1)
      {
         if (x<3)
         {
            if (TargetType==0)
               targetPrice = NormalizePrice(Ask+targetValue[x]*Point);
            else
               targetPrice = NormalizePrice(Ask+targetValue[x]*iATR(NULL,ATRTimeValue,ATRLength,1));
         }
         else
            targetPrice = 0;
      
         longStopPrice = NormalizePrice(Ask+sv);
         longTicket[x] = OrderSend(Symbol(),OP_BUY,tradeSize[x],Ask,slippage,0,0,"",MagicNumber[x],0,Blue);                           
         
         if(longTicket[x]>0)
         {
            if(OrderSelect(longTicket[x],SELECT_BY_TICKET,MODE_TRADES))
            {               
               OrderPrint();               
               ordermodify = 0;             
               if(longStopPrice != OrderStopLoss() || targetPrice != OrderTakeProfit())
               {              
                  ordermodify = OrderModify(OrderTicket(),OrderOpenPrice(),longStopPrice,targetPrice,0,Green);                              
                  if ( ordermodify > 0 )
                  {
                     OrderPrint();
                     Print( "Modify buy ",OrderTicket(), " done!");                     
                  }
                  else
                  {
                     error = GetLastError();
                     Print("Modification buy failed! GetLastError = ", error, ", ErrorDescription =  \"", ErrorDescription( error ), "\"" );       
                  }
               }
            }   
         }
         if(longTicket[x]<0)
         {
            error=GetLastError();
            Print("Error opening buy order : ",ErrorDescription(error));
            return false;
         } 
      }
   }
   
   return (true);
}

double NormalizePrice(double p)
{
    double ts = MarketInfo(Symbol(), MODE_TICKSIZE);
    return( MathRound(p/ts)*ts );
}
 
Can anyone help? I've been stuck on this issue for over week!!!
 

I think this:

longStopPrice = NormalizePrice(Ask+sv);

must be like this:

longStopPrice = NormalizePrice(Ask-sv);
 
traderman58:
Can anyone help? I've been stuck on this issue for over week!!!
When the OrderModify() fails what error do you get ?
 
JDeel:

I think this:

must be like this:


My initial stop is set to a negative value (ex. -1000 pips).
 
RaptorUK:
When the OrderModify() fails what error do you get ?


It is no longer giving me an error, but it is not modifying the TP. I will run it again and try to provide exact logs.
 
traderman58:

It is no longer giving me an error, but it is not modifying the TP. I will run it again and try to provide exact logs.
Please add Print() for the Open price, the TP, the SL and Bid and Ask all to a precision of Digits using DoubleToStr()