LSMA EMA
Download scriptThis technical indicator is designed to provide visual clarity regarding the relationship between current market prices and two distinct types of moving averages: the Exponential Moving Average (EMA) and the Linear Weighted Moving Average (LSMA). Instead of simply plotting these lines as standard trend indicators, this tool acts as a dynamic filter that highlights whether the price is trading above or below specific calculated thresholds.
Core Logic and Mechanics
The indicator operates by evaluating two different mathematical approaches to price trends simultaneously:
- EMA Analysis: This component calculates a standard Exponential Moving Average, which gives more weight to recent price data. The logic checks the current closing price against this average. It is designed to identify when the market is gaining momentum relative to its recent history.
- LSMA Analysis: This component utilizes a Linear Weighted Moving Average. Unlike a standard moving average that treats all days equally, the LSMA applies a linear weighting system where the most recent prices have the highest impact on the calculation. This makes it highly responsive to sudden shifts in market direction.
Visual Representation
The primary purpose of this script is to "filter" the visual noise of the chart. Rather than drawing continuous lines that can clutter the screen, the indicator uses a logic based on price positioning:
- Threshold Detection: The tool establishes a baseline (a specific distance from the zero level) to anchor its data.
- Dynamic Positioning:
- If the market price sits above the calculated average, the indicator registers a signal for the upper boundary.
- If the market price sits below the calculated average, it registers a signal for the lower boundary.
- Data Suppression: The script intelligently hides (empties) values that do not meet these specific conditions. This means that on your chart, you only see the data points that represent an active state of "Price vs. Average."
Summary for Traders
By using this tool, a user can quickly discern the dominance of price action over trend averages. Because it combines both the EMA (smooth trend) and the LSMA (weighted momentum), it provides a dual-layered view of whether the market is currently trading in a high-strength zone or a low-strength zone relative to its moving historical benchmarks. It simplifies the decision-making process by visually highlighting these specific price-to-average relationships in real-time.
//+---------------------------------------------------------------------+
//| i-GentorLSMA&EMA_v.1.0.mq4 |
//| FX Sniper, KimIV |
//| 2005.08.20 KimIV v.0.0 |
//| Combined in LSMA and EMA |
//| 2005.08.20 KimIV v.0.2 |
//| Synchronized numeration of the versions with i-GentorCCIM_v.0.2.mq4 |
//| 2005.08.21 KimIV v.1.0 |
//| Distance from zero for EMA and LSMA is changable now |
//+---------------------------------------------------------------------+
#property copyright "FX Sniper, KimIV"
#property link "http://www.kimiv.ru"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Lime
//------- Âíåøíèå ïàðàìåòðû ------------------------------------------
extern int EMAPeriod = 34; // ÅÌÀ period
extern int LSMAPeriod = 21; // LSMA period
extern int FromZero = 3; // Distance from zero level
//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double LineHighEMA[];
double LineLowEMA[];
double LSMABuffer1[];
double LSMABuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init() {
IndicatorDigits(2);
SetIndexBuffer(0, LineHighEMA);
SetIndexLabel (0, "EMA is above price");
SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 3);
SetIndexBuffer(1, LineLowEMA);
SetIndexLabel (1, "EMA is below price");
SetIndexStyle (1, DRAW_LINE, STYLE_SOLID, 3);
SetIndexBuffer(2, LSMABuffer1);
SetIndexLabel (2, "LSMA is above price");
SetIndexStyle (2, DRAW_LINE, STYLE_SOLID, 3);
SetIndexBuffer(3, LSMABuffer2);
SetIndexLabel (3, "LSMA is below price");
SetIndexStyle (3, DRAW_LINE, STYLE_SOLID, 3);
Comment("");
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
double sum, lengthvar, tmp, wt;
int i, shift, counted_bars = IndicatorCounted();
int Draw4HowLong, loopbegin;
if (counted_bars<0) return;
if (counted_bars>0) counted_bars--;
counted_bars = Bars - counted_bars;
for (shift=0; shift<counted_bars; shift++) {
LineLowEMA[shift] = -FromZero;
LineHighEMA[shift] = -FromZero;
double EmaValue = iMA(NULL, 0, EMAPeriod, 0, MODE_EMA, PRICE_TYPICAL, shift);
if (Close[shift]>EmaValue) LineHighEMA[shift] = EMPTY_VALUE;
if (Close[shift]<EmaValue) LineLowEMA[shift] = EMPTY_VALUE;
}
Draw4HowLong = Bars-LSMAPeriod - 5;
loopbegin = Draw4HowLong - LSMAPeriod - 1;
for(shift=loopbegin; shift>=0; shift--) {
sum = 0;
for (i=LSMAPeriod; i>=1; i--) {
lengthvar = LSMAPeriod + 1;
lengthvar /= 3;
tmp = 0;
tmp = (i - lengthvar) * Close[LSMAPeriod-i+shift];
sum+=tmp;
}
wt = sum * 6 / (LSMAPeriod * (LSMAPeriod + 1));
LSMABuffer1[shift] = FromZero;
LSMABuffer2[shift] = FromZero;
if (wt>Close[shift]) LSMABuffer2[shift] = EMPTY_VALUE;
if (wt<Close[shift]) LSMABuffer1[shift] = EMPTY_VALUE;
}
}
//+------------------------------------------------------------------+
Comments