Triggerlines Shift Modified_v2
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform, specifically used to visualize market trends and potential momentum shifts. It functions by calculating two distinct types of moving averages and plotting them on your price chart to help identify specific trading conditions.
Core Logic and Functionality
1. Dual Moving Average Calculation The script processes historical price data (specifically the closing prices) to generate two different types of indicators:
- A Weighted Trend Line: This is a specialized moving average that assigns different levels of importance to different pieces of data within its period. Unlike a standard average, it prioritizes specific data points to create a more responsive line that follows price action more closely.
- A Linear Smoothed Average: The script also calculates a secondary, smoother moving average. This serves as a "baseline" to filter out minor market noise and provide a clearer view of the broader trend.
2. Data Smoothing and Calculation To ensure the lines are useful for analysis, the script performs a multi-step mathematical process:
- It looks back at a defined number of historical bars (controlled by the "Period" settings).
- It calculates a weighted sum of these prices.
- It applies a smoothing formula to the result to produce the final values displayed on your screen.
3. Visual Filtering and Color Coding One of the primary features of this script is its ability to "hide" information based on market conditions to provide cleaner visual signals:
- The tool identifies the relationship between the weighted trend line and the smoothed average.
- Active Signals: When the primary trend line is above the smoothed average, it remains visible on your chart.
- Filtered Out: If the weighted trend line falls below the smoothed average, the script automatically hides those specific data points (marking them as "Empty").
Summary for the Trader
Essentially, this tool acts as a visual filter. It highlights moments where the short-term momentum is trending higher than the long-term average. By suppressing the lines when they fall below the baseline, it helps the user focus on specific price movements and reduces the "clutter" on the trading chart, making it easier to spot potential trends at a glance.
//+------------------------------------------------------------------+
//| 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];
if (wt[shift] < lsma_ma[shift])
{
ExtMapBuffer4[shift]=EMPTY_VALUE;
ExtMapBuffer3[shift]=EMPTY_VALUE;
}
}
}
//+------------------------------------------------------------------+
Comments