LSMA_ind_03x
Download scriptThis script is designed as a specialized technical analysis tool for the MetaTrader platform. It functions by calculating and visualizing price trends to help traders identify potential entry points for buy and sell orders.
Here is a breakdown of how the logic works:
Core Trend Calculation
The heart of this script is a modified moving average logic (referred to as LSMA). Instead of looking at simple averages, it performs a weighted calculation over a specific period of time (defined by the user). This means that more recent price data is given more significance than older data, allowing the indicator to react more fluidly to current market movements.
Visual Feedback
The script produces several visual elements on your trading chart:
- Trend Lines: It tracks the movement of the weighted average. Depending on whether the current value is higher or lower than the previous value, the script manages different colored indicators (Yellow, Green, and Red) to highlight the direction of price flow.
- Signal Markers: The script identifies specific "momentum" points. When the trend moves consistently in one direction for a set number of steps, it places a distinct marker (a large dot/point) on the chart.
Entry Signal Logic
The tool uses a counting mechanism to filter out "noise" and identify stronger trends:
- Buy Signals: If the price trend moves upward consistently for 5 consecutive steps, the script generates a specific signal marker at the high of that price candle.
- Sell Signals: Conversely, if the price trend moves downward consistently for 5 consecutive steps, it places a signal marker at the low of that candle.
Reset Mechanism
To ensure the signals remain fresh and don't become "stuck" on old data, the script includes a reset logic. Once it detects both an upward and a downward movement cycle (indicating a shift in trend), it clears its internal counters. This allows it to start identifying the next significant trend from a clean slate.
Purpose for the Trader
Essentially, this tool acts as a trend-following filter. It ignores minor price fluctuations and only "alerts" the user with markers when a sustained momentum of 5 steps is detected in either direction. By using the visual lines and the specific markers, it helps traders see where a trend has established enough strength to potentially warrant an action.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| LSMA indicator with global variables to drive a companion expert |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, FX Sniper "
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 White
//---- buffers
double ExtMapBuffer1[]; //Yellow
double ExtMapBuffer2[]; //Green
double ExtMapBuffer3[]; //Red
double XBuffer[]; //White
extern int extRperiod = 48;
extern int extDraw4HowLong = 500;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,ExtMapBuffer1); //Yellow
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1,ExtMapBuffer2); //Green
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2,ExtMapBuffer3); //Red
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
// 233 up arrow
// 234 down arrow
// 159 big dot
// 168 open square
// 120 box with X
SetIndexStyle(3,DRAW_ARROW);
SetIndexBuffer(3, XBuffer); //White
SetIndexArrow(3,159);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int i;
for( i=0; i<Bars; i++ ) ExtMapBuffer1[i]=0;
for( i=0; i<Bars; i++ ) ExtMapBuffer2[i]=0;
for( i=0; i<Bars; i++ ) ExtMapBuffer3[i]=0;
for( i=0; i<Bars; i++ ) XBuffer[i]=0;
return(0);
}
int start()
{
//----- variables
int c;
int i;
int length;
double lengthvar;
int loopbegin;
int pos;
double sum;
double tmp;
int width;
double wtp; //previous value
double wt; //current value
int rc=0;
int gc=0;
double p=Point;
length = extRperiod;
loopbegin = extDraw4HowLong - length - 1;
for(pos = loopbegin; pos >= 0; pos--)
{
sum = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
tmp = ( i - lengthvar)*Close[length-i+pos];
sum+=tmp;
}
wtp=wt;
wt = sum*6/(length*(length+1));
ExtMapBuffer1[pos] = wt; //yellow
ExtMapBuffer2[pos] = wt; //green
ExtMapBuffer3[pos] = wt; //red
if (wtp > wt)
{
ExtMapBuffer2[pos+1] = EMPTY_VALUE; //remove GREEN
rc++;
}
else
{
ExtMapBuffer3[pos+1] = EMPTY_VALUE; //remove RED
gc++;
}
//Comment("wtp=",wtp,"\nwt=",wt,"\nRed=",rc,"\nGreen=",gc);
if (gc>0 && rc>0)
{
// Close any orders
gc=0;
rc=0;
}
if (gc==5)
{
// indicate buy order
XBuffer[pos]=High[pos];
}
if (rc==5)
{
// indicate sell order
XBuffer[pos]=Low[pos];
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments