DT-ZigZag-ATR_v3

Download script
Author: Copyright � 2005, klot

This script is designed to enhance your trading charts by automatically identifying and plotting specific price levels based on two primary market factors: significant trend reversals and current market volatility.

Core Logic Overview

The tool functions by layering three distinct pieces of information to determine where to place visual markers on your chart:

1. Trend Identification (The ZigZag Basis) The script looks back at historical price data to identify major "peaks" and "troughs." It uses a standard ZigZag methodology, which filters out minor price fluctuations to focus only on the significant structural shifts in the market. This ensures that the markers are tied to meaningful movements rather than random noise.

2. Volatility Measurement (The ATR Component) To ensure that the markers are relevant to current market conditions, the script incorporates the Average True Range (ATR). Because markets move differently depending on whether they are calm or volatile, the ATR acts as a "ruler" that measures how much price is moving on average. This allows the tool to adjust its distance from the price dynamically.

3. Dynamic Marker Placement Once the script identifies a major peak or trough (via the ZigZag) and calculates the current volatility (via the ATR), it places markers on your chart based on the following logic:

  • Resistance Markers: When the script detects a significant peak, it projects a marker slightly above that price. The exact distance of this projection is determined by multiplying the current volatility by a user-defined multiplier.
  • Support Markers: When the script detects a significant trough, it projects a marker slightly below that price, again using the volatility calculation to determine the offset.

How It Benefits the User

By combining trend structure with real-time volatility, this script provides a more "intelligent" visual aid than a standard fixed-distance indicator. Instead of placing markers at a rigid distance from every high and low, it places them in a way that respects the current "breathing room" of the market. This helps traders visualize potential support and resistance zones that are mathematically adjusted to the intensity of the prevailing market environment.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
DT-ZigZag-ATR_v3
//+------------------------------------------------------------------+ 
//| DT-ZigZag-ATR.mq4                                                | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2005, klot"
#property link "klot@mail.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters 
extern int depth=12;
extern int perATR=12;
extern double k=2;
//---- buffers 
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init()
  {
//---- indicators 
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexArrow(1,159);
//---- 
   return(0);
  }
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit()
  {
//---- 

//---- 
   return(0);
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   double zigzag1,atr1;
//---- 
   // if (counted_bars<0) return(-1); 
   if (counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit--;
   for(int i=limit; i>0; i--)
     {
      for(int cnt=i; cnt<(100+i); cnt++)
        {
         zigzag1=iCustom(NULL,0,"ZigZag",depth,5,3,0,cnt+1);
         if(zigzag1!=0)break;
        }
      atr1=iATR(NULL,0,perATR,i);
      if(iHigh(NULL,0,i+1)<=zigzag1)ExtMapBuffer2[i]=iLow(NULL,0,i)+k*atr1; else ExtMapBuffer2[i]=0.0;
      if(iLow(NULL,0,i+1)>=zigzag1)ExtMapBuffer1[i]=iHigh(NULL,0,i)-k*atr1; else ExtMapBuffer1[i]=0.0;
     }
   Comment ("zigzag1 = ",zigzag1," limit = ",limit );
//---- 
   return(0);
  }
//+------------------------------------------------------------------+

Comments