not all control paths return a value.

 

ok I have tried to find an answer but I'm not seeing it. I have searched the forums but none of the solutions seem to apply to me. I'm probably wrong though. the error is on the final "}". Thanks for your patience.


//Function to Check the last 100 candles(trendLegth) to look for a trend
bool bullTrend()
{
   for(i = 1; i < trendLength; i++){
      candleValue = Close[i];
      double movingAverageValue = iMA(Symbol(), PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i);
      if(movingAverageValue < candleValue){
         up++;
         }else up = 0;
              if(up > 40)
              return true;
              else return false;
      }
   }
}
 
SirFency:

ok I have tried to find an answer but I'm not seeing it. I have searched the forums but none of the solutions seem to apply to me. I'm probably wrong though. the error is on the final "}". Thanks for your patience.


try this one 

//Function to Check the last 100 candles(trendLegth) to look for a trend
bool bullTrend()
  {
   bool retval=false;
   for(i = 1; i < trendLength; i++)
     {
      candleValue = Close[i];
      double movingAverageValue = iMA(Symbol(), PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i);
      if(movingAverageValue < candleValue)
         up++;
      else
         up = 0;
      if(up > 40)
         retval=true;
     }
   return(retval);
  }
 
Kenneth Parling:

try this one 

Thanks for that Kenneth. I removed the brackets for the for loop and the error went away. I dont understand this. I thought the for loop needed brackets.

 
SirFency:

Thanks for that Kenneth. I removed the brackets for the for loop and the error went away. I dont understand this. I thought the for loop needed brackets.

You're welcome! Main problem was not all control paths return a value in your code, i did a slightly different version beside yours and i removed unnecessary brackets.

 
SirFency:

Thanks for that Kenneth. I removed the brackets for the for loop and the error went away. I dont understand this. I thought the for loop needed brackets.

You do need brackets in for, while and if statements....unless the next statement is completed in a single line.

So, this

for(i=0;i<array_size;i++) 
  if(array[i]==0) 
    break;

is the same as

for(i=0;i<array_size;i++){ 
  if(array[i]==0){
    break;
}
}

but, VERY different from

for(i=0;i<array_size;i++) 
  Sleep(100);
  if(array[i]==0) 
    break;
 
andrew:

You do need brackets in for, while and if statements....unless the next statement is completed in a single line.

So, this

is the same as

but, VERY different from

break must be used with a loop or switch statement in first example as follow and the other two written as followed;

//+------------------------------------------------------------------+
void test()//1st
  {
   for(i=0; i<array_size; i++)
     {
      Sleep(100);
      if(array[i]==0)
         break;
     }

  }
//+------------------------------------------------------------------+
void test2()//2nd
  {
   for(i=0; i<array_size; i++)
      if(array[i]==0)
        {
         break;
        }
  }
//+------------------------------------------------------------------+
void test3()//3rd
  {
   for(i=0; i<array_size; i++)
      if(array[i]==0)
         break;
  }
//+------------------------------------------------------------------+
Reason: