MQL4 Errors for OnCalculate function

MQL4 Errors for OnCalculate function

Manage alerts

Loading saved threads...

younss boudali · External communityPost link
External question — Stack Overflow Stack Exchange Author: younss boudali Original post: https://stackoverflow.com/questions/78466394 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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 column6 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; } } }
Quote
Report
Daniel Kniaz · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Daniel Kniaz Original post: https://stackoverflow.com/a/78467951 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. int OnCalculate( should help. It is okay if you do not need any result, but the function should meet the requirements in order to be recognized by compiler. so you can add return(rates_total); after loop is over.
Quote
Report

Post Reply

Checking account access…