LSMA_ind_01b

Download script
LSMA_ind_01b

This tool is designed as a visual trend indicator for trading platforms, aimed at helping traders identify the underlying momentum and direction of price movements in real-time. Instead of simply following the raw price, it uses a mathematical smoothing technique to filter out market "noise," providing a clearer picture of where the market is headed.

Core Logic and Functionality

1. Weighted Price Analysis The script operates by analyzing a specific window of historical price data (defined by the "Rperiod" setting). Rather than treating every past price point as equally important, the logic applies a weighted calculation. It gives different importance to prices based on their position relative to the current timeframe. This allows the indicator to prioritize more recent price action while still acknowledging the broader trend.

2. Trend Smoothing and Calculation The tool calculates a weighted sum of these prices and converts that sum into a single, fluid value. This value represents the "momentum" or "velocity" of the market at any given moment. By transforming raw data into this smooth value, the indicator helps traders see whether the market is gaining strength, losing steam, or moving sideways.

3. Dynamic Visual Feedback (Color Coding) The most practical feature for a user is how the script communicates these changes visually on the chart:

  • Directional Detection: The script constantly compares the current momentum value against the previous one to determine if the trend is rising or falling.
  • Visual Distinction: It utilizes three distinct color buffers (Yellow, Green, and Red) to represent different states of movement.
  • Smart Filtering: To keep the chart clean, the logic is designed to "hide" certain colors based on the direction of the move. If the momentum is moving in one direction, it clears out the opposing color signals. This ensures that the user isn't overwhelmed by conflicting visual data and can quickly see the prevailing trend at a glance.

Summary for the User

In essence, this script acts as a "trend filter." It looks back at a set number of bars, weighs the importance of those prices, and translates that into a smoothed line on your chart. By automatically switching between color profiles based on whether the momentum is increasing or decreasing, it provides a clear, visual representation of market flow, helping you distinguish between meaningful price movements and minor fluctuations.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
LSMA_ind_01b
/*-----------------------------+
|			       |
| 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[];
int width;

extern int Rperiod = 34;
extern int Draw4HowLong = 500;

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