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;
}
}
}
New contributor
younss boudali is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.