LSMA_in_Color3

Download script
LSMA_in_Color3

This custom technical indicator is designed to provide visual market analysis by identifying price trends and momentum shifts. Instead of simply plotting a static line, it uses a weighted mathematical approach to determine the "strength" of current price movements over a specific period.

Core Logic Overview

The tool operates by looking at a historical window of price data (defined by the user) and applying a weighted calculation to each point. Unlike basic moving averages that treat all data points equally, this logic gives different importance to different prices within the lookback period. This creates a smoother, more reactive representation of market velocity.

How it Works:

  • Trend Calculation: The script scans back through previous price "closes" and calculates a weighted sum. By weighting these values, the indicator can more accurately reflect the underlying momentum of the market rather than just reacting to sudden, insignificant price spikes.
  • Dynamic Coloring System: The most unique feature of this script is its visual feedback system. Rather than showing a single continuous line, it uses three distinct color buffers (Yellow, Green, and Red) to communicate movement direction:
    • Upward Momentum: When the current weighted value is higher than the previous one, the indicator highlights the trend in one specific color (Green), signaling an upward move.
    • Downward Momentum: When the current weighted value drops below the previous one, the indicator shifts to a different color (Yellow), signaling a downward move.
    • Neutrality: If there is no change between the values, the indicator remains neutral or "empty," ensuring that only active market movements are highlighted to the trader.

Summary for Traders

In simple terms, this tool acts as a visual "momentum tracker." It filters out some of the noise found in standard charts by calculating a weighted average of recent price action. By changing colors based on whether that momentum is rising or falling, it allows you to see at a glance whether the market is trending up or down without having to manually interpret complex raw data.

Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
LSMA_in_Color3
//+------------------------------------------------------------------+
//|                                                        |
//|                      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 Green
#property indicator_color3 Red

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

extern int Rperiod = 14;
extern int Draw4HowLongg = 1500;
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,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);

//---- 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] = 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] = EMPTY_VALUE; //-1 red/greem tight
       //ExtMapBuffer3[shift+1] = EMPTY_VALUE;
        
        }
         else 
         {
         
         ExtMapBuffer1[shift]=EMPTY_VALUE;//EMPTY_VALUE;
         ExtMapBuffer2[shift]=EMPTY_VALUE;//EMPTY_VALUE;
         }
        
      }
    
      return(0);
  }
//+------------------------------------------------------------------+



Comments