LSMA_in_color_00a

LSMA_in_color_00a

This script functions as a specialized visual analysis tool designed for the MetaTrader platform. Its primary purpose is to track price momentum and identify specific entry signals by calculating a modified moving average of the market's closing prices.

Core Logic & Visuals

The tool creates several dynamic visual elements on your trading chart:

  • Trend Tracking: The script calculates a custom "Linear Weighted" value based on a user-defined period. This is visualized as a yellow line, which acts as the baseline for the current market trend.
  • Dynamic Channels: It generates two additional lines (Green and Red) that hover slightly above and below the main trend line. These represent a specific "buffer zone" or range around the moving average.
  • Signal Indicators: Beyond the lines, the script identifies specific price points using distinct symbols (dots and boxes). These appear automatically when the market meets specific mathematical conditions.

How the Analysis Works

The logic processes historical data to determine the direction of the market:

  1. Momentum Calculation: The script looks at a set number of previous bars and applies a weighted formula to them. This ensures that more recent price action has a greater influence on the current value than older data.
  2. Directional Detection: It constantly compares the current weighted value against the previous one.
    • If the value is decreasing, it marks a "Red" count.
    • If the value is increasing, it marks a "Green" count.
  3. Reset Mechanism: To ensure the signals are based on fresh momentum rather than old data, the script automatically resets its internal counters once both "Red" and "Green" movements have occurred in sequence. This filters out "noise" and focuses on consistent trends.

Entry Signals

The tool is programmed to trigger specific visual alerts (the white symbols) based on the frequency of these movements:

  • Buy Signal: When the script detects a sustained upward momentum (a specific count of consecutive "Green" moves), it places a symbol at the high of the candle.
  • Sell Signal: When the script detects a sustained downward momentum (a specific count of consecutive "Red" moves), it places a symbol at the low of the candle.

Summary for the User

Essentially, this tool acts as a "momentum filter." It smooths out the erratic movements of the market to show you the underlying trend. By tracking how many times the price consistently moves in one direction relative to its weighted average, it highlights potential points where a trend has gained enough strength to be considered a valid trade signal.

Price Data Components
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
LSMA_in_color_00a
//+------------------------------------------------------------------+
//| LSMA indicator with global variables to drive a companion expert |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, FX Sniper "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window

#property indicator_buffers   5
#property indicator_color1  Yellow      
#property indicator_color2  Green
#property indicator_color3  Red
#property indicator_color4  White
#property indicator_color5  White


//---- buffers
double ExtMapBuffer1[];  //Yellow
double ExtMapBuffer2[];  //Green
double ExtMapBuffer3[];  //Red
double XBuffer[];        //White
double ZBuffer[];        //White

extern int extRperiod = 32;
extern int extDraw4HowLong = 500;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   SetIndexBuffer(0,ExtMapBuffer1);   //Yellow
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);

   SetIndexBuffer(1,ExtMapBuffer2);  //Green
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);

   SetIndexBuffer(2,ExtMapBuffer3);  //Red
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);


   // 233 up arrow
   // 234 down arrow
   // 158 little dot
   // 159 big dot
   // 168 open square
   // 120 box with X
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3, XBuffer);     //White
   SetIndexArrow(3,120);

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexBuffer(4, ZBuffer);     //White
   SetIndexArrow(4,159);

   return(0);
  }

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   int i;
   
   for( i=0; i<Bars; i++ ) ExtMapBuffer1[i]=0;
   for( i=0; i<Bars; i++ ) ExtMapBuffer2[i]=0;
   for( i=0; i<Bars; i++ ) ExtMapBuffer3[i]=0;
   for( i=0; i<Bars; i++ ) XBuffer[i]=0;
   for( i=0; i<Bars; i++ ) ZBuffer[i]=0;

   return(0);
  }


int start()
  {   

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

   double wtp; //previous value
   double wt;  //current value
   int    rc=0;
   int    gc=0;
   
   double p=Point;
   
   length = extRperiod;
   loopbegin = extDraw4HowLong - length - 1;
 
   for(pos = loopbegin; pos >= 0; pos--)
     { 
      sum = 0;
      for(i = length; i >= 1  ; i--)
        {
         lengthvar = length + 1;
         lengthvar /= 3;
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+pos];
         sum+=tmp;
        }
         
      wtp=wt;
      wt = sum*6/(length*(length+1));
         
      ExtMapBuffer1[pos] = wt;   //yellow
      ExtMapBuffer2[pos] = wt+(10*Point());   //green
      ExtMapBuffer3[pos] = wt-(10*Point());   //red 

      if (wtp > wt)
        {
         ExtMapBuffer2[pos+1] = wt; //remove GREEN
         rc++;
         ZBuffer[pos]=Low[pos];
        }
      else
        {
         ExtMapBuffer3[pos+1] = wt; //remove RED
         gc++;
         ZBuffer[pos]=High[pos];
        }

      //Comment("wtp=",wtp,"\nwt=",wt,"\nRed=",rc,"\nGreen=",gc);
      
      
      if (gc>0 && rc>0)
        {
         // Close any orders
         gc=0; 
         rc=0;
        }
      
      if (gc==6)
        {
         // indicate buy order 
         XBuffer[pos]=High[pos];
        }
        
      if (rc==6)
        {
         // indicate sell order 
         XBuffer[pos]=Low[pos];
        }

     }

   return(0);
  }
//+------------------------------------------------------------------+



Comments