OsHMA
Download scriptThis technical tool is designed to help traders analyze price momentum by visualizing the relationship between two different smoothed trend lines. Instead of looking at raw price action, which can be erratic and "noisy," this script processes data into a readable histogram that highlights the speed and direction of market movement.
Core Logic and Mechanics
The logic operates through a multi-layered smoothing process to ensure that the resulting data is responsive to new price changes while remaining smooth enough to filter out insignificant market jitters. Here is how it works step-by-step:
1. The Dual Foundation (Fast and Slow Trends) The tool tracks two different moving averages simultaneously: a "Fast" version and a "Slow" version. These represent the shorter-term and longer-term trends of the asset, respectively. By comparing these two, the script can identify when the short-term momentum is accelerating ahead of or falling behind the long-term average.
2. Advanced Smoothing (Hull Moving Average Logic) Unlike standard moving averages that can lag significantly behind current prices, this script utilizes a specialized calculation method. It calculates internal weighted averages to "pre-process" the data before the final output is generated. This mathematical approach aims to reduce the delay typically found in traditional indicators, allowing for a more timely reflection of price shifts.
3. Momentum Calculation (The Oscillator) Once the two smoothed trends are established, the script subtracts the "Slow" value from the "Fast" value. The resulting difference is plotted as a histogram in a separate window on your chart.
How to Interpret the Results
- Trend Direction: When the histogram values are positive and rising, it suggests that the short-term momentum is stronger than the long-term trend (often interpreted as bullish pressure). Conversely, negative and falling values suggest the short-term momentum is weakening relative to the long-term trend (often interpreted as bearish pressure).
- Momentum Strength: The height of the histogram bars indicates the intensity of this momentum. Larger spikes suggest a rapid move in price, while shrinking bars may indicate that the current trend is losing steam or consolidating.
- Visual Clarity: By placing this data in a separate window as a histogram, it allows you to see the "pulse" of the market independently from the price candles, making it easier to spot turning points and shifts in sentiment at a glance.
//+------------------------------------------------------------------+
//| OsHMA.mq4 |
//| Copyright © 2009, Meta Quotes & sealdo |
//| sealdo@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Meta Quotes & sealdo"
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
//#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DarkOrchid
#property indicator_width1 2
//---- indicator parameters
extern int FastHMA = 12;
extern int SlowHMA = 26;
//---- indicator buffers
double OsmaBuffer[];
double PreHMA1[];
double PreHMA2[];
//+------------------------------------------------------------------+
int pF, pS;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 4 additional buffers are used for counting.
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
//SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(Digits+2);
//---- 5 indicator buffers mapping
SetIndexBuffer(0,OsmaBuffer);
SetIndexBuffer(1,PreHMA1);
SetIndexBuffer(2,PreHMA2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("OsHMA("+FastHMA+","+SlowHMA+")");
pF = MathSqrt(FastHMA);
pS = MathSqrt(SlowHMA);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
double WMA(int x, int p) {
return(iMA(NULL, 0, p, 0, MODE_LWMA, PRICE_CLOSE, x));
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- preparing the HMA
for(int i=0; i<limit; i++) {
PreHMA1[i] = 2*WMA(i, FastHMA/2) - WMA(i, FastHMA);
PreHMA2[i] = 2*WMA(i, SlowHMA/2) - WMA(i, SlowHMA);
}
//---- macd counted in the 1-st additional buffer
for(i=0; i<limit; i++)
OsmaBuffer[i]= iMAOnArray(PreHMA1, 0, pF, 0, MODE_LWMA, i) - iMAOnArray(PreHMA2, 0, pS, 0, MODE_LWMA, i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments