Code:
//+------------------------------------------------------------------+
//| sumon.mq4 |
//| Copyright 2024, Asif Iqbal Sumon |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Asif Iqbal Sumon"
#property link "https://englishact.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime // Verified Support
#property indicator_color2 Orange // Weak Support
#property indicator_color3 Red // Verified Resistance
#property indicator_color4 DarkRed // Weak Resistance
//--- indicator buffers
double VerifiedSupportBuffer[];
double WeakSupportBuffer[];
double VerifiedResistanceBuffer[];
double WeakResistanceBuffer[];
//--- input parameters
input int lookBackPeriod = 50; // Look back period for support/resistance detection
input double verifiedLevelThreshold = 20; // Threshold for verified levels
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Buffers
SetIndexBuffer(0, VerifiedSupportBuffer);
SetIndexBuffer(1, WeakSupportBuffer);
SetIndexBuffer(2, VerifiedResistanceBuffer);
SetIndexBuffer(3, WeakResistanceBuffer);
// Set names for buffers
IndicatorShortName("Support and Resistance Levels");
SetIndexLabel(0, "Verified Support");
SetIndexLabel(1, "Weak Support");
SetIndexLabel(2, "Verified Resistance");
SetIndexLabel(3, "Weak Resistance");
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 double &spread[])
{
// Ensure that we have enough rates
if (rates_total < lookBackPeriod)
return 0;
// Clear buffer values
ArraySetAsSeries(VerifiedSupportBuffer, true);
ArraySetAsSeries(WeakSupportBuffer, true);
ArraySetAsSeries(VerifiedResistanceBuffer, true);
ArraySetAsSeries(WeakResistanceBuffer, true);
for (int idx = 0; idx < rates_total; idx++)
{
VerifiedSupportBuffer[idx] = EMPTY_VALUE;
WeakSupportBuffer[idx] = EMPTY_VALUE;
VerifiedResistanceBuffer[idx] = EMPTY_VALUE;
WeakResistanceBuffer[idx] = EMPTY_VALUE;
}
for (int i = lookBackPeriod; i < rates_total; i++)
{
double highPrice = high[i];
double lowPrice = low[i];
int countSupport = 0;
int countResistance = 0;
// Count support and resistance levels
for (int j = 1; j <= lookBackPeriod; j++)
{
if (low[i - j] <= lowPrice) countSupport++;
if (high[i - j] >= highPrice) countResistance++;
}
// Identify zones
if (countSupport >= verifiedLevelThreshold)
VerifiedSupportBuffer[i] = lowPrice;
else
WeakSupportBuffer[i] = lowPrice;
if (countResistance >= verifiedLevelThreshold)
VerifiedResistanceBuffer[i] = highPrice;
else
WeakResistanceBuffer[i] = highPrice;
}
return rates_total;
}
//+------------------------------------------------------------------+
Errors:
OnCalculate function declared with wrong type or/and parameters sumon.mq4 50 5
OnCalculate function not found in custom indicator 1 1
Replacing
const double &spread[])
to
const int &spread[])
is solving the problem