i-GentorLSMA&EMA_v[1]_v1
Download scriptThis tool is designed as a visual market analysis indicator that helps traders identify potential trend shifts and price momentum by monitoring the relationship between current price action and two distinct moving averages: the Exponential Moving Average (EMA) and the Linear Scaled Moving Average (LSMA).
Core Logic and Behavior
The script functions by comparing the closing price of a financial instrument against these two mathematical models. Rather than simply showing lines on a chart, it uses "conditional visibility," meaning it only displays data points when specific market conditions are met.
1. EMA Interaction (Trend Monitoring) The indicator calculates a standard Exponential Moving Average based on a user-defined period. It acts as a filter for the price:
- If the current price is trading above the calculated EMA, the tool recognizes an upward sentiment.
- If the current price falls below the EMA, it recognizes a downward sentiment. By only plotting points when these conditions are met, the indicator helps highlight whether the price is currently maintaining its position relative to the moving average.
2. LSMA Interaction (Momentum & Scaling) The tool also incorporates a Linear Scaled Moving Average. Unlike a standard average, this type of calculation applies a weighted distribution to the price data over a specific period. This allows the indicator to react differently to trends than the EMA does.
- It calculates a specific weight based on the timeframe provided by the user.
- It compares this weighted value against the current closing price.
- Similar to the EMA logic, it only displays information when the price confirms a specific position relative to this weighted average.
3. Visual Representation and "Distance from Zero" Because these indicators are designed to appear in a separate window (rather than directly on the main price chart), they utilize a "FromZero" offset. This ensures that the visual markers for the EMA and LSMA are plotted at a consistent distance from the baseline, preventing them from overlapping with the zero axis. This creates a clean, readable workspace where different colors represent different trend signals.
Summary of Usage
For a trader, this logic provides a filtered view of market dynamics. Instead of seeing constant lines, the user sees visual confirmations that appear only when the price validates a move against two different types of mathematical averages—one focused on smooth exponential trends and the other on linear weighted momentum.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| i-GentorLSMA&EMA_v.1.0.mq4 |
//| FX Sniper, KimIV |
//| 2005.08.20 KimIV v.0.0 |
//| Ñîåäèíèë â LSMA è EMA |
//| 2005.08.20 KimIV v.0.2 |
//| Ñèíõðîíèçèðîâàë íóìåðàöèþ âåðñèé ñ i-GentorCCIM_v.0.2.mq4 |
//| 2005.08.21 KimIV v.1.0 |
//| Âûíåñ âî âíåøíèé ïàðàìåòð ðàññòîÿíèå îò íóëÿ äëÿ ÅÌÀ è LSMA |
//+------------------------------------------------------------------+
#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 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 Lime
//------- Âíåøíèå ïàðàìåòðû ------------------------------------------
extern int EMAPeriod = 34; // Ïåðèîä ÅÌÀ
extern int LSMAPeriod = 25; // Ïåðèîä LSMA
extern int FromZero = 3; // Ðàññòîÿíèå îò íóëåâîãî óðîâíÿ
//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double LineHighEMA[];
double LineLowEMA[];
double LSMABuffer1[];
double LSMABuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init() {
IndicatorDigits(2);
SetIndexBuffer(0, LineHighEMA);
SetIndexLabel (0, "EMA âûøå öåíû");
SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 5);
SetIndexBuffer(1, LineLowEMA);
SetIndexLabel (1, "EMA íèæå öåíû");
SetIndexStyle (1, DRAW_LINE, STYLE_SOLID, 5);
SetIndexBuffer(2, LSMABuffer1);
SetIndexLabel (2, "LSMA âûøå öåíû");
SetIndexStyle (2, DRAW_LINE, STYLE_SOLID, 5);
SetIndexBuffer(3, LSMABuffer2);
SetIndexLabel (3, "LSMA íèæå öåíû");
SetIndexStyle (3, DRAW_LINE, STYLE_SOLID, 5);
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