Download MetaTrader 5
To add comments, please log in or register
Looking for like-minded people? You will find lots of them on the Forum!
Erki
18
Erki 2014.09.14 19:45 

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;
      }
   }     
  }
Keith Watford
Moderator
7897
Keith Watford 2014.09.14 20:42  

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

 Try replacing

&& OrderOpenPrice()==ActionPrice)

 

 with

&& MathAbs(OrderOpenPrice()-ActionPrice)<Point
Erki
18
Erki 2014.09.15 09:58  
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.
whroeder1
13602
whroeder1 2014.09.15 16:09  
Rahle:  Code works and I will use your suggestion.
&& OrderOpenPrice()==ActionPrice)
Now learn why The == operand. - MQL4 forum
Erki
18
Erki 2014.09.18 09:20  
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.
ffoorr
983
ffoorr 2014.09.18 12:32  

This would never be true :

&& OrderOpenPrice()==ActionPrice)


double   ActionPrice=2.0000
/
To add comments, please log in or register