DT-ZZ-M1
Download scriptThis script is a specialized technical analysis tool designed to help traders identify significant market trend reversals by monitoring price movement relative to a smoothed "ZigZag" structure. Instead of cluttering the main price chart, it operates in a separate sub-window, providing clear visual signals and automated alerts when the market's momentum shifts from one direction to another.
Core Logic Overview
The tool functions by analyzing historical price data through a multi-layered filtering process:
- Trend Smoothing: It utilizes an underlying "ZigZag" logic—a standard technical method used to filter out minor market noise and highlight significant highs and lows. By using a specific "depth" setting, the script ensures that only substantial price movements are considered meaningful for analysis.
- Timeframe Alignment: The script performs a time-syncing operation. It looks at higher-level periods (the "Gross Period") to establish a broader market context, ensuring that the signals it generates are consistent with the larger trend rather than just momentary fluctuations on the smallest timeframe.
- Dynamic Comparison: For every price candle on your chart, the script actively searches backward through recent history to find the most relevant ZigZag turning point. It then compares the current closing price against this significant level.
Signal Generation and Visuals
The indicator translates these complex comparisons into two simple visual states:
- Upward Momentum (Blue): When the closing price remains above a primary structural high, the script identifies this as bullish momentum.
- Downward Momentum (Red): When the closing price falls below a primary structural low, the script identifies this as bearish momentum.
Automated Alerts
Beyond just visual cues, the script includes an active notification system. It monitors for "state changes"—the exact moment the price crosses from one side of the structural level to the other. When the market switches from an upward bias to a downward bias (or vice versa), the script triggers a real-time alert on your platform. This allows traders to react immediately to trend shifts without having to constantly watch the screen, providing a proactive way to manage entries and exits.
//+------------------------------------------------------------------+
//| DT-ZigZag-Lauer.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, klot"
#property link "klot@mail.ru"
//----
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 2
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 4
#property indicator_width2 4
//---- input parameters
extern int depth=50;//was 5
extern int GrossPeriod=5;//was 15
extern int MAX_Limit=300;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
datetime daytimes[];
double alertBar;
double prev;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
string short_name;
//---- name for DataWindow and indicator subwindow label
short_name="MY(" + depth + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
IndicatorDigits(0);
//----
SetIndexStyle(0,DRAW_HISTOGRAM, STYLE_SOLID);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_HISTOGRAM, STYLE_SOLID);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
//----
//----
// if (Period()>GrossPeriod) { Alert("DT-ZigZag: Current timeframe must be less than", GrossPeriod); return(0); }
// All Time[ ] series of time is sorted out in the direction of the decrease
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),GrossPeriod);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit=MAX_Limit,bigshift;
double zigzag1;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i=0; i<limit; i++)
{
if(Time[i]>=daytimes[0]) bigshift=0;
else
{
bigshift=ArrayBsearch(daytimes,Time[i-1],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<=GrossPeriod) bigshift++;
}
for(int cnt=bigshift; cnt<(300+bigshift); cnt++)
{
zigzag1=iCustom(NULL,GrossPeriod,"Zigzag",depth,15,9,0,cnt+1);
if(zigzag1!=0)break;
}
if(iClose(NULL,0,i+1)<=zigzag1)ExtMapBuffer2[i]=1; else ExtMapBuffer2[i]=0.0;
if(i==0 && prev != ExtMapBuffer2[i] && ExtMapBuffer1[i] == 1 && ExtMapBuffer2[i] == 0 && Bars>alertBar) {Alert("DT-ZZ Alert changing Up " + Symbol() + " on the " + Period() + " minute chart.");alertBar = Bars;prev = ExtMapBuffer2[i];}
if(iClose(NULL,0,i+1)>=zigzag1)ExtMapBuffer1[i]=1; else ExtMapBuffer1[i]=0.0;
if(i==0 && prev != ExtMapBuffer2[i] && ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 1 && Bars>alertBar) {Alert("DT-ZZ Alert changing Down " + Symbol() + " on the " + Period() + " minute chart.");alertBar = Bars;prev = ExtMapBuffer2[i];}
ObjectsRedraw();
}
// Comment("zigzag1 = ",zigzag1);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments