LSMA_v1
Download scriptThis script is a custom technical analysis tool designed to help traders visualize market trends through a smoothed moving average. Instead of showing a single static line, it uses a multi-colored display system to highlight the direction and momentum of price movements in real-time.
Core Logic and Functionality
The primary goal of this tool is to filter out "market noise"—the small, erratic price fluctuations that can make it difficult to see the bigger picture—and present a clearer view of where the price is heading. It achieves this through three main stages:
1. Weighted Price Calculation The script analyzes a specific window of past price data (defined by the user). Unlike a simple average where every price point is treated equally, this logic applies a "weight" to different prices. It gives more significance to certain parts of the recent history, creating a smoothed trend line that reacts to the market's movement without being overly jittery.
2. Trend Detection Once the script calculates the smoothed value for the current moment, it compares it against the previous calculation. By looking at whether the current value is higher or lower than the one immediately preceding it, the tool determines the "velocity" and direction of the market trend.
3. Dynamic Color Coding The most distinct feature of this script is its visual output. It uses three different colors (Yellow, Green, and Red) to represent the state of the trend:
- When the price momentum shifts in one direction, the script "activates" a specific color to show the current flow.
- When the trend reverses or stays flat, the script hides the previous color and highlights the new one.
Summary for the User
Essentially, this tool acts as a visual guide for market direction. By looking at the colors on your chart, you can quickly identify whether the momentum is currently moving upward, downward, or remaining neutral. It simplifies complex price history into a clear, color-coded stream, allowing you to see trends more intuitively at a glance.
//LSMA in Color mq4
//+------------------------------------------------------------------+
//| |
//| 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 Green
#property indicator_color3 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;
extern int Rperiod = 34;
extern int Draw4HowLongg = 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,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,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;
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]; //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
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
}
else
{
ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments