Learning to code, need help with a while operator.

 

hi I am learning to code. The code below is supposed to look and see if the last closed candle was above a RSI high and if not it will look at the next candle back and see if that was and if not the next and so on and so on.  it mark the candles that are above the high and all the ones that don't.  After it locates a RSI high the function should return. 

It just marks every candle with both arrows and keeps on running forwards to mark the next. Any help would be appreciated.  

int Direction()
  {
   int Shift_Count=1;
   double Direction_Long_High= 0.0;
   double Direction_Long_Low = 0.0;
   double Direction_Last_Long_High= 0.0;
   double Direction_Last_Long_Low = 0.0;

   while(Direction_Long_High==0.0)
     {
      double RSI=iRSI(NULL,0,User_RSIPeriod,0,Shift_Count);
      if(RSI==0.0)
        {
         PrintFormat("iRSI ( Direction ) call error. Error code=%d",GetLastError());  // No RSI error report
        }
      if(RSI>70)
        {
         Direction_Long_High=RSI;
         Print (" RSI > 70 Direction long high is"+ DoubleToString (Direction_Long_High,2));
         MarkCandle_1();
         return(0);
        }
      else if(RSI<70)
         MarkCandle_2();
                  Print (" RSI <70 Direction long high is"+ DoubleToString (Direction_Long_High,2));

      Shift_Count++;

     }
   return (0);
  }
 

Remarks  about your codes :

1)Brackets are missing after "else if(RSI<70)"

2)Why two "return(0)"

3)Shift_Count must also be tested with chart bars limit

4)sub-pg  MarkCandle_1,..?

 

Fixed the missing brackets..

and the Shift_Count.

The two "return(0)" is to exit the function  if the argument is true 

The MarkCandle1_() is a bulk function I use for testing i.e MarkCandle_1, MarkCandle_2 etc

 
paul selvan:

Remarks  about your codes :

1)Brackets are missing after "else if(RSI<70)"

2)Why two "return(0)"

3)Shift_Count must also be tested with chart bars limit

4)sub-pg  MarkCandle_1,..?

 I have now realised that the thing is written completely wrong and will wipe it and start again. 

Thank you for your help

Reason: