Accelerator_LSMA_v2
Download scriptThis technical indicator, titled "Accelerator_LSMA_v2," is designed to help traders visualize the momentum and strength of price movements by analyzing the relationship between different types of moving averages. Instead of simply following price trends, it focuses on the "acceleration"—measuring how fast a trend is speeding up or slowing down.
Core Components of the Logic
1. The Least Squares Moving Average (LSMA) The foundation of this script is a specific type of average called the Least Squares Moving Average. Unlike standard moving averages that might lag behind the price, the LSMA uses a linear regression calculation. This means it attempts to find the "best fit" line for a specific period of data, providing a more responsive view of the current trend direction.
2. Dual-Speed Comparison (Fast vs. Slow) The script calculates two different versions of this LSMA:
- Fast LSMA: A short-term average that reacts quickly to recent price changes.
- Slow LSMA: A longer-term average that represents the broader, overarching trend.
By subtracting the Slow LSMA from the Fast LSMA, the indicator creates a "difference" value. This tells you not just where the price is going, but whether the short-term momentum is pulling ahead of or falling behind the long-term trend.
3. The Signal Smoothing To ensure the data isn't too volatile for a trader to read easily, the script takes that "difference" value and applies a third smoothing layer (a Simple Moving Average). This creates a "Signal Line," which acts as a baseline to identify when momentum shifts are becoming significant or when they are merely minor fluctuations.
Visual Interpretation
The indicator translates these mathematical differences into three distinct visual elements on your chart:
- The Main Value: It calculates the gap between the momentum and the signal line, multiplying it by 100 to make it easier to read on a large scale. This represents the current "strength" of the move.
- Dynamic Directional Tracking: The script compares the current momentum to the previous bar's momentum. If the momentum is increasing, it highlights the value in one direction; if it begins to decrease, it switches to another.
- Visual Cues (Histogram & Lines):
- A Yellow line tracks the primary momentum value.
- Green and Red histograms provide an immediate visual "pulse." They appear on opposite sides of a zero-line based on whether the acceleration is moving upward or downward. This allows a trader to see at a glance if the current price push is gaining speed or losing steam.
Summary for the User
Essentially, this tool acts as a "speedometer" for the market. It doesn't just tell you if the price is up or down; it tells you how hard the price is pushing in that direction. When the histograms are large and moving in one direction, the trend has high acceleration. When they begin to shrink or flip, it signals that the trend may be "decelerating," potentially warning of a coming reversal or a period of stagnation.
//+------------------------------------------------------------------+
//| 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