Triggerlines Shift Modified
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform to help traders visualize specific price trends and potential entry points on a chart. It functions by calculating two distinct types of moving averages and overlaying them to identify momentum shifts.
Core Functionality
The script processes historical price data to generate two primary visual components:
- Weighted Momentum Line: The tool calculates a weighted average where specific price points are given different levels of importance based on their position in time. This helps smooth out "market noise" while remaining responsive to recent price action.
- Linear Smoothed Average (LSMA): The script then applies a linear smoothing calculation to that weighted data. This creates a secondary, even smoother line that represents the broader underlying trend of the market.
How it Works on Your Chart
Instead of showing every minor fluctuation in price, the script focuses on the relationship between these two calculated lines:
- Trend Identification: By plotting both the weighted momentum and the smoothed average, the tool allows you to see whether the current price movement is accelerating or decelerating relative to its recent history.
- Dynamic Filtering: The logic includes a specific filtering rule regarding visual output. The script is designed to "hide" certain data points based on their position relative to one another. Specifically, it evaluates whether the weighted value is currently below the smoothed average.
- Visual Clarity: When the conditions for a trend are met, the lines appear on your chart; when they are not, the script suppresses the visual output (leaving those areas empty). This helps traders ignore "messy" data and focus only on significant movements where the momentum aligns with the smoothed trend.
Summary for the User
Think of this tool as a filter for market volatility. It takes raw price data, weights it to emphasize relevant recent movement, and then smooths it out to show the "true" direction. By comparing these two smoothed results, it helps you identify clear trends while automatically filtering out irrelevant fluctuations, providing a cleaner visual path for your trading analysis.
//+------------------------------------------------------------------+
//| Triggerlines Shift Modified.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int width;
//----
extern int Rperiod=20;
extern int RperiodShift=0;
extern int LSMA_Period=20;
extern int LSMA_PeriodShift=0;
//----
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;
//----
double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 7 additional buffers are used for counting.
IndicatorBuffers(7);
//---- drawing settings
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexShift(0,LSMA_PeriodShift);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexShift(1,LSMA_PeriodShift);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexShift(2,RperiodShift);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexShift(3,RperiodShift);
SetIndexBuffer(4,sum);
SetIndexBuffer(5,wt);
SetIndexBuffer(6,lsma_ma);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{ Draw4HowLong=Bars-Rperiod - 5; //Rperiod = 20
length=Rperiod; //length now = 20
lsma_length=LSMA_Period;
loopbegin=Draw4HowLong - length - 1;
for(shift=loopbegin; shift>=0; shift--) // MAIN For Loop
{
sum[1]=0;
for(i=length; i>=1 ;i--) //LSMA loop
{
lengthvar=length + 1; //lengthvar = 21
lengthvar/=3; //lengthvar = 7
tmp=0;
tmp =(i - lengthvar)*Close[length-i+shift]; //tmp = 20 - 7 * close[20-i+shift]
sum[1]+=tmp;
}
wt[shift]=sum[1]*6/(length*(length+1));
j=shift;
lsma_ma[shift]=wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);
//========== COLOR CODING ===========================================
ExtMapBuffer1[shift]=wt[shift];
ExtMapBuffer2[shift]=lsma_ma[shift];
ExtMapBuffer3[shift]=wt[shift];
ExtMapBuffer4[shift]=lsma_ma[shift];
int Buffer1=ExtMapBuffer1[shift];
int Buffer2=ExtMapBuffer2[shift];
int Buffer3=ExtMapBuffer3[shift];
int Buffer4=ExtMapBuffer4[shift];
Print(ObjectGet(ExtMapBuffer1[shift],OBJPROP_COLOR));
if (wt[shift] < lsma_ma[shift])
{
ExtMapBuffer4[shift]=EMPTY_VALUE;
ExtMapBuffer3[shift]=EMPTY_VALUE;
}
}
}
//+------------------------------------------------------------------+
Comments