#MTF_zlagMACD_v2
Download scriptThis technical script is designed to provide traders with a specialized visual aid for analyzing market momentum and trends. It functions as a "Multi-Timeframe Zero-Lag MACD" indicator, which combines several complex trading concepts into a single visual display.
Here is a breakdown of how the logic works in plain English:
Multi-Timeframe Analysis
The primary strength of this script is its ability to "look ahead" at different time horizons simultaneously. While you are viewing your current chart (for example, a 5-minute chart), this tool can automatically pull and display data from much larger timeframes, such as the Hourly or Daily charts. This allows you to see the "big picture" trend without having to constantly switch back and forth between different windows.
Zero-Lag Momentum Tracking
Standard technical indicators often suffer from "lag," meaning they tell you what happened in the past rather than what is happening now. This script utilizes a "Zero-Lag" logic, which is specifically designed to smooth out price fluctuations while keeping the data as close to real-time as possible. It aims to identify changes in momentum more quickly than traditional methods.
Dynamic Scaling and Visualization
To make the data easier for human eyes to interpret, the script includes a specific scaling logic:
- Visual Enhancement: It uses a multiplier to enlarge the lines on your screen. This ensures that even subtle movements in the market are clearly visible and not lost as tiny flickers on the chart.
- Simplified Interface: The script cleans up the visual workspace by removing unnecessary labels and extra data points, focusing solely on the two primary trend lines.
Core Processing Logic
The script operates by following a specific sequence:
- Time Synchronization: It maps the time coordinates of the larger timeframe onto your current chart so that the data aligns perfectly with the candles you are seeing.
- Data Fetching: It calls upon the "Zero-Lag MACD" calculation for every historical bar on your chart.
- Coordinate Matching: It ensures that even if the timeframes differ significantly, the data points stay synchronized, allowing you to see a continuous, unbroken trend line across your current view.
In summary, this tool acts as a "bridge," bringing high-level market trends from larger timeframes into your immediate workspace, processed through a formula designed to reduce delay and maximize visual clarity.
//+------------------------------------------------------------------+
//| #MTF_zlagMACD_v2.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Keris2112"
#property link "http://www.forex-tsd.com"
#property link "HOH CHEE YEN"
// Raise "Multiplier" to enlarge its lines (HCY)
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Orange
#property indicator_level1 0
// Added (HCY)
#property indicator_width1 1
#property indicator_style2 2
// Set window range for proper line display (HCY)
#property indicator_maximum 1
#property indicator_minimum -1
//---- input parameters
/* Settings for different periods (Own preferences): (HCY)
MN,WK,D1:22,11,8 -- D1:11,22,8
WK,D1,H4:30,13,10 -- H4:13,30,10
D1,H4,H1:24,11,8 -- H1:11,24,8
H4,H1,M15:15,7,5 -- M15:7,15,5
H1,M15,M5:12(or 13),6,4 -- M5:6,12,4
M15,M5,M1:15,7,5 -- M1:7,15,5
*/
extern int TimeFrame=0;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
// For proper line display - raise this number to enlarge its lines (HCY)
extern double Multiplier=2;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//---- input parameters
/*************************************************************************
PERIOD_M1 1
PERIOD_M5 5
PERIOD_M15 15
PERIOD_M30 30
PERIOD_H1 60
PERIOD_H4 240
PERIOD_D1 1440
PERIOD_W1 10080
PERIOD_MN1 43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
**************************************************************************/
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
// SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID,1);
// SetIndexStyle(1,DRAW_SECTION,STYLE_SOLID,1);
// Draw lines only (HCY)
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
/* Original settings (HCY)
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2);
SetIndexStyle(1,DRAW_LINE,EMPTY,2);
*/
SetIndexDrawBegin(0,SlowEMA);
SetIndexDrawBegin(1,SlowEMA);
// No value displayed at left corner (HCY)
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
/* Original settings (HCY)
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
*/
// Show only 2 decimal points (HCY)
IndicatorDigits(2);
//---- name for DataWindow and indicator subwindow label
int TF=TimeFrame;
if (TimeFrame==0) TF=Period();
switch(TF)
{
case 1 : string TimeFrameStr="M1"; break;
case 5 : TimeFrameStr="M5"; break;
case 15 : TimeFrameStr="M15"; break;
case 30 : TimeFrameStr="M30"; break;
case 60 : TimeFrameStr="H1"; break;
case 240 : TimeFrameStr="H4"; break;
case 1440 : TimeFrameStr="D1"; break;
case 10080 : TimeFrameStr="W1"; break;
case 43200 : TimeFrameStr="MN1"; break;
default : TimeFrameStr="CUR";
}
// Set shorter indicator name (HCY)
// short_name="MzM";
// Show only TimeFrame (HCY)
IndicatorShortName(TimeFrameStr);
/* Original settings (HCY)
short_name="MTF ZeroLag MACD";
IndicatorShortName(short_name+ " " + TimeFrameStr+ " | " +FastEMA + ", " + SlowEMA + ", " + SignalEMA+" | ");
*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| MTF Moving Average |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
// Plot defined timeframe on to current timeframe
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
// Modified (HCY)
limit=Bars-counted_bars+TimeFrame/Period();
// limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
/***********************************************************
Add your main indicator loop below. You can reference an existing
indicator with its iName or iCustom.
Rule 1: Add extern inputs above for all neccesary values
Rule 2: Use 'TimeFrame' for the indicator timeframe
Rule 3: Use 'y' for the indicator's shift value
**********************************************************/
// For proper line display (HCY)
ExtMapBuffer1[i]=(iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,0,y)*Multiplier);
ExtMapBuffer2[i]=(iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,1,y)*Multiplier);
/* Original (HCY)
ExtMapBuffer1[i]=iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,0,y);
ExtMapBuffer2[i]=iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,1,y);
*/
}
/* Disabled (HCY)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (TimeFrame>Period()) {
int PerINT=TimeFrame/Period()+1;
datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period());
for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
//----
/************************************************ by Raff
Refresh buffers: buffer[i] = buffer[0];
********************************************************/
/* Disabled (HCY)
ExtMapBuffer1[i]=ExtMapBuffer1[0];
ExtMapBuffer2[i]=ExtMapBuffer2[0];
//----
} } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
return(0);
}
//+------------------------------------------------------------------+
Comments