SignalLine
Download scriptThis script is designed as a visual trading tool for the MetaTrader platform, specifically created to help traders identify and follow market trends. Instead of showing simple price movements, it uses a sophisticated mathematical approach to smooth out market "noise" and highlight the underlying direction of the price action.
Core Logic and Functionality
The indicator works by processing price data through three distinct logical layers:
1. Smoothing and Velocity Calculation The script begins by analyzing the price over a specific period (which you can customize). Rather than just looking at the current price, it calculates two different weighted averages. It then compares these averages to determine the "velocity" of the market. This helps the tool distinguish between minor fluctuations and actual momentum.
2. Trend Mapping Once the velocity is calculated, the script applies a second layer of smoothing. This creates a refined "signal line." By doing this, the tool filters out temporary spikes or "fake-outs," providing a much cleaner path that represents the core trend of the asset more accurately than raw price bars ever could.
3. Directional Detection (The Signal) The final logic determines whether the market is currently moving upward or downward based on the direction of this refined signal line:
- Uptrend: When the signal line moves higher than its previous position, the script identifies an uptrend and plots a Lime colored line on your chart.
- Downtrend: When the signal line moves lower than its previous position, it identifies a downtrend and plots a Red colored line.
How to Interpret the Results
The primary goal of this logic is to provide clear visual cues:
- Color Shifts: The tool is designed to switch colors as soon as the trend direction changes. This allows you to see at a glance whether the current market sentiment is bullish (Lime) or bearish (Red).
- Trend Clarity: Because it uses a multi-step smoothing process, the lines are less likely to "jitter" than standard moving averages. It aims to stay aligned with the major trend while reacting quickly enough to alert you when that trend shifts.
In summary, this script acts as a trend-tracking assistant that simplifies complex market data into two clear visual paths, helping traders stay on the right side of the market momentum.
//+------------------------------------------------------------------+
//| HMA.mq4
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104
//| wizardserg@mail.ru
//| Revised by IgorAD,igorad2003@yahoo.co.uk |
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T)
//| Link:
//| contact: thefuturemaster@hotmail.com
//+------------------------------------------------------------------+
#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 Lime
#property indicator_color2 Red
//---- input parameters
extern int period=15;
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("Signal Line("+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