Big trend_001
Download scriptThis technical tool is designed to provide traders with a smoothed visual representation of market trends, specifically utilizing an advanced calculation known as the Hull Moving Average (HMA). Unlike standard moving averages which often suffer from significant "lag"—the delay between a price movement and the indicator's reaction—this script employs a multi-layered mathematical approach to prioritize speed and accuracy.
Core Logic Breakdown
The logic operates through three distinct phases:
1. Velocity Calculation Instead of looking at the price in isolation, the tool first calculates the "velocity" of the market. It does this by taking a weighted average of the shorter term movements and subtracting the longer term movements. This highlights the momentum of the current price action relative to its recent history.
2. Smoothing Process To ensure the resulting data isn't too erratic or "noisy" for human observation, the tool performs a second layer of processing. It takes that calculated velocity and applies a moving average to it (calculated based on the square root of your chosen period). This step is crucial because it creates a much smoother line that follows the price closely without the jagged jumps common in other indicators.
3. Trend Identification & Visualization Once the smooth data is generated, the script analyzes the direction of that line:
- Uptrend Detection: If the current value is higher than the previous one, the script identifies this as a positive movement and plots it as an "Uptrend."
- Downtrend Detection: If the current value is lower than the previous one, it identifies this as a negative movement and plots it as a "Dntrend."
Visual Behavior on Chart
The primary benefit for the user is the visual clarity provided by the dual-color output. By separating these movements into two distinct buffers (colored Light Blue and Tomato), the script allows you to see exactly where a trend shifts from positive to negative in real-time. When the market changes direction, the indicator "switches" colors, providing a clear visual signal of momentum shifts while filtering out minor price fluctuations that might otherwise trigger false signals.
//+------------------------------------------------------------------+
//| HMA.mq4
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104
//| wizardserg@mail.ru
//| Revised by IgorAD,igorad2003@yahoo.co.uk |
//|
//| Personalized by iGoR for the Trend Slope Trading method (T_S_T)
//| Link: http://www.strategybuilderfx.com/forums/showthread.php?t=16507
//| contact: igor@igor.cc
//+------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104"
#property link "wizardserg@mail.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Tomato
//---- input parameters
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend);
//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
IndicatorShortName("Hull Moving Average("+period+")");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
// ???? ????? ?????? ??????
return(0);
}
//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
double vect[], trend[];
if(e > Bars)
e = Bars;
ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);
for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
if (trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}
//Print( " trend=",trend[x]);
}
return(0);
}
//+------------------------------------------------------------------+
Comments