You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
McClellan Oscillator: This indicator uses the difference between two exponential moving averages to assess the breadth of market participation. It has values that typically range between -100 and +100.
#property indicator_separate_window
// Input parameters
input int fastEMAPeriod = 19; // Period for the fast EMA
input int slowEMAPeriod = 39; // Period for the slow EMA
// Indicator buffers
double McClellanBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Indicator label
IndicatorShortName("McClellan Oscillator");
// Set up indicator buffers
SetIndexBuffer(0, McClellanBuffer);
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 beginIndex = MathMax(fastEMAPeriod, slowEMAPeriod) - 1;
// Calculate the fast and slow EMAs
ArraySetAsSeries(McClellanBuffer, false);
double fastEMA = iMA(NULL, 0, fastEMAPeriod, 0, MODE_EMA, PRICE_CLOSE, beginIndex);
double slowEMA = iMA(NULL, 0, slowEMAPeriod, 0, MODE_EMA, PRICE_CLOSE, beginIndex);
// Calculate the McClellan Oscillator value
double mcclellanOscillator = fastEMA - slowEMA;
// Fill indicator buffer
if (rates_total > beginIndex)
{
for (int i = 0; i < rates_total - beginIndex; i++)
McClellanBuffer[i] = mcclellanOscillator;
}
return(rates_total);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Beta Was this translation helpful? Give feedback.
All reactions