LSwpr_in+Color
Download scriptThis tool is designed as a visual momentum indicator for trading platforms, providing traders with a streamlined way to interpret price trends and potential reversals. Instead of cluttering the main price chart, it operates in a separate window, focusing on the underlying mathematical weight of market movements.
Core Logic and Methodology
The script functions by analyzing historical price data through a customized smoothing process. Here is how the logic flows from raw data to visual output:
1. Weighted Momentum Analysis The primary engine of the script relies on identifying momentum. Rather than just looking at where the price is moving, it calculates a "weighted" value. It takes a specific timeframe (the period) and applies a mathematical weight to each previous data point. This ensures that more recent market activity has a significant influence on the final calculation, allowing the indicator to react dynamically to new information while maintaining a stable view of the broader trend.
2. Calculation Flow The script performs a multi-step loop for every price tick:
- It gathers a sequence of data points based on your chosen period.
- It assigns a variable weight to these points, ensuring the "sum" of the movement is proportional to its progression over time.
- It normalizes this sum into a single value, which represents the current strength or "weight" of the trend.
3. Visual Representation and Trend Tracking The final result is displayed as a multi-colored line. The script uses specific logic to determine how these lines appear on your screen:
- Trend Continuity: The tool compares the current calculated weight against the previous one.
- Dynamic Coloring: Based on whether the "weight" is increasing or decreasing, the script determines which color (Yellow, Chartreuse, or Red) should be visible.
- Visual Filtering: To keep the chart clean for the user, the script intelligently hides specific segments of the line when the trend direction changes. This prevents a messy overlap of colors, making it easier for the trader to see exactly when momentum is shifting from one direction to another.
Summary for the Trader
In essence, this script acts as a "momentum filter." It smooths out the market's noise and translates complex price movements into a clear, color-coded trend line. By observing the shifts in these colors, you can more easily identify whether the market is gaining strength, losing steam, or preparing for a potential change in direction.
//+------------------------------------------------------------------+
//| |
//| 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_separate_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Chartreuse
#property indicator_color3 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;
extern int Rperiod = 14;
extern int Draw4HowLongg = 300; // 500 // 1000
int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum[];
int length;
double lengthvar;
double tmp ;
double wt[];
int c;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(0,ExtMapBuffer3);
SetIndexBuffer(3,sum);
SetIndexBuffer(4,wt);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
//---- initialization done
return(0);
}
int start()
{ Draw4HowLong = 1000-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;
tmp = ( i - lengthvar)*iWPR(NULL,0,Rperiod,length-i+shift);
sum[1]+=tmp;
}
wt[shift] = sum[1]*6/(length*(length+1));
//========== COLOR CODING ===========================================
ExtMapBuffer3[shift] = wt[shift]; //red
ExtMapBuffer2[shift] = wt[shift]; //green
ExtMapBuffer1[shift] = wt[shift]; //yellow
// for(c=loopbegin;c==shift;c++)
// {
if (wt[shift+1] > wt[shift])
{
ExtMapBuffer2[shift+1] = EMPTY_VALUE;
// ObjectCreate("smiley_face", OBJ_ARROW, 0, Time[shift], Low[shift]-Point*20);
// Print("time= ",Time[shift]);
// ObjectSet("smiley_face", OBJPROP_ARROWCODE, 242);
// ObjectSet("smiley_face", OBJPROP_COLOR , Red);
// ObjectSet("smiley_face", OBJPROP_WIDTH , 1);
// ObjectsRedraw();
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else if (wt[shift+1] < wt[shift])
{
ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
MessageBox("asda");
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else
{
ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments