LSMA in ColorOpen3_v1
Download scriptThis technical tool is designed to analyze market trends by identifying specific momentum shifts in price action. It functions as a visual guide, placing directional signals (arrows) on your trading chart to highlight potential turning points based on the behavior of three different trend lines.
How the Logic Works
The core logic of this script relies on the relationship between three moving averages of different lengths (set at 15, 30, and 60 periods). Instead of looking at simple price movements, the tool calculates a "Linear Weighted" average for each of these three timeframes. This helps smooth out market noise and provides a clearer picture of the underlying trend.
The tool operates by comparing the current value of these three averages against their previous values. It assigns a "score" based on whether each average is moving up or down:
- Trend Strength Tracking: The script checks all three averages simultaneously. If an average is higher than it was in the previous period, it contributes a positive point to the momentum score. If it is lower, it contributes a negative point.
- Signal Generation: A signal is only triggered when there is total agreement across all three timeframes:
- Bearish Signal (Red Arrow): When all three averages are moving downward simultaneously, the script identifies a strong bearish trend and places a red arrow at the top of the price candle.
- Bullish Signal (White Arrow): When all three averages are moving upward simultaneously, the script identifies a strong bullish trend and places a white arrow at the bottom of the price candle.
Summary for Traders
Essentially, this script acts as a "confluence filter." It ignores minor fluctuations where only one or two indicators might be moving in a certain direction. By requiring all three weighted averages to align perfectly before displaying a signal, it aims to highlight moments where the market trend has gained significant momentum across short, medium, and long-term horizons.
//+------------------------------------------------------------------+
//| |
//| 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_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red
double Buffer1[]; //White
double Buffer2[]; //Red
// User input
extern int Rperiod1 = 15;
extern int Rperiod2 = 30;
extern int Rperiod3 = 60;
extern int Draw4HowLong = 400;
//Static
double lsma0a;
double lsma1a;
double lsma0b;
double lsma1b;
double lsma0c;
double lsma1c;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(6);
// 233 up arrow
// 234 down arrow
// 159 big dot
SetIndexBuffer(0,Buffer1);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233); //up
SetIndexBuffer(1,Buffer2);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234); //down
}
int start()
{
int shift;
int i;
int dir3;
for(shift = Draw4HowLong; shift >= 0; shift--)
{
dir3=0;
lsma1a=lsma0a;
lsma1b=lsma0b;
lsma1c=lsma0c;
lsma0a = LSMA(Rperiod1,shift);
lsma0b = LSMA(Rperiod2,shift);
lsma0c = LSMA(Rperiod3,shift);
if ( lsma1a > lsma0a ) dir3++;
if ( lsma1b > lsma0b ) dir3++;
if ( lsma1c > lsma0c ) dir3++;
if ( lsma1a < lsma0a ) dir3--;
if ( lsma1b < lsma0b ) dir3--;
if ( lsma1c < lsma0c ) dir3--;
Buffer1[shift]=CLR_NONE;//EMPTY_VALUE;
Buffer2[shift]=CLR_NONE;//EMPTY_VALUE;
if ( dir3 == 3 ) Buffer2[shift]=High[shift];
if ( dir3 == (-3) ) Buffer1[shift]=Low[shift];
}
}
double LSMA(int myLPeriod, int myShift )
{
int myI;
double myLengthvar;
double mySum=0;
myLengthvar = myLPeriod + 1;
myLengthvar /= 3;
for(myI = myLPeriod; myI >= 1 ; myI--)
{
mySum += ( myI - myLengthvar)*Open[myLPeriod-myI+myShift];
}
return( mySum*6/(myLPeriod*(myLPeriod+1)) );
}
Comments