several_ZZs

Download script
Author: Copyright � 2007, Mathemat
several_ZZs

This tool is designed to provide traders with a multi-layered perspective on market structure by synchronizing trend data from four different timeframes simultaneously onto a single chart. Instead of forcing you to switch back and forth between different windows to see the "big picture," this script aggregates and aligns various price movements into one unified visual display.

Core Functionality

The logic operates by pulling information from four specific market intervals: Hourly (H1), 4-Hour (H4), Daily (D1), and Weekly (W1). Each timeframe is represented on your chart with a unique color and line thickness, allowing you to distinguish between short-term fluctuations and long-term trends at a glance.

How the Logic Works

1. Timeframe Synchronization One of the primary challenges in trading is comparing different timeframes because their "bars" do not align perfectly (for example, one hour on a daily chart covers 24 hours). This script solves this by automatically calculating the correct chronological position for each timeframe. It ensures that when you look at a specific point in time, the data displayed for the Weekly or Daily trends corresponds exactly to that moment.

2. Hierarchical Trend Filtering The script employs a "top-down" logic to clean up the visual data. To prevent the chart from becoming cluttered with overlapping lines, it uses a conditional filtering system:

  • It checks the current status of the Hourly trend first.
  • It then evaluates the 4-Hour trend based on the Hourly status.
  • This pattern continues up to the Daily and Weekly levels.

3. Intelligent Smoothing (Data Suppression) The most important feature of this logic is its ability to hide unnecessary data. If a smaller timeframe (like the Hourly) shows a specific price movement that is already being captured or "satisfied" by a larger timeframe, the script suppresses the display of the smaller line. This ensures that the visual output remains clean and only highlights the most relevant structural peaks and valleys for each respective time period.

Visual Representation

To help you interpret the data quickly, the script uses a clear visual hierarchy:

  • Red (Thinnest Line): Represents the immediate Hourly price action.
  • Goldenrod: Tracks the 4-Hour trend.
  • Green: Highlights the Daily market structure.
  • Blue (Thickest Line): Illustrates the major Weekly trend.

By using this logic, you can see how minor hourly price "zigzags" fit into the broader context of the weekly trend, helping to identify whether a current move is a significant structural shift or just minor noise.

Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
several_ZZs
//+------------------------------------------------------------------+
//|                                                  several_ZZs.mq4 |
//|                                       Copyright © 2007, Mathemat |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Mathemat"
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_color1 Red         // H1
#property indicator_width1 2

#property indicator_color2 Goldenrod   // H4
#property indicator_width2 3

#property indicator_color3 Green       // D1
#property indicator_width3 4

#property indicator_color4 Blue        // W1
#property indicator_width4 5

//---- ZZ parameters
extern int _Depth = 12;
extern int _Dev = 5;
extern int _BStep = 3;

//---- indicator buffers
double H1[], H4[], D1[], W1[];


int init()
{
   IndicatorBuffers( 4 );

   for( int i = 0; i < 4; i++)   SetIndexStyle( i, DRAW_SECTION );
   
   SetIndexBuffer( 0, H1 );
   SetIndexBuffer( 1, H4 );
   SetIndexBuffer( 2, D1 );
   SetIndexBuffer( 3, W1 );
   
   for( i = 0; i < 4; i++ )      SetIndexEmptyValue( i, 0.0 );
  
   IndicatorShortName( "ZigZag(" + _Depth + "," + _Dev + "," + _BStep + ")" );
   
   return( 0 );
}

int deinit()
{
   return( 0 );
}

// êîíâåðòèðóåò áàðîâîå ñìåùåíèå, óêàçàííîå íà H1, â áàðîâîå íà áîëåå êðóïíîì ÒÔ
int convertShift( int sh, int toTF )
{
   datetime time = iTime( NULL, PERIOD_H1, sh );
   return( iBarShift( NULL, toTF, time, true ) );
}


double ZZ( int period, int shift )
{
   return( iCustom( NULL, period, "ZigZag_Rosh", 
                    _Depth, _Dev, _BStep, 
                    0, shift ) );
}


int start()
{
   int    counted_bars=IndicatorCounted();
   for( int shift = Bars - 1; shift >= 0; shift-- )
   {
      H1[ shift ] = ZZ( PERIOD_H1, shift );
   
      int shiftH4 = convertShift( shift, PERIOD_H4 );
      int shiftD1 = convertShift( shift, PERIOD_D1 );
      int shiftW1 = convertShift( shift, PERIOD_W1 );
      
      bool condition1 = ( ZZ( PERIOD_H1, shift )   < 0.01 );
      bool condition2 = ( ZZ( PERIOD_H4, shiftH4 ) < 0.01 ) || condition1;
      bool condition3 = ( ZZ( PERIOD_D1, shiftD1 ) < 0.01 ) || condition2;
      
      
      if ( condition1 )  H4[ shift ] = 0.0;
      else               H4[ shift ] = ZZ( PERIOD_H4, shiftH4 );
            
      if ( condition2 )  D1[ shift ] = 0.0;
      else               D1[ shift ] = ZZ( PERIOD_D1, shiftD1 );
            
      if ( condition3 )  W1[ shift ] = 0.0;
      else               W1[ shift ] = ZZ( PERIOD_W1, shiftW1 );
   }   
   return( 0 );
}

Comments