i-GentorLSMA&EMA_v.1.1

Download script
Author: FX Sniper, KimIV
i-GentorLSMA&EMA_v.1.1

This indicator is designed to provide traders with a visual representation of price momentum and the distance between current market prices and two specific moving averages: the Exponential Moving Average (EMA) and the Linear Weighted Moving Average (LSMA).

By analyzing these two different types of averages simultaneously, the tool helps identify how "stretched" the price is from its recent historical trend. Here is a breakdown of the logic used to generate the visuals:

Core Components

The script tracks three primary elements to provide a complete picture of market behavior:

  1. EMA (Exponential Moving Average): A trend line that gives more weight to recent price data.
  2. LSMA (Linear Weighted Moving Average): A trend line where weights are distributed linearly, emphasizing the most recent prices even more heavily than the EMA.
  3. Price Distance: The script calculates exactly how far the current market price is from both of these averages.

How the Logic Works

The indicator functions by performing three main tasks on every candle:

1. Identifying Trend Position (High/Low Markers) The script monitors whether the current closing price is trading above or below the EMA and LSMA lines.

  • If the price is above a line, it designates that as a "high" position.
  • If the price is below a line, it designates that as a "low" position.
  • This creates a visual boundary on the chart, helping you see at a glance whether the price is currently in an overextended state relative to the averages.

2. Distance Calculation One of the key features of this tool is its ability to measure "Distance." It calculates the numerical gap between the current price and both moving averages. Instead of just seeing that the price is "higher" or "lower," the script translates this into a measurable distance. This helps traders identify when a market move might be over-extended (overbought or oversold) and potentially due for a correction.

3. Dynamic Visual Rendering The tool uses a "FromZero" variable to establish a baseline. It plots specific indicators only when certain conditions are met (e.g., showing a high marker only when the price exceeds the average). This ensures that the chart remains clean, only displaying relevant data points that signify significant price action or trend deviations.

Summary for the User

In simple terms, this script acts as a momentum and deviation tracker. It doesn't just tell you where the trend is going; it tells you how "far" the current price has pushed away from that trend. By comparing the EMA (the smoother trend) with the LSMA (the more aggressive trend), you can better judge whether the market is moving sustainably or if it is becoming too stretched in one direction.

Indicators Used
Moving average indicator
8 Views
0 Downloads
0 Favorites
i-GentorLSMA&EMA_v.1.1
//+------------------------------------------------------------------+
//|                                       i-GentorLSMA&EMA_v.1.1.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      |
//|   2005.08.21 KimIV  v.1.1                                        |
//| Äâà äîïîëíèòåëüíûõ áóôåðà îòâ¸ë äëÿ õðàíåíèÿ ðàññòîÿíèÿ ìåæäó    |
//| EMA, LSMA è Close.                                               |
//+------------------------------------------------------------------+
#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;     // Ïåðèîä ÅÌÀ
extern int LSMAPeriod = 25;     // Ïåðèîä LSMA
extern int FromZero   = 3;      // Ðàññòîÿíèå îò íóëåâîãî óðîâíÿ

//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double LineHighEMA[];
double LineLowEMA[];
double LSMABuffer1[];
double LSMABuffer2[];
double DistEMA[];
double DistLSMA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  IndicatorBuffers(6);
  IndicatorDigits(2);

  SetIndexBuffer(0, LineHighEMA);
  SetIndexLabel (0, "EMA âûøå öåíû");
  SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 3);
  SetIndexBuffer(1, LineLowEMA);
  SetIndexLabel (1, "EMA íèæå öåíû");
  SetIndexStyle (1, DRAW_LINE, STYLE_SOLID, 3);
  SetIndexBuffer(2, LSMABuffer1);
  SetIndexLabel (2, "LSMA âûøå öåíû");
  SetIndexStyle (2, DRAW_LINE, STYLE_SOLID, 3);
  SetIndexBuffer(3, LSMABuffer2);
  SetIndexLabel (3, "LSMA íèæå öåíû");
  SetIndexStyle (3, DRAW_LINE, STYLE_SOLID, 3);
  SetIndexBuffer(4, DistEMA);
  SetIndexBuffer(5, DistLSMA);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  double sum, lengthvar, tmp, wt, EmaValue;
  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;

    EmaValue = iMA(NULL, 0, EMAPeriod, 0, MODE_EMA, PRICE_TYPICAL, shift);
    DistEMA[shift] = MathRound((EmaValue - Close[shift]) / Point);
    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));
    DistLSMA[shift] = MathRound((wt - Close[shift]) / Point);

    LSMABuffer1[shift] = FromZero;
    LSMABuffer2[shift] = FromZero;

    if (wt>Close[shift]) LSMABuffer2[shift] = EMPTY_VALUE;
    if (wt<Close[shift]) LSMABuffer1[shift] = EMPTY_VALUE;
  }
}
//+------------------------------------------------------------------+

Comments