Accelerator_LSMA_v2_v1
Download scriptThe Accelerator LSMA v2 is a technical analysis tool designed to help traders identify momentum shifts and price trends by measuring the "speed" of market movement. Unlike standard oscillators that might simply show if a price is going up or down, this script focuses on how quickly that movement is accelerating or decelerating.
Core Logic & Methodology
The indicator operates through a multi-layered calculation process:
1. The Foundation: Least Squares Moving Average (LSMA) Instead of using a simple average of past prices, the tool utilizes the Least Squares Moving Average. This is a sophisticated mathematical method that calculates a linear regression line for a specific period. In simpler terms, it attempts to find the "best fit" line through a series of data points, making it more responsive to recent price trends than a traditional moving average.
2. Momentum Differentiation The script creates two distinct LSMA values: a Fast version and a Slow version.
- By subtracting the Slow LSMA from the Fast LSMA, the indicator calculates the "velocity" of the market.
- If the gap between these two lines is widening, it suggests accelerating momentum; if the gap is narrowing, it suggests the trend is losing steam.
3. Signal Smoothing To prevent "market noise" (random, jagged price fluctuations) from providing false signals, the script applies an additional Simple Moving Average (SMA) to the velocity data. This creates a secondary "Signal Line," allowing the user to see the underlying trend of the momentum more clearly.
4. Visual Dynamics and Color Logic The final output is presented in a dedicated sub-window on your chart, using three distinct visual components:
- The Main Line (Yellow): This represents the actual difference between the calculated momentum and its signal line. It provides the primary reading of current market strength.
- The Momentum Histograms (Green & Red): These bars act as a directional confirmation. The logic automatically switches between green and red based on whether the momentum is increasing or decreasing compared to the previous bar.
How to Interpret the Results
For a user, this tool serves as a "momentum gauge." When the yellow line is moving upward and the histograms are green, it indicates that the current trend is gaining strength. Conversely, if the yellow line begins to curl downward while the histograms turn red, it signals that the market's upward energy is exhausting, potentially foreshadowing a reversal or a period of consolidation.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Accelerator_LSMA_v2.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#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
#property indicator_level1 0.0
extern int FastLsma = 5; // default = 5
extern int SlowLsma = 34; // default = 34
extern int MaArray = 5; // default = 5
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double ExtBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,38);
SetIndexDrawBegin(1,38);
SetIndexDrawBegin(2,38);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("AC");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------------+
//| LSMA - Least Squares Moving Average function calculation |
//| LSMA_In_Color Indicator plots the end of the linear regression line |
//+------------------------------------------------------------------------+
double LSMA(int Rperiod, int shift)
{
int i;
double sum;
int length;
double lengthvar;
double tmp;
double wt;
length = Rperiod;
sum = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
tmp = ( i - lengthvar)*Close[length-i+shift];
sum+=tmp;
}
wt = sum*6/(length*(length+1));
return(wt);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ExtBuffer3[i]=LSMA(FastLsma,i)-LSMA(SlowLsma,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,MaArray,0,MODE_SMA,i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ExtBuffer3[i]-ExtBuffer4[i];
prev=ExtBuffer3[i+1]-ExtBuffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ExtBuffer2[i]=current*100;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current*100;
ExtBuffer2[i]=0.0;
}
ExtBuffer0[i]=current*100;
}
//---- done
return(0);
}
Comments