HMA_Angle1
Download scriptThis tool is designed to help traders visualize the strength and direction of market momentum by measuring the specific "tilt" or angle of a Hull Moving Average (HMA). Instead of just looking at the price line, this indicator translates the movement into a separate visual window that highlights whether the trend is sufficiently steep to be considered significant.
Core Logic and Functionality
The script operates by comparing two different points in time on a Hull Moving Average. It calculates the difference between the current position of the average and its position several bars back. By measuring this gap, the tool determines the "angle" at which the moving average is currently climbing or falling.
Key Components of the Analysis
- Trend Measurement: The indicator looks at two specific points—a "Start" point and an "End" point. The distance between these two points allows the script to calculate a mathematical slope.
- The Angle Threshold: To filter out minor market noise and "flat" movements, the script uses a user-defined threshold. If the calculated angle is too small (meaning the price is moving sideways or very slowly), it stays neutral.
- Dynamic Scaling: The logic includes a built-in adjustment factor that automatically recognizes different types of currency pairs (such as JPY pairs vs. standard pairs). This ensures that the visual representation remains consistent and accurate regardless of the asset being traded.
Visual Representation
The results are displayed in a separate sub-window on your chart using three distinct colors to categorize the market state:
- Upward Movement: When the average climbs at an angle steeper than your chosen threshold, it creates a visual signal (Olive) indicating a strong bullish trend.
- Downward Movement: When the average drops at an angle steeper than your chosen threshold, it creates a visual signal (FireBrick) indicating a strong bearish trend.
- Neutral Zone: If the movement is too shallow to meet your requirements, the indicator shows the value in a third color (Orange), representing a period of consolidation or lack of clear momentum.
In essence, this tool simplifies your trading by filtering out "lazy" price movements and only highlighting trends that have enough directional velocity to be of interest.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| HMA_Angle.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Olive
#property indicator_color2 FireBrick
#property indicator_color3 Orange
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
//---- indicator parameters
extern int HMA_Period=7;
extern double AngleTreshold=15;
extern int StartHMAShift=2;
extern int EndHMAShift=0;
//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];
//---- additional buffers
int draw_begin0;
double mFactor;
int ShiftDif;
string Sym;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,UpBuffer) &&
!SetIndexBuffer(1,DownBuffer) &&
!SetIndexBuffer(2,ZeroBuffer))
Print("cannot set indicator buffers!");
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
draw_begin0=HMA_Period+MathFloor(MathSqrt(HMA_Period));
SetIndexDrawBegin(0,draw_begin0);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("HMA_Angle("+HMA_Period+","+AngleTreshold+","+StartHMAShift+","+EndHMAShift+")");
SetIndexLabel(0,"HMA Angle");
if(EndHMAShift >= StartHMAShift)
{
Print("Error: EndHMAShift >= StartHMAShift");
StartHMAShift = 6;
EndHMAShift = 0;
}
mFactor = 100000.0;
Sym = StringSubstr(Symbol(),3,3);
if (Sym == "JPY") mFactor = 1000.0;
ShiftDif = StartHMAShift-EndHMAShift;
mFactor /= ShiftDif;
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
double ma1, ma2;
double fEndMA, fStartMA;
double fAngle;
int limit,i;
double angle;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0)
return(-1);
if(counted_bars<1)
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- main loop
for(i=0; i<limit; i++)
{
fEndMA=iCustom(NULL, 0, "HMA",HMA_Period,0,i+EndHMAShift);
fStartMA=iCustom(NULL, 0, "HMA",HMA_Period,0,i+StartHMAShift);
// 10000.0 : Multiply by 10000 so that the fAngle is not too small
// for the indicator Window.
fAngle = mFactor * (fEndMA - fStartMA)/2.0;
//Print (mFactor, fEndMA, fStartMA, fAngle);
DownBuffer[i] = 0.0;
UpBuffer[i] = 0.0;
ZeroBuffer[i] = 0.0;
if(fAngle > AngleTreshold)
{
UpBuffer[i] = fAngle;
}
else if (fAngle < -AngleTreshold)
{
DownBuffer[i] = fAngle;
}
else ZeroBuffer[i] = fAngle;
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments