LSMA_ind_03x_v1
Download scriptThis tool is a specialized technical analysis indicator designed to track price trends and identify specific entry points for trading. It functions by calculating a smoothed trend line based on historical price data and uses that data to generate visual signals on your chart.
Core Logic and Visual Behavior
The script operates by analyzing a set period of recent market closes. Rather than simply plotting the current price, it calculates a weighted average to create a smooth "map" of where the price is heading. This helps filter out minor market noise so you can see the broader direction more clearly.
On your chart, this logic produces several visual components:
- Trend Tracking: It uses multi-colored lines (Yellow, Green, and Red) to represent the current state of the moving average.
- Dynamic Color Switching: The script actively compares the current calculated value against the previous one. If the trend is moving upward, it manages the green and red indicators; if it moves downward, it adjusts accordingly.
- Signal Filtering: The tool keeps a running count of how many times the price has moved in a specific direction consecutively. This acts as a "momentum filter," ensuring that signals aren't triggered by small, insignificant fluctuations.
Automated Signals
The primary goal of this script is to highlight high-probability areas for action. It looks for specific patterns in the trend's momentum:
- Buy Signals: When the script detects a sustained upward momentum reaching a specific threshold (5 consecutive movements), it places a visual dot above the price candles.
- Sell Signals: Conversely, when it detects a sustained downward momentum reaching that same threshold, it places a visual dot below the price candles.
Integration Capability
Beyond just being a visual aid on your screen, this script is designed with "Global Variables." This means it acts as a bridge; it can share its internal calculations and data with other automated trading programs (Expert Advisors). By using these shared variables, an automated robot can "read" the signals generated by this indicator to execute trades automatically.
//+------------------------------------------------------------------+
//| 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