LSMA1_v1
Download scriptThis technical tool is designed as a visual assistant for traders to identify price trends and potential momentum shifts by analyzing historical closing prices. It functions by creating a smoothed moving average that reacts to the relationship between current market prices and recent historical data.
Core Operational Logic
The script processes market data through several distinct stages to generate its visual output:
1. Historical Data Weighting Rather than treating all past prices equally, the tool applies a specific mathematical weight to historical data points. It looks back over a user-defined period (the "Rperiod") and calculates a weighted sum. This means that prices closer to the present moment have a different influence on the final calculation than older prices, allowing the indicator to be more responsive to recent market activity while still maintaining a sense of broader trend history.
2. Trend Calculation The script performs a continuous loop through the price history. In each step, it calculates a weighted value based on the closing prices. This result is then normalized to produce a specific "weight" value. This value serves as the basis for the indicator line displayed on your chart.
3. Dynamic Color Signaling The most distinctive feature of this tool is its visual feedback system. It uses two different color layers (Red and Green) to signify the relationship between the calculated trend weight and the actual market price:
- Bullish Sentiment: When the calculated trend weight falls below the current market closing price, the tool emphasizes a specific visual state to indicate upward momentum.
- Bearish Sentiment: Conversely, when the calculated trend weight rises above the current market closing price, the tool switches the visual priority to indicate downward pressure.
Visual Summary
By monitoring these transitions on your chart, the tool aims to provide a clear, real-time visual cue of whether the market is currently trading above or below its weighted "fair value." It effectively filters out minor market noise to highlight the underlying direction of the price action, making it easier for users to identify whether the prevailing trend is moving in their favor.
/*-----------------------------+
| |
| 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_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern int Rperiod = 25;
extern int Draw4HowLongg = 300;
int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum[];
int length;
double lengthvar;
double tmp ;
double wt[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(4);
//---- drawing settings
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,sum);
SetIndexBuffer(3,wt);
SetIndexStyle(0,DRAW_LINE,1,3);
SetIndexStyle(1,DRAW_LINE,1,3);
//---- 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 ===========================================
ExtMapBuffer1[shift] = wt[shift]; //red
ExtMapBuffer2[shift] = wt[shift]; //green
if (wt[shift] > Close[shift])
ExtMapBuffer2[shift] = EMPTY_VALUE;
else
if (wt[shift] < Close[shift])
ExtMapBuffer1[shift] = EMPTY_VALUE;
}
return(0);
}
//+------------------------------------------------------------------+
Comments