OrderModify does not seem to work during EA backtesting

 
Hi Experts,

I need your valuable help on the following peace of code, I am trying to modify an open order as part of my EA but during the back testing it does not seems to be working. I have tested with several pairs, time-frames and time range but it does not seems to modify any order. Here is the peace of code:

if(OrderSelect(openOrderID,SELECT_BY_TICKET)==true && OrdersTotal()!=0)

      {

      int orderType = OrderType();// Short = 1, Long = 0

      double optimalTakeProfit;

            if(orderType == 0)//long position

            {

                optimalTakeProfit = NormalizeDouble(bbUpperProfitExit,Digits); 

            }

            else //if short

            {

                optimalTakeProfit = NormalizeDouble(bbLowerProfitExit,Digits);

            }

            double TP = OrderTakeProfit();

            double TPdistance = MathAbs(TP - optimalTakeProfit);

            if(TP != optimalTakeProfit && TPdistance > 0.0001)

            {

               bool Ans = OrderModify(OrderTicket(), OrderOpenPrice(),OrderStopLoss(),optimalTakeProfit,0,clrAqua);

               Print ("Order Type is: ", OrderType(), "Order Ticket is: " + openOrderID);

               if (Ans==true)                     

{

                  Print("Order modified: ",openOrderID);

                  return;                           

                }

               else

                {

                  Print("Unable to modify order: ",openOrderID);

                }       

         }

      }

Could you please help me to spot the error in the logic of the code?

Many thanks in advance
Documentation on MQL5: Trade Functions / OrderGetTicket
Documentation on MQL5: Trade Functions / OrderGetTicket
  • www.mql5.com
Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal. An order is a request to conduct a transaction, while a position is a result of one or more deals. Function OrderGetTicket() copies data about an order into the program environment, and further calls of...
 
Please edit your post and
use the code button (Alt+S) when pasting code
 
Keith Watford:
Please edit your post and
use the code button (Alt+S) when pasting code
Thanks Keith, Doing it right now.
Reason: