Modifying Order Error 1

 

Hello,


I have this High/Low trailing function on which I'm getting an Error 1 while running. I know this error is not very significant  but I can't understand why it's coming up.

the strangest part is that I wrote 

if(prevsl<newsl && newsl<=Bid-stoplevel && prevsl!=newsl)

which is now actually checking twice that prevsl is different than newsl (cause I'm going crazy), but the the algorithm still goes through, even though when I print the two values, they are the same!

void prevHLTrailing(int nb_of_bars,int Trailing_Pips,int MagN)
  {
   double pip,stoplevel,Trail;
   SetPipValue(pip);
   stoplevel=MarketInfo(NULL,MODE_STOPLEVEL)*Point();
   Trail=Trailing_Pips*pip;
   datetime CurrentBarTime;

   if(Time[0]>CurrentBarTime)
     {
      CurrentBarTime=Time[0];
      double low,high;
      low=Low[iLowest(NULL,0,MODE_LOW,nb_of_bars,0)];
      high=High[iHighest(NULL,0,MODE_HIGH,nb_of_bars,0)];

      for(int i=0; i<OrdersTotal(); i++)
        {
         int select=OrderSelect(i,SELECT_BY_POS);
         if(!select)
            Print("Something went wrong with isOrder OrderSelect. Error = ",GetLastError());

         if(OrderType()==OP_BUY && OrderMagicNumber()==MagN)
           {
            double newsl=NormalizePrice(AdjustStopToLevel(low-Trail,false));
            double prevsl=OrderStopLoss();
            if(prevsl<newsl && newsl<=Bid-stoplevel && prevsl!=newsl)
              {
               Print(prevsl+" "+" sl: "+newsl);
               int modifying=OrderModify(OrderTicket(),OrderOpenPrice(),newsl,OrderTakeProfit(),0);
               if(!modifying)
                  Print("Something went wrong with modifying for prevHLTrailing Order. Error = ",GetLastError());
              }
           }
         else if(OrderType()==OP_SELL && OrderMagicNumber()==MagN)
           {
            double newsl=NormalizePrice(AdjustStopToLevel(high+Trail,true));

            if((OrderStopLoss()>newsl || OrderStopLoss()==0) && newsl>=Ask+stoplevel && OrderStopLoss()!=newsl)
              {
               int modifying=OrderModify(OrderTicket(),OrderOpenPrice(),newsl,OrderTakeProfit(),0);
               if(!modifying)
                  Print("Something went wrong with modifying for prevHLTrailing Order. Error = ",GetLastError());
              }
           }

        }

     }
  }
 
Naim El Hajj:

Hello,


I have this High/Low trailing function on which I'm getting an Error 1 while running. I know this error is not very significant  but I can't understand why it's coming up.

the strangest part is that I wrote 

which is now actually checking twice that prevsl is different than newsl (cause I'm going crazy), but the the algorithm still goes through, even though when I print the two values, they are the same!

Because that's double, your way to compare prices is not correct. Check the forum they are plenty of topics on that.

newsl=1.2500000000000002

prevsl=1.25000

As double they are different, but as price ?

 
Alain Verleyen:

Because that's double, your way to compare prices is not correct. Check the forum they are plenty of topics on that.

newsl=1.2500000000000002

prevsl=1.25000

As double they are different, but as price ?

I'm already using WHRoeder's NormalizePrice() function to normalize the newsl, shouldn't that solve the "1.2500000000000002" issue?

 
Naim El Hajj:

I'm already using WHRoeder's NormalizePrice() function to normalize the newsl, shouldn't that solve the "1.2500000000000002" issue?

Seems not, what do you think ?