candle close count mql5

 

hello,

im trying to count how many candle closed below 30000 and how many candle close above 30000 on us30 for the 15candle, below the code i use.

the returns values are non sence

void OnTick(){
   int above, below;
   bool is_calc = above_below(
      above, below 
   );
bool above_below( int &count_above,
                  int &count_below,

                  double price = 29880,
                  const ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT)
{
   count_above = 0;
   count_below = 0;
   
   MqlRates rates[];

   double closes[];

   int total_closes = CopyClose(_Symbol, timeframe, 0, 15, closes);
   
   int total_rates = CopyRates(_Symbol, timeframe,0,15,rates);
   if(total_rates < 1)
      return false;

   
   for(int i=0; i<total_rates; i++){
      if(rates[i].close > price)
         count_above++;
         Print(count_above);
      if(rates[i].close < price)
         count_below++;
         Print(count_below);
   }
   return true;
}


thanks for help

 
Belgacem Issam:

hello,

im trying to count how many candle closed below 30000 and how many candle close above 30000 on us30 for the 15candle, below the code i use.

the returns values are non sence

thanks for help

If your program compiles without any error but doesn't do what is should use the debugger and control the relevant variables:

https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

Code debugging - Developing programs - MetaEditor Help
Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
Reason: