Time_Zone_Pivots_midpoints

Download script
Author: Copyright � 2005, Denis Manigart
Time_Zone_Pivots_midpoints

Overview

The TimeZone Pivots indicator is designed to provide traders with a structured set of support and resistance levels based on daily price action. By automatically calculating specific mathematical "Pivot Points," it helps identify key price zones where the market might experience a shift in trend, a reversal, or a consolidation period.

Core Logic & Functionality

The script operates by analyzing historical price data—specifically the High, Low, and Close prices from the previous trading session—to project several levels for the current day.

1. Timezone Awareness One of the key features of this script is its ability to synchronize with specific global time zones. By adjusting the "TimeZoneOfData" input, the user can ensure that the indicator identifies the start of a new day correctly based on their preferred market's local time (e.g., GMT offsets). This ensures the calculation begins exactly when the market cycle resets for that specific region.

2. Dynamic Tracking As the script moves through the price history, it constantly monitors the highest and lowest prices reached during a trading session. When it detects the exact moment a new day begins (based on the user-defined timezone), it captures:

  • The opening price of the current day.
  • The closing price of the previous day.
  • The highest point reached yesterday.
  • The lowest point reached yesterday.

3. Pivot Point Calculations Once the script identifies the end of a trading day, it uses those four primary data points (Yesterday's High, Low, Close, and today's Open) to generate six distinct pivot levels:

  • M0 & M5: These represent "extreme" pivots, calculated using heavier weights on the previous day's low and high respectively.
  • M1 & M4: These are intermediate pivots that balance the high and low values against the closing price.
  • M2 & M3: These are central pivot points, essentially finding the mid-points between the previous day's extremes and the closing price.

How it appears on your chart

The indicator plots these six levels as lines on your trading screen. Instead of being static, these levels update automatically at the start of every new day. This provides a "roadmap" of the current day's expected range, allowing traders to see where the market has historically found balance and where it might face resistance or find support based on the previous day's momentum.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Time_Zone_Pivots_midpoints
//+------------------------------------------------------------------+
//|                                              TimeZone Pivots.mq4 |
//|                                 Copyright © 2005, Denis Manigart |
//|                                     mailto:emaildomino@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Denis Manigart"
#property link      "mailto:emaildomino@gmail.com"

#property indicator_chart_window
#property indicator_buffers 8

#property indicator_color1 Olive
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Olive
#property indicator_color7 Olive
#property indicator_color8 Red
//#property indicator_color4 Gray

//---- input parameters
extern int TimeZoneOfData=5; // by default if time zone of data is at GMT +5
                             // This gives you the Pivot calculations for 0 GMT

//---- buffers
double M0Array[];
double M1Array[];
double M2Array[];
double M3Array[];
double M4Array[];
double M5Array[];

double TodayOpenBuffer[];
double YesterdayCloseBuffer[];
double YesterdayHighBuffer[];
double YesterdayLowBuffer[];


//---- variables
int indexbegin = 0;
double todayopen = 0;
double yesterdayclose = 0;

double barhigh = 0;
double dayhigh = 0;
double yesterdayhigh = 0;

double barlow = 0;
double daylow = 0;
double yesterdaylow = 0;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
	
	// M0
SetIndexStyle(0,DRAW_LINE,2);
SetIndexBuffer(0,M0Array);
IndicatorShortName("TDmidPivot");
SetIndexLabel(0,"MO");
SetIndexEmptyValue(0, 0.0);
// M1
SetIndexStyle(1,DRAW_LINE,2);
SetIndexBuffer(1,M1Array);
SetIndexLabel(1,"M1");
SetIndexEmptyValue(1, 0.0);
// M2
SetIndexStyle(2,DRAW_LINE,2);
SetIndexBuffer(2,M2Array);
SetIndexLabel(2,"M2");
SetIndexEmptyValue(2, 0.0);
// M3
SetIndexStyle(3,DRAW_LINE,2);
SetIndexBuffer(3,M3Array);
SetIndexLabel(3,"M3");
SetIndexEmptyValue(3, 0.0);
// M4
SetIndexStyle(4,DRAW_LINE,2);
SetIndexBuffer(4,M4Array);
SetIndexLabel(4,"M4");
SetIndexEmptyValue(4, 0.0);
// M5
SetIndexStyle(5,DRAW_LINE,2);
SetIndexBuffer(5,M5Array);
SetIndexLabel(5,"M5");
SetIndexEmptyValue(5, 0.0);


// You may also display the previous day close - high - low

// Daily Close	
//	SetIndexStyle(5, DRAW_LINE);
//	SetIndexBuffer(5, YesterdayCloseBuffer);
//	SetIndexLabel(5, "Daily Close");
//	SetIndexEmptyValue(5, 0.0);

// Daily High	
//	SetIndexStyle(6, DRAW_LINE);
//	SetIndexBuffer(6, YesterdayHighBuffer);
//	SetIndexLabel(6, "YesterDay High");
//	SetIndexEmptyValue(6, 0.0);	
	
// Daily Low	
//	SetIndexStyle(7, DRAW_LINE);
//	SetIndexBuffer(7, YesterdayLowBuffer);
//	SetIndexLabel(7, "YesterDay Low");
//	SetIndexEmptyValue(7, 0.0);
	

//----
	indexbegin = Bars - 20;
	if (indexbegin < 0)
		indexbegin = 0;
return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;
  
	int counted_bars = IndicatorCounted();
	
	
double M0;
double M1;
double M2;
double M3;
double M4;
double M5;
	
	//---- check for possible errors
	if (counted_bars < 0) counted_bars = 0;
	//---- last counted bar will be recounted
	if (counted_bars > 0) counted_bars--;
	if (counted_bars > indexbegin) counted_bars = indexbegin;


		for (i = indexbegin-counted_bars; i >= 0; i--)
		{ 
		
		   if ( i == indexbegin-counted_bars) 
		       {
		        dayhigh = High[i];
		        daylow = Low[i];
		       }
		       
		       barlow = Low[i];	
				 barhigh = High[i];
				 
			if ( barhigh >= dayhigh) 
			    dayhigh = barhigh;	 		
			
			if ( barlow <= daylow) 
			    daylow = barlow;
		
//Cycle through all the bars and fill the indicator bars with the Pivot point values		   
		
			if ((TimeMinute(Time[i]) == 00) && (TimeHour(Time[i]) - TimeZoneOfData == 00))
				{todayopen = Open[i];
				 yesterdayclose = Close[i+1];
				 yesterdaylow = daylow;
				 daylow = Low [i]; // input new day value
				
				 yesterdayhigh = dayhigh;
				 dayhigh = High [i]; // input new day value
				
				M0 = (3*yesterdaylow-2*yesterdayhigh+yesterdayclose)/2;
				M1 = (2*yesterdaylow-yesterdayhigh+yesterdayclose)/2;
				M2 = (yesterdaylow+yesterdayclose)/2;
				M3 = (yesterdayhigh+yesterdayclose)/2;
				M4 = (2*yesterdayhigh-yesterdaylow+yesterdayclose)/2;
				M5 = (3*yesterdayhigh-2*yesterdaylow+yesterdayclose)/2;
				
				
				 }
				
				//These can be used for any calculations 
				TodayOpenBuffer[i] = todayopen;
				YesterdayCloseBuffer[i] = yesterdayclose;
				YesterdayHighBuffer[i] = yesterdayhigh;
				YesterdayLowBuffer[i] = yesterdaylow;
				
				
				
			   M0Array[i]=M0;
            M1Array[i]=M1;
            M2Array[i]=M2;
            M3Array[i]=M3;
            M4Array[i]=M4;
            M5Array[i]=M5;
            			    

	}

	
	return(0);
}
//+------------------------------------------------------------------+

Comments