zz_DT_ZZ_optimized

Download script
Author: Copyright � 2006, klot.
zz_DT_ZZ_optimized

This script is designed to identify and visualize significant structural turning points in a financial chart. It operates by analyzing price movement over a specific historical window to determine where "peaks" and "valleys" occur, helping traders see the broader flow of the market.

Core Logic Overview

The tool works by scanning the price history to find local highs and lows. Instead of marking every single minor price fluctuation, it uses a "depth" setting to look for more substantial price movements. It identifies significant points based on two primary conditions:

  • Price Reversals: It looks for moments where the market creates a new high or a new low relative to the most recent peak or valley.
  • Structural Filtering: When a new structural point is identified (like a new bottom), the script logic performs a "cleanup" of the previous area. It ensures that only the most prominent extreme points are kept on the chart, removing smaller, less relevant fluctuations that happen within that specific price swing.

How it Visualizes Data

The script processes the data and provides three distinct types of visual information:

  1. Trend Lines: It connects significant structural points to show the overall direction of the trend (e.g., connecting a series of lows to form an ascending line).
  2. High Markers: It places specific indicators at the "peaks" of price movements.
  3. Low Markers: It places specific indicators at the "valleys" of price movements.

Key Parameters

  • ExtDepth (Depth): This determines how far back the script looks to calculate what constitutes a "high" or a "low." A higher number means it will look for more significant, long-term structural points; a lower number makes it more sensitive to smaller, shorter-term movements.
  • CalculateLevel: This helps manage how many recent levels the script prioritizes when performing its calculations and visual updates.

Summary for the User

In simple terms, this script acts as an automated "trend mapper." It filters out the "noise" of minor price ticks and draws clear lines and markers on your chart to highlight where the market has truly shifted direction. By identifying these major structural highs and lows, it helps you see the underlying framework of the current market trend more clearly.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
zz_DT_ZZ_optimized
//+------------------------------------------------------------------+
//|                                                        DT_ZZ.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, klot."
#property link      "klot@mail.ru"
// optimized by Rosh

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Red
//---- indicator parameters
extern int ExtDepth=12;
extern int calculateLevel=2; 
//---- indicator buffers
double zzL[];
double zzH[];
double zz[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 //  IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);
   
   SetIndexArrow(1,159);
   SetIndexArrow(2,159);
   
//---- indicator buffers mapping
   SetIndexBuffer(0,zz);
   SetIndexBuffer(1,zzH);
   SetIndexBuffer(2,zzL);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
     
//---- indicator short name
   IndicatorShortName("DT_ZZ("+ExtDepth+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
   {
   int i,shift,pos,lasthighpos,lastlowpos,curhighpos,curlowpos;
   double curlow,curhigh,lasthigh,lastlow;
   double min, max;
   int counted_bars=IndicatorCounted();
   if (counted_bars==0)
      {
      ArrayInitialize(zz,0.0);
      ArrayInitialize(zzL,0.0);
      ArrayInitialize(zzH,0.0);
   
      lasthighpos=Bars; lastlowpos=Bars;
      lastlow=Low[Bars];lasthigh=High[Bars];
      Print("limit=",Bars-ExtDepth);
      for(shift=Bars-ExtDepth; shift>=0; shift--)
         {
         curlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,shift);
         curlow=Low[curlowpos];
         curhighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,shift);
         curhigh=High[curhighpos];
         //------------------------------------------------
         if( curlow>=lastlow ) { lastlow=curlow; }
         else
            { 
            //èäåì âíèç
            if( lasthighpos>curlowpos  ) 
               { 
               zzL[curlowpos]=curlow;
               ///*
               min=100000; pos=lasthighpos;
               for(i=lasthighpos; i>=curlowpos; i--)
                  { 
                    if (zzL[i]==0.0) continue;
                    if (zzL[i]<min) { min=zzL[i]; pos=i; }
                    zz[i]=0.0;
                  } 
               zz[pos]=min;
               //*/
               } 
            lastlowpos=curlowpos;
            lastlow=curlow; 
            }
         //--- high
         if( curhigh<=lasthigh )  { lasthigh=curhigh;}
         else
            {  
            // èäåì ââåðõ
            if( lastlowpos>curhighpos ) 
               {  
               zzH[curhighpos]=curhigh;
               ///*
                  max=-100000; pos=lastlowpos;
                  for(i=lastlowpos; i>=curhighpos; i--)
                     { 
                       if (zzH[i]==0.0) continue;
                       if (zzH[i]>max) { max=zzH[i]; pos=i; }
                       zz[i]=0.0;
                     } 
                  zz[pos]=max;
               //*/     
               }  
            lasthighpos=curhighpos;
            lasthigh=curhigh;    
            }       
         zz[0]=Close[0];
         }
       //----------------------------------------------------------------------
      }
   else
      {
      int pos2;
      i=0;
      while (pos2<calculateLevel && i<Bars-1)
         {
         if (zz[i]!=0 && (zzH[i]!=0||zzL[i]!=0)) pos2++;
         i++;
         }
      pos2=i-1;    
      for (i=pos2-1;i>=0;i--)
         {
         zzH[i]=0;
         zzL[i]=0;
         zz[i]=0;   
         }
      if (zzH[pos2]!=0) 
         {
         lasthighpos=pos2;
         lasthigh=High[pos2];
         lastlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,pos2);
         lastlow=Low[lastlowpos];
         }
      else
         {         
         lastlowpos=pos2;
         lastlow=Low[pos2];
         lasthighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,pos2);
         lasthigh=High[lasthighpos];
         }
      //------------------------- îïñ÷èòàåì çàíîâî   
      Print("limit=",pos2-1);
      for(shift=pos2-1; shift>=0; shift--)
         {
         curlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,shift);
         curlow=Low[curlowpos];
         curhighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,shift);
         curhigh=High[curhighpos];
         //------------------------------------------------
         if( curlow>=lastlow ) { lastlow=curlow; }
         else
            { 
            //èäåì âíèç
            if( lasthighpos>curlowpos  ) 
               { 
               zzL[curlowpos]=curlow;
               ///*
               min=100000; pos=lasthighpos;
               for(i=lasthighpos; i>=curlowpos; i--)
                  { 
                    if (zzL[i]==0.0) continue;
                    if (zzL[i]<min) { min=zzL[i]; pos=i; }
                    zz[i]=0.0;
                  } 
               zz[pos]=min;
               //*/
               } 
            lastlowpos=curlowpos;
            lastlow=curlow; 
            }
         //--- high
         if( curhigh<=lasthigh )  { lasthigh=curhigh;}
         else
            {  
            // èäåì ââåðõ
            if( lastlowpos>curhighpos ) 
               {  
               zzH[curhighpos]=curhigh;
               ///*
                  max=-100000; pos=lastlowpos;
                  for(i=lastlowpos; i>=curhighpos; i--)
                     { 
                       if (zzH[i]==0.0) continue;
                       if (zzH[i]>max) { max=zzH[i]; pos=i; }
                       zz[i]=0.0;
                     } 
                  zz[pos]=max;
               //*/     
               }  
            lasthighpos=curhighpos;
            lasthigh=curhigh;    
            }       

         }
      //------------------------- îïñ÷èòàåì çàíîâî         
      zz[0]=Close[0];   
      }
   return(0);
   }
//+------------------------------------------------------------------+

Comments