Elliott_Wave_Oscillator
Download scriptThis tool is designed to provide a visual representation of market momentum by analyzing the relationship between two different moving averages. Instead of looking at price directly on a standard chart, this script creates an "oscillator"—a separate visual window that helps traders identify whether the current price movement is gaining strength or losing steam based on specific mathematical trends.
How the Logic Works
The underlying logic relies on comparing a short-term average with a long-term average to determine the "speed" and "direction" of the market:
- Short-Term Trend (5-Period Average): The script calculates a simple moving average over a very short period. This represents the immediate, fast-moving sentiment of the market.
- Long-Term Trend (34-Period Average): The script simultaneously calculates a much broader moving average. This represents the established, slower-moving trend of the market.
Generating the Visual Signal
The indicator calculates the difference between these two averages. By subtracting the long-term average from the short-term average, the script produces a numerical value that dictates what you see on your screen:
- Positive Momentum (Upward Bars): When the short-term average is higher than the long-term average, the result is a positive number. The indicator displays this as a green histogram bar pointing upward. This suggests that the immediate price action is currently trending above its historical baseline.
- Negative Momentum (Downward Bars): When the short-term average falls below the long-term average, the result is a negative number. The indicator displays this as a red histogram bar pointing downward, signaling that the immediate price action is lagging behind or falling below the broader trend.
- Neutral Zone: If the two averages are perfectly aligned (the difference is zero), no bars are displayed, indicating a moment of equilibrium where neither trend is dominant over the other.
Practical Purpose
By distilling complex price movements into a simple up-and-down histogram, this tool allows you to see "momentum" at a glance. It filters out minor market noise and highlights whether the current price movement has enough strength to sustain its direction, making it easier to identify potential shifts in market cycles.
//+------------------------------------------------------------------+
//| Elliott Wave Oscillator.mq4 |
//| tonyc2a@yahoo.com |
//| |
//+------------------------------------------------------------------+
#property copyright "tonyc2a@yahoo.com"
#property link ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 FireBrick
//---- buffers
double Buffer;
double HistogramBufferUp[];
double HistogramBufferDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(0, HistogramBufferUp);
SetIndexBuffer(1, HistogramBufferDown);
IndicatorDigits(Digits + 2);
IndicatorShortName("Elliott Wave Oscillator");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double MA5,MA34;
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
//---- TODO: add your code here
for(int i=0; i<limit; i++)
{
MA5=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i);
MA34=iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);
Buffer=MA5-MA34;
if(Buffer > 0)
{
HistogramBufferUp[i] = Buffer;
HistogramBufferDown[i] = 0;
}
else
if(Buffer < 0)
{
HistogramBufferDown[i] = Buffer;
HistogramBufferUp[i] = 0;
}
else
{
HistogramBufferUp[i] = 0;
HistogramBufferDown[i] = 0;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments