Download MetaTrader 5

Odd behaviour of WHILE operator - page 4

To add comments, please log in or register
Ian Venner
2584
Ian Venner  
lord_hiro:


That's it!

Shame on me... :-)

Moreover it's not the first time I use WHILE but I started thinking in reverse and never came out of MY OWN loop :-/

And so the deVries' suggestion of replacing || with && turns right.

A lot of other things to take care of came out from this topic, i.e. whit the IF( == ) works.

Thank you all for your patience and the time you spent to make me understand.

We all have done similar things lol...

Yes you could do as deVries said or you could just add a break to get out of the while loop after it draws the object.

Having said that if you use break you could make a little bit more efficient code because there would be no need for the first while condition.

Also as GumRai said, calling EMPTY_VALUE is a better comparison value than calling iHigh().

extern int SwingBarCount=100;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int SwingHighShift=0;
   string StringHighStatus="False";
   int SwingHigh=0;
   while(SwingHighShift<=SwingBarCount)
     {
      if(iFractals(NULL,0,MODE_UPPER,SwingHighShift)!=EMPTY_VALUE && iFractals(NULL,0,MODE_UPPER,SwingHighShift)>Close[0])
        {
         StringHighStatus="True";
         SwingHigh=SwingHighShift;
         ObjectDelete("SwingHigh");
         ObjectCreate("SwingHigh",OBJ_VLINE,0,Time[SwingHigh],0);
         ObjectSet("SwingHigh",OBJPROP_COLOR,Red);
         break;
        }
      else SwingHighShift++;
     }
   return(0);
  }
To add comments, please log in or register