This technical indicator is designed to help traders visualize market momentum and price trends by calculating a weighted movement of price data over a specific period. Instead of simply looking at the current price, the tool analyzes how much "weight" historical price action carries to determine the overall direction of the market.
Core Logic and Methodology
The script operates by examining a defined window of historical candles (determined by the user-defined period). It calculates a weighted sum based on the following mechanics:
- Data Selection: Depending on the configuration, the tool can focus on the High, Low, or Closing prices of the candles within its lookback period.
- Weighting System: Rather than treating every candle in the timeframe equally, the logic applies a mathematical weighting to each data point. This ensures that the influence of older prices is balanced against more recent price action, providing a smoothed representation of the trend.
- Momentum Calculation: By aggregating these weighted values, the script produces a continuous numerical value that represents the "strength" or "flow" of the current price movement.
Visual Behavior and Interpretation
The primary purpose of this script is to provide a clear, visual distinction between upward and downward trends on your trading chart:
- Trend Identification: The indicator compares the current calculated value against the previous one. If the current value is higher than the previous, it indicates upward momentum; if lower, it indicates downward momentum.
- Color-Coded Direction: To make this easy to read at a glance, the script uses a dual-color system (typically Red and Lime). It dynamically switches which color is visible based on the trend direction:
- When the market trends upward, the indicator highlights the growth.
- When the market turns downward, the indicator shifts to highlight the decline.
- Visual Continuity: The logic is designed to "connect the dots," showing a clean path of market movement that helps traders identify where a trend is accelerating or beginning to reverse.
In summary, this tool acts as a visual filter that strips away minor price fluctuations (noise) to reveal the underlying weighted momentum of the market, allowing you to see the prevailing trend more clearly.
//+------------------------------------------------------------------+
//| |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, FX Sniper "
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern int Rperiod = 14;
extern int Draw4HowLongg = 1500;
extern int Type = 3;
int Draw4HowLong,shift,i,loopbegin,width,length,c;
double sum[];
double lengthvar;
double tmp ;
double wt[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(4);
//---- drawing settings
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,sum);
SetIndexBuffer(3,wt);
SetIndexStyle(0,DRAW_LINE,0,2);
SetIndexStyle(1,DRAW_LINE,0,2);
//---- initialization done
return(0);
}
int start()
{ Draw4HowLong = Bars-Rperiod - 5;
length = Rperiod;
loopbegin = Draw4HowLong - length - 1;
for(shift = loopbegin; shift >= 0; shift--)
{
sum[1] = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
if(Type==1)
tmp = ( i - lengthvar)*High[length-i+shift];
if (Type==2)
tmp = ( i - lengthvar)*Low[length-i+shift];
if(Type==3)
tmp = ( i - lengthvar)*Close[length-i+shift];
sum[1]+=tmp;
}
wt[shift] = sum[1]*6/(length*(length+1));
//========== COLOR CODING ===========================================
ExtMapBuffer1[shift] = wt[shift];
ExtMapBuffer2[shift] = wt[shift];
if (wt[shift] > wt[shift+1])
{
ExtMapBuffer1[shift] = EMPTY_VALUE;
ExtMapBuffer2[shift+1] = wt[shift+1];
}
else if (wt[shift] < wt[shift+1])
{
ExtMapBuffer2[shift] = EMPTY_VALUE;
ExtMapBuffer1[shift+1] = wt[shift+1];
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments