LSMA_ind_01

Download script
LSMA_ind_01

This tool is designed to provide a visual representation of price momentum and trend direction on your trading charts. By analyzing historical price data, the script identifies whether the market is currently trending upwards, downwards, or moving sideways, translating these complex movements into easy-to-read visual signals.

How the Logic Works

1. Data Aggregation & Weighting The core of the script relies on a specific calculation method that looks at a designated window of past price candles (defined by the period settings). Instead of looking at every candle equally, the logic applies a weighted mathematical formula to the closing prices. This means that more recent price action is given different significance than older data, allowing the tool to react more dynamically to new market information.

2. Trend Calculation The script constantly calculates a running total based on these weights. By comparing these values across consecutive points in time, it determines the "velocity" of the price movement. This helps smooth out the minor "noise" or random fluctuations often seen in volatile markets, focusing instead on the underlying direction of the price action.

3. Visual Signal Coloring The primary purpose of this calculation is to provide a clear, color-coded map on your chart:

  • Trend Detection: The script monitors the relationship between current and previous values. If the calculated momentum is moving higher, it identifies an upward trend. If it is moving lower, it identifies a downward trend.
  • Dynamic Display: To keep the chart clean and readable, the script uses a "conditional visibility" logic. It only highlights the specific color corresponding to the active trend. For example, when the price momentum is rising, it prioritizes one visual indicator while suppressing others; conversely, when the momentum falls, it switches the focus to the opposite signal.
  • Real-Time Updates: As new candles form and close, the script re-runs its calculations instantly. This ensures that the colored lines on your chart are always updated to reflect the most current market sentiment.

Summary for Traders

In simple terms, this script acts as a visual filter. It takes a large amount of raw price data, weighs it based on its relevance, and translates it into a moving line that changes appearance based on momentum. This allows you to see at a glance whether the current market "flow" is leaning bullish or bearish without having to manually interpret every candle.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
LSMA_ind_01
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                        |
//|                      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[];

extern int Rperiod = 48;
extern int Draw4HowLong = 500;

//----- variables
int    c;
int    i;
int    length;
double lengthvar;
int    loopbegin;
int    pos;
int    width;


// arrays 
double sum[];
double tmp ;
double wt[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //2 additional buffers are used for counting.
   IndicatorBuffers(5);

   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);

   return(0);
  }

int start()

  {   
      length = Rperiod;
      loopbegin = Draw4HowLong - length - 1;
 
      for(pos = loopbegin; pos >= 0; pos--)
      { 
         sum[1] = 0;
         for(i = length; i >= 1  ; i--)
         {
         lengthvar = length + 1;
         lengthvar /= 3;
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+pos];
         sum[1]+=tmp;
         }
         
         wt[pos] = sum[1]*6/(length*(length+1));
         
//========== COLOR CODING ===========================================               
        
      // 1 Yellow      
      // 2 Green
      // 3 Red

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



Comments