[MT4] Cannot find order when looking for OrderOpenPrice()?

 

Hi, having long time problem understanding why I cannot find order in loop when looking for OrderOpenPrice. I have temporarly solved the problem by adding open price to comment but this is not solid solution.

Please suggest how to solve this. (In below code OrderComment() is commented out)


void OnTick()
  {
   int      Action=2,MAGIC=1111,Check=0,Step=50;
   double   ActionPrice=2.0000,UpPrice=2.0100;
   string   TestString="";
   //Digits
   if(Digits==3 || Digits==5)
   {
   Step=Step*10;
   }
   //Check Order and OrderSend
   while(Action>0 && ActionPrice!=0)
   {
      Check=0;
      //Checking Is There Order At ActionPrice
      for(int i17=OrdersTotal()-1;i17>=0;i17--)
      {
         if(OrderSelect(i17,SELECT_BY_POS,MODE_TRADES))
         {
            if(OrderSymbol()==Symbol() 
            && OrderMagicNumber()==MAGIC
            && OrderOpenPrice()==ActionPrice)
            //&& OrderComment()==DoubleToStr(ActionPrice,Digits))
            {
               Check++;
            }
         }
      }
      //Found Order
      if(Check>0)
      {
         TestString="Order Found!";
         Print(TestString);
      }
      //Stop Check And Exit 
      if(ActionPrice>UpPrice)
      {
         ActionPrice=0;
         Action=0;
      }
      //There Is No Order At ActionPrice, Open Order And Add Step to ActioPrice
      if(Check==0)
      {
         int ticket=OrderSend(Symbol(),OP_BUYSTOP,1.00,ActionPrice,0,0,0,DoubleToStr(ActionPrice,Digits),MAGIC,0,clrNONE);
         if(ticket<0)
         {
            Print("OrderSend Error");
            Action--;
         }
         else
         {
            Print("OrderSend Success");
            ActionPrice=ActionPrice+Step*Point;
         }
      }
      //Order Exists At ActionPrice, Add Step to ActionPrice
      else
      {
         ActionPrice=ActionPrice+Step*Point;
      }
   }     
  }
 

I don't know whether this may be a comparing doubles thing or not

 Try replacing

&& OrderOpenPrice()==ActionPrice)

 

 with

&& MathAbs(OrderOpenPrice()-ActionPrice)<Point
 
GumRai:

I don't know whether this may be a comparing doubles thing or not

 Try replacing

 

 with

 

Thank you for help. Code works and I will use your suggestion.
 
Rahle:  Code works and I will use your suggestion.
&& OrderOpenPrice()==ActionPrice)
Now learn why The == operand. - MQL4 forum
 
WHRoeder:
Rahle:  Code works and I will use your suggestion.
Now learn why The == operand. - MQL4 forum

Thank you, very interesting link..I didn't got this at first time, but I will give it a second go. This might explain why I am constantly having Ghost in my code.
 

This would never be true :

&& OrderOpenPrice()==ActionPrice)


double   ActionPrice=2.0000