LSMA+in+Color_v1

Download script
LSMA+in+Color_v1

This technical tool is designed to analyze price movements by calculating a weighted trend line based on historical closing prices. Its primary goal is to smooth out market "noise" and provide a visual representation of the prevailing momentum, helping traders distinguish between significant trends and minor fluctuations.

Core Logic and Methodology

The script operates through a sophisticated mathematical progression that moves beyond simple moving averages. Here is how the logic flows:

1. Data Weighting System Instead of treating every price point in a time period equally, the script applies a unique weighting logic. It calculates a sum where earlier data points are treated differently than more recent ones. By multiplying these prices by their specific position in the look-back period (the "Rperiod"), the tool ensures that the resulting value is highly responsive to current market dynamics while still remaining grounded in historical context.

2. Dynamic Normalization Once the weighted sum is calculated, the script performs a normalization step. It divides the total by a factor derived from the length of the period. This translates the raw data into a consistent "weighted value," which serves as the foundation for the visual indicator on your chart.

3. Trend Identification and Visualization The script continuously compares the current weighted value against the previous one to determine the direction of the market:

  • Trend Detection: By comparing the value at the current moment to the value immediately preceding it, the tool identifies whether the momentum is moving upward or downward.
  • Visual Filtering: To make the chart cleaner and more readable, the script uses conditional logic to "hide" certain parts of the line. It intelligently decides which segments of the trend should be visible based on whether the price movement is increasing or decreasing. This prevents the chart from becoming cluttered with unnecessary overlapping lines, allowing the user to see the primary direction of the trend clearly.

User Experience Summary

For the end-user, this means the indicator provides a streamlined, color-coded visual path of the market's strength. Rather than showing every tiny tick of price movement, it filters the data to highlight the underlying momentum, making it easier to identify whether the current trend is gaining strength or losing steam.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
LSMA+in+Color_v1
//+------------------------------------------------------------------+
//|                                                        |
//|                      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 3
#property indicator_color1 Yellow      
#property indicator_color2 Chartreuse
#property indicator_color3 Red

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;

extern int Rperiod = 34;
extern int Draw4HowLongg = 300;  // 500 // 1000
int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum[];
int length;
double lengthvar;
double tmp ;
double wt[];
int c;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
   
//---- drawing settings
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(0,ExtMapBuffer3);
   SetIndexBuffer(3,sum);
   SetIndexBuffer(4,wt);
   
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);  
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);  
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);  

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

int start()

  {   Draw4HowLong = Bars-Rperiod - 5;
      length = Rperiod;
      loopbegin = Draw4HowLong - length - 1;
 
      for(shift = loopbegin; shift >= 0; shift--)
      { 
         sum[1] = 0;
         for(i = length; i >= 1  ; i--)
         {
         lengthvar = length + 1;
         lengthvar /= 3;
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+shift];
         sum[1]+=tmp;
         }
         wt[shift] = sum[1]*6/(length*(length+1));
         
//========== COLOR CODING ===========================================               
        
       ExtMapBuffer3[shift] = wt[shift]; //red 
       ExtMapBuffer2[shift] = wt[shift]; //green
       ExtMapBuffer1[shift] = wt[shift]; //yellow
       
       //  for(c=loopbegin;c==shift;c++)
       // {
        if (wt[shift+1] > wt[shift])
        {
        ExtMapBuffer2[shift+1] = EMPTY_VALUE;
  // ObjectCreate("smiley_face", OBJ_ARROW, 0, Time[shift], Low[shift]-Point*20);
  // Print("time=  ",Time[shift]);
  // ObjectSet("smiley_face", OBJPROP_ARROWCODE, 242);
  // ObjectSet("smiley_face", OBJPROP_COLOR , Red);
  // ObjectSet("smiley_face", OBJPROP_WIDTH  , 1);
  // ObjectsRedraw();

        //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        
        }
       else if (wt[shift+1] < wt[shift]) 
        {
        ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
       //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        
        }
         else 
         {
         
         ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
         ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
         }
        
      }
    
      return(0);
  }
//+------------------------------------------------------------------+



Comments