Lsma2

This script is a custom technical analysis tool designed to help traders identify trends on a price chart. It functions by creating a smoothed trend line, often referred to as a Linear Weighted Moving Average (LSMA), which helps filter out "market noise" to reveal the underlying direction of price movement.

How it Works

The logic follows a specific mathematical process to ensure that the trend line is not just an average of all past prices, but rather a weighted representation of recent activity:

  • Weighting System: Unlike a standard moving average—where every day or hour in a period carries the same importance—this script gives more significance to the most recent price data. By applying this weighting, the indicator reacts more intelligently to current market momentum while still accounting for historical context.
  • Dynamic Calculation: For every new candle that appears on your chart, the script looks back at a specific number of previous periods (defined by the user settings). It calculates a sum based on the relationship between the price and its position in time relative to those periods.
  • Smoothing Effect: Once the weighted sum is calculated, the script applies a final normalization formula. This produces a smooth, continuous line on your chart.

What it Shows You

Instead of following every tiny "zig-zag" of the market, this indicator provides a clearer picture of where the price is headed. Because it is weighted toward recent events:

  1. It tends to be more responsive to sudden changes in trend than a simple average.
  2. It helps traders visualize the "fair value" or the primary path of the market at any given moment.
  3. The resulting yellow line serves as a visual guide to help determine whether the current market sentiment is bullish (moving up) or bearish (moving down).
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Lsma2
//+------------------------------------------------------------------+
//|                                                       LSMA       |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, FX Sniper "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 2      

//---- buffers
double ExtMapBuffer1[];

extern int Rperiod = 14;
int shift;
int i;
int loopbegin;
double sum1;
int length;
double lengthvar;
double tmp ;
double wt;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   IndicatorBuffers(1);
   
//---- drawing settings
   SetIndexBuffer(0,ExtMapBuffer1);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);

//---- initialization done
   return(0);
  }

int start()

  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
  
      length = Rperiod;
 
      for(shift = limit; shift >= 0; shift--)
      { 
         sum1 = 0;
         for(i = length; i >= 1  ; i--)
         {
         lengthvar = length + 1;
         lengthvar /= 3;
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+shift];
         sum1+=tmp;
         }
         wt = sum1*6/(length*(length+1));
         
//========== COLOR CODING ===========================================               
        
       ExtMapBuffer1[shift] = wt;
       
      }
    
      return(0);
  }
//+------------------------------------------------------------------+



Comments