svs_trend
Download scriptThis tool is designed to analyze and visualize market trends by calculating the relationship between different moving averages. Instead of just showing you a simple average price, it breaks down the momentum of the market into four distinct visual components, helping traders identify the underlying strength and direction of price movements.
How the Logic Works
The script operates by comparing two different time horizons (defined by your input periods). It takes the "Weighted Average Price" and looks at how these averages behave over short and medium spans. Here is the breakdown of what it calculates:
- Core Comparison: The tool identifies a primary price average based on a shorter timeframe and compares it against a secondary average based on a longer timeframe. By measuring the distance between these two, the script can determine if the current trend is accelerating, slowing down, or reversing.
- Cumulative Analysis: To ensure accuracy, the logic doesn't just look at two isolated points; it performs a cumulative summation of prices across the chosen periods. This provides a more rounded view of the market's "weight" rather than just a snapshot of the most recent price.
The Four Visual Components
The script outputs four different data points, which are displayed as histograms in a separate window. Each represents a specific nuance of the trend:
- Primary Trend Difference: This shows the direct mathematical difference between the two main averages. It serves as a baseline for the current price momentum.
- Trend Equilibrium (Average Weight): This value represents the middle ground between the relative differences of the short and long-term trends. It helps in identifying the "balance" point of the market.
- Proportional Variance: This calculates a specific ratio based on how much the primary trend fluctuates compared to its weighted average. It highlights the "intensity" of the move.
- Momentum Offset: The final component measures the variance between the price difference and the proportional variance. This is essentially designed to highlight "lags" or "leads" in the market—showing whether the price is pushing ahead of its own averages or falling behind.
Summary for the User
Essentially, this script takes raw price data and filters out the noise by calculating the mathematical "gap" between different timeframes. By observing these four histograms, you can get a clearer picture of whether a trend is healthy, weakening, or about to shift, providing more context than a standard moving average line alone.
//+------------------------------------------------------------------+
//| svs_trend.mq4 |
//| Copyright © 2007, SVS. |
//| |
//+------------------------------------------------------------------+
#property copyright "Tver,Spirovo,SVS,S Vadim S,svstnd@mail.ru,2008."
#property link ""
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 MediumSeaGreen
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Black
extern int Period1=4;
extern int Period2=8;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(3,ExtMapBuffer4);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double v0,v1;
double f0,f1;
double vv,ff;
double vj,vk,vd;
double vts;
int MODE,p1,p2;
//---- TODO: add your code here
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;
for(int i=0;i<=limit;i++){
//------------------------------------------------------
MODE=0;
vts=0;
p1=Period1;
if(Period2<=p1)Period2=p1+1;
p2=Period2;
//------------------------------------
f0=iMA(NULL,0,p1,0,MODE,PRICE_WEIGHTED,i);
f1=iMA(NULL,0,p2,0,MODE,PRICE_WEIGHTED,i);
//-----------------------------------------
for (int c=0;c<=p2;c++){
vts=vts+iMA(NULL,0,c,0,MODE,PRICE_WEIGHTED,i);
if(c==p1)v0=(vts/p1);
if(c==p2)v1=(vts/p2);
}
//-------------------------------------------
vv=v0-v1;
ff=f0-f1;
vk=(vv+ff)/2;
vd=(vv/2);
vj=(ff-vd);
//-------------------------
ExtMapBuffer1[i]=ff;
ExtMapBuffer2[i]=vk;
ExtMapBuffer3[i]=vd;
ExtMapBuffer4[i]=vj;
}
return(0);
}
//+--------------------------------+
Comments