MQL4 Errors for OnCalculate

 

I am hoping you can help fix my code. I am trying to code a MT4 indicator to indicate a powerful downward bar.

No matter what I do, I still get :1 errors, 1 warnings

OnCalculate function declared with wrong type or/and parameters line 42 column 6

OnCalculate function not found in custom indicator line 1 column 1

Any suggestions?

Thanks!!!

#property strict

// Define indicator buffers
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime

// Define indicator labels
#property indicator_label1 "Doji"
#property indicator_label2 "Exhaustion"
#property indicator_label3 "Engulfing"

// Declare indicator buffers
double DojiBuffer[];
double ExhaustionBuffer[];
double EngulfingBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Set buffer arrays
   SetIndexBuffer(0, DojiBuffer);
   SetIndexBuffer(1, ExhaustionBuffer);
   SetIndexBuffer(2, EngulfingBuffer);
   
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void OnCalculate(const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const int &spread[])
  {
   int i;
   for(i = prev_calculated; i < rates_total; i++)
     {
      // Calculate candle range
      double candle_range = high[i] - low[i];

      // Calculate upper shadow length
      double upper_shadow = high[i] - MathMax(open[i], close[i]);

      // Calculate lower shadow length
      double lower_shadow = MathMin(open[i], close[i]) - low[i];

      // Check for Doji candle condition
      if (candle_range > 0 && upper_shadow < 0.05 * candle_range && lower_shadow < 0.05 * candle_range) {
          DojiBuffer[i] = low[i];
      } else {
          DojiBuffer[i] = EMPTY_VALUE;
      }
      
      // Check for Exhaustion candle condition
      if (i > 0 && candle_range > 2 * MathAbs(close[i] - close[i - 1]) && upper_shadow < 0.15 * candle_range && lower_shadow < 0.15 * candle_range) {
          ExhaustionBuffer[i] = low[i];
      } else {
          ExhaustionBuffer[i] = EMPTY_VALUE;
      }
      
      // Check for Engulfing candle condition
      if (i > 0 && close[i] > open[i] && open[i - 1] > close[i - 1] && close[i] > open[i - 1] && open[i] < close[i - 1] && (close[i] - open[i]) > 0.9 * (high[i] - low[i]) && (open[i - 1] - close[i - 1]) > 0.9 * (high[i - 1] - low[i - 1])) {
          EngulfingBuffer[i] = low[i];
      } else {
          EngulfingBuffer[i] = EMPTY_VALUE;
      }
     }
  }
 
younss boudali: OnCalculate function declared with wrong type or/and parameters line 42 column 6
  1. You know what the error is.

  2. Perhaps you should read the manual. Program Running - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    What type does the documentation state the function must return?

 
I don't understand what you mean, but do you know where the error is in this code?
William Roeder #:
  1. You know what the error is.

  2. Perhaps you should read the manual. Program Running - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    What type does the documentation state the function must return?

 
younss boudali #: I don't understand what you mean, 

What part of “what type does the documentation state the function must return” is unclear to you? It is simple English. Did you click on the link and look at the return type?

 

Hi

Use this, you have had missing one parameter in On Calculate function (volume) and On Calculate must be declared only in one way. Now it will work:

#property strict

// Define indicator buffers
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime

// Define indicator labels
#property indicator_label1 "Doji"
#property indicator_label2 "Exhaustion"
#property indicator_label3 "Engulfing"

// Declare indicator buffers
double DojiBuffer[];
double ExhaustionBuffer[];
double EngulfingBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Set buffer arrays
   SetIndexBuffer(0, DojiBuffer);
   SetIndexBuffer(1, ExhaustionBuffer);
   SetIndexBuffer(2, EngulfingBuffer);
   
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {  
   int i;
   for(i = prev_calculated; i < rates_total; i++)
     {
      // Calculate candle range
      double candle_range = high[i] - low[i];

      // Calculate upper shadow length
      double upper_shadow = high[i] - MathMax(open[i], close[i]);

      // Calculate lower shadow length
      double lower_shadow = MathMin(open[i], close[i]) - low[i];

      // Check for Doji candle condition
      if (candle_range > 0 && upper_shadow < 0.05 * candle_range && lower_shadow < 0.05 * candle_range) {
          DojiBuffer[i] = low[i];
      } else {
          DojiBuffer[i] = EMPTY_VALUE;
      }
      
      // Check for Exhaustion candle condition
      if (i > 0 && candle_range > 2 * MathAbs(close[i] - close[i - 1]) && upper_shadow < 0.15 * candle_range && lower_shadow < 0.15 * candle_range) {
          ExhaustionBuffer[i] = low[i];
      } else {
          ExhaustionBuffer[i] = EMPTY_VALUE;
      }
      
      // Check for Engulfing candle condition
      if (i > 0 && close[i] > open[i] && open[i - 1] > close[i - 1] && close[i] > open[i - 1] && open[i] < close[i - 1] && (close[i] - open[i]) > 0.9 * (high[i] - low[i]) && (open[i - 1] - close[i - 1]) > 0.9 * (high[i - 1] - low[i - 1])) {
          EngulfingBuffer[i] = low[i];
      } else {
          EngulfingBuffer[i] = EMPTY_VALUE;
      }
     }
     return(rates_total);
  }

Best Regards