i-GentorLSMA&EMA_v1.0

Download script
Author: FX Sniper, KimIV
i-GentorLSMA&EMA_v1.0

This technical indicator is designed to provide traders with a visual representation of price momentum and trend direction by comparing the current market price against two specific types of moving averages: the Exponential Moving Average (EMA) and the Linear Weighted Moving Average (LSMA).

Core Logic Overview

The script operates by monitoring the relationship between the current closing price and two mathematical "averages" of past price data. Instead of simply plotting these averages as standard lines, the indicator acts as a signal generator that highlights whether the price is currently trading above or below these specific benchmarks.

Component Breakdown

1. Exponential Moving Average (EMA) Monitoring The script calculates an EMA based on a user-defined period (defaulting to 34). The EMA is a type of moving average that places a higher weight and significance on the most recent price data.

  • Action: The logic checks the current price against the EMA value. If the price is above the EMA, it identifies an upward bias; if the price is below, it identifies a downward bias.

2. Linear Weighted Moving Average (LSMA) Monitoring In addition to the EMA, the script calculates an LSMA based on a separate period (defaulting to 25). Unlike standard averages, the LSMA applies a weighted system where the most recent data points carry the heaviest influence on the result, making it highly responsive to sudden price shifts.

  • Action: The logic evaluates the current price against this weighted average to determine the immediate strength of the trend.

3. Visual Signaling System Rather than cluttering the chart with overlapping lines, the script uses a "Distance from Zero" logic to display signals:

  • Dynamic Positioning: The indicator creates markers at a specific distance above and below a center zero-line.
  • Conditional Display: A signal only appears on the screen when a specific condition is met (e.g., the price crosses above or below the respective average). If the condition is not met, the indicator remains invisible at that point.

Summary for Traders

Essentially, this tool acts as a "trend filter." By observing where the signals appear relative to the zero-line, traders can quickly identify when the market is gaining strength (moving above the averages) or losing momentum (falling below the averages). It combines the stability of the EMA with the high responsiveness of the LSMA to provide a comprehensive view of current market sentiment.

Indicators Used
Moving average indicator
16 Views
0 Downloads
0 Favorites
i-GentorLSMA&EMA_v1.0
//+---------------------------------------------------------------------+
//|                                       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 = 25;     // 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