LSMA in Color_seperate
Download scriptThis indicator is designed to provide a visual representation of market momentum and price trends by analyzing historical price data. Instead of simply looking at the current price, it calculates a weighted movement over a specific period to help traders identify the direction and strength of the market.
How the Logic Works
1. Data Collection and Weighting The script looks back at a predefined number of previous candles (the "Rperiod"). Rather than treating every past price point as equally important, the logic applies a mathematical weighting system. It gives more significance to certain points in that period based on their position relative to the current price action. This helps smooth out "noise"—the minor, erratic fluctuations in price—to reveal the underlying trend.
2. Momentum Calculation The core of the script performs a continuous calculation where it sums these weighted prices and then scales them. This results in a momentum value that reflects whether the market is gaining strength, losing steam, or remaining stagnant. By processing this data in a loop, the indicator ensures that the trend line remains fluid and responsive to real-time changes.
3. Visual Trend Identification The script translates these complex calculations into three distinct visual layers (colored lines) on your chart:
- Directional Tracking: The logic compares the current momentum value against the previous one.
- Color Coding:
- If the momentum is increasing, the indicator highlights the upward movement (typically represented by Lime).
- If the momentum is decreasing, it highlights the downward movement (typically represented by Red).
- When the market is neutral or moving sideways with no significant change in momentum, the lines remain consistent to show a lack of clear direction.
Summary for the User Essentially, this tool acts as a "trend filter." It looks at a window of past prices, calculates how much weight that history carries toward the current price, and draws a color-coded line that tells you whether the market's strength is currently pushing upward or downward. It is designed to help you stay on the right side of the trend by visually separating meaningful price movements from insignificant market fluctuations.
//+------------------------------------------------------------------+
//| |
//| 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 Lime
#property indicator_color3 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;
extern int Rperiod = 34;
extern int Draw4HowLongg = 1000; //1500
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 = 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;
tmp = ( i - lengthvar)*Close[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]; //lime
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
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else
{
ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments