LSMA in ColorOpen3
Download scriptThis trading indicator is designed to help market observers identify potential trend reversals by analyzing the momentum of three different moving averages simultaneously. Instead of looking at simple price action, it evaluates the underlying "flow" of the market to spot moments where the trend may be losing steam or shifting direction.
How the Logic Works
1. Multi-Layered Momentum Tracking The script monitors three distinct types of Linear Weighted Moving Averages (LSMA). Each of these averages looks at different time horizons (defaulting to 15, 30, and 60 periods). By using three different lengths, the indicator captures short-term volatility, medium-term trends, and long-term momentum all at once.
2. Directional Analysis For every new price candle that forms, the script compares the current value of these three moving averages against their previous values. It assigns a numerical score based on the direction of movement:
- If a moving average is higher than it was in the previous period, it adds to the "upward" momentum score.
- If a moving average is lower than it was in the previous period, it subtracts from the score, indicating "downward" momentum.
3. Signal Generation (The Arrows) The indicator only triggers a visual signal when there is total consensus across all three time horizons. This prevents "false starts" caused by a single short-term spike.
- Sell Signals (Red Down Arrow): These appear only when all three moving averages are trending downward simultaneously. This suggests that the market's momentum has shifted significantly to the downside across short, medium, and long timeframes.
- Buy Signals (White Up Arrow): These appear only when all three moving averages are trending upward simultaneously. This indicates a unified move toward the upside, suggesting strong bullish momentum.
Summary for the Trader
Think of this tool as a "consensus filter." Rather than reacting to every tiny price flicker, the script waits for the three major trend lines to agree with each other. When all three point in the same direction, it places an arrow on your chart to highlight a high-probability momentum shift.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| |
//| 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