LSMA_in_Color_v1

Download script
LSMA_in_Color_v1

This technical tool is designed to provide a visual representation of market momentum and price trends by calculating specific weighted averages over a defined period. Rather than simply showing a standard moving average, it applies a sophisticated mathematical logic to emphasize how price movements are distributed over time.

Core Logic and Methodology

The script operates by analyzing historical closing prices within a specific window (the "period"). Instead of treating every price point in that window equally, the logic assigns a unique weight to each data point based on its position relative to the current moment. By calculating these weighted values, the tool can more effectively capture the underlying "velocity" or strength of a trend, smoothing out minor market noise while highlighting significant shifts in price direction.

Visual Representation

The primary output of this logic is displayed on your chart as a multi-colored line. The script uses a dynamic color-coding system to help traders identify the direction of market movement at a glance:

  • Directional Tracking: The tool constantly compares the current calculated value against the previous one.
  • Dynamic Color Shifting: When the trend changes—meaning the calculated momentum moves higher or lower than it did in the preceding moment—the script automatically adjusts the visual output. This creates a clear, continuous path where the colors shift to reflect whether the market is gaining strength or retreating.
  • Visual Clarity: By using specific color assignments (Yellow, Green, and Red), the indicator allows you to differentiate between upward pressure and downward momentum without needing to manually interpret complex numerical data.

Practical Purpose

The goal of this logic is to provide a "cleaned" view of price action. By prioritizing certain price points over others through its weighting system, it helps users identify whether a trend is accelerating or losing steam. It serves as a visual guide to help determine the prevailing market sentiment, making it easier to see where the momentum is heading in real-time.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
LSMA_in_Color_v1
//+------------------------------------------------------------------+
//|                                                        |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2008 "
#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 = 34;
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+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