LSdemarker_in_Color
Download scriptThis tool is designed as a visual aid for traders using the MetaTrader platform. Its primary purpose is to analyze price movements by calculating a weighted momentum value based on historical data, then displaying this information through a series of colored lines in a separate window below the main chart.
Core Logic and Calculation
The script operates by looking back at a specific number of previous bars (defined by the "Rperiod" setting). Instead of simply looking at the most recent price, it performs a multi-layered calculation:
- Weighted Analysis: The tool evaluates price markers over the chosen period. It applies a specific mathematical weighting to these markers, meaning that data points are prioritized based on their position in time. This helps smooth out "noise" and highlights more significant trends.
- Summation & Scaling: It accumulates these weighted values into a total sum and then scales that sum down to a manageable figure. This creates a stabilized line that represents the current strength or direction of the market's momentum.
Visual Representation
The script communicates the results to the user through three distinct visual components:
- Trend Tracking: The calculated value is mapped onto three different buffers, which allows the tool to display colors dynamically based on whether the momentum is rising or falling.
- Dynamic Coloring: The logic compares the current calculated value against the previous one:
- When the momentum shifts in a specific direction, the script hides certain lines and highlights others.
- This creates a visual "flow," where different colors (Yellow, Chartreuse/Green, and Red) appear to switch as the market's strength fluctuates.
- Movement Identification: By observing which color is currently visible on the chart, a trader can quickly identify whether the underlying momentum of the asset is gaining strength or beginning to retreat.
In summary, this script transforms complex historical price data into a simplified, color-coded visual stream. It filters out minor price fluctuations to provide the user with a clearer picture of the prevailing market momentum.
//+------------------------------------------------------------------+
//| |
//| 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 3
#property indicator_color1 Yellow
#property indicator_color2 Chartreuse
#property indicator_color3 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;
extern int Rperiod = 50;
extern int BarProcessed = 1000;
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,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
//---- initialization done
return(0);
}
int start()
{
if (Bars < Rperiod+1) BarProcessed = Bars-Rperiod-1;
if (Bars < Rperiod+1) return;
if (BarProcessed ==0) BarProcessed = Bars-Rperiod-1;
length = Rperiod;
loopbegin = BarProcessed;
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)* iDeMarker(NULL,0,Rperiod,length-i+shift);
sum[1]+=tmp;
}
wt[shift] = sum[1]*6/(length*(length+1));
ExtMapBuffer3[shift] = wt[shift]; //red
ExtMapBuffer2[shift] = wt[shift]; //green
ExtMapBuffer1[shift] = wt[shift]; //yellow
if (wt[shift+1] > wt[shift])
{
ExtMapBuffer2[shift+1] = EMPTY_VALUE;
} else if (wt[shift+1] < wt[shift]) {
ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
} else {
ExtMapBuffer1[shift+1] = CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1] = CLR_NONE;//EMPTY_VALUE;
}
}
return(0);
}
Comments