Time_Zone_Pivots_with_R3_and_S3

Download script
Author: Copyright � 2005, Denis Manigart
Time_Zone_Pivots_with_R3_and_S3

This tool is designed to automatically calculate and display key price levels—known as Pivot Points—on your trading chart. These levels are essential for identifying potential areas of support (where prices might stop falling) and resistance (where prices might struggle to rise further).

How the Logic Works

The script functions by analyzing historical price data to establish a mathematical framework for the current trading day. Here is the step-by-step breakdown of its logic:

1. Timezone Synchronization Because markets operate across different regions, the tool includes a specific setting to account for your local time offset. It uses this information to identify exactly when a new trading day begins (specifically looking for the 00:00 hour mark). This ensures that the calculations are synchronized correctly with your data feed.

2. Data Collection As the script moves through the price history, it constantly monitors three critical pieces of information from the previous completed trading day:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final price at which the day ended (Close)

3. Pivot Point Calculation Once a new day begins, the script captures these "Yesterday" values and performs a series of standardized calculations to project today's levels:

  • The Pivot Point: This is the central baseline for the day, calculated by taking the average of yesterday's High, Low, and Close.
  • Support and Resistance Levels (S1, S2, S3 and R1, R2, R3): The script uses the central Pivot Point and the previous day's boundaries to project three layers of support and resistance above and below the baseline.

4. Visual Display The tool then draws these levels as horizontal lines on your chart. By providing these pre-calculated marks, the script helps traders visualize where the market "memory" suggests price action might react, allowing for more informed decision-making regarding entries and exits.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Time_Zone_Pivots_with_R3_and_S3
//+------------------------------------------------------------------+
//|                                              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 Black
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Red
#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 PivotArray[];
double R1Array[];
double S1Array[];
double R2Array[];
double S2Array[];
double R3Array[];
double S3Array[];

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
	
	// Pivot
SetIndexStyle(0,DRAW_LINE,0,2);
SetIndexBuffer(0,PivotArray);
IndicatorShortName("TDPivot");
SetIndexLabel(0,"Pivot");
SetIndexEmptyValue(0, 0.0);
// Resistance 1
SetIndexStyle(1,DRAW_LINE,0,1);
SetIndexBuffer(1,R1Array);
SetIndexLabel(1,"R1");
SetIndexEmptyValue(1, 0.0);
// Support 1
SetIndexStyle(2,DRAW_LINE,0,1);
SetIndexBuffer(2,S1Array);
SetIndexLabel(2,"S1");
SetIndexEmptyValue(2, 0.0);
// Resistance 2
SetIndexStyle(3,DRAW_LINE,0,1);
SetIndexBuffer(3,R2Array);
SetIndexLabel(3,"R2");
SetIndexEmptyValue(3, 0.0);
// Support 2
SetIndexStyle(4,DRAW_LINE,0,1);
SetIndexBuffer(4,S2Array);
SetIndexLabel(4,"S2");
SetIndexEmptyValue(4, 0.0);
// Resistance 3
SetIndexStyle(5,DRAW_LINE,0,1);
SetIndexBuffer(5,R3Array);
SetIndexLabel(5,"R3");
SetIndexEmptyValue(5, 0.0);
// Support 3
SetIndexStyle(6,DRAW_LINE,0,1);
SetIndexBuffer(6,S3Array);
SetIndexLabel(6,"S3");
SetIndexEmptyValue(6, 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 Pivot;
double R1;
double S1;
double R2;
double S2;
double R3;
double S3;
	
	//---- 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
				
				Pivot = (yesterdayhigh + yesterdaylow + yesterdayclose)/3;
            R1 = (2*Pivot)-yesterdaylow;
            S1 = (2*Pivot)-yesterdayhigh;
            R2 = Pivot-S1+R1;
            S2 = Pivot-R1+S1;
            R3 = yesterdayhigh+2*(Pivot-yesterdaylow);
            S3 = yesterdaylow-2*(yesterdayhigh-Pivot);
				
				 }
				
				//These can be used for any calculations 
				TodayOpenBuffer[i] = todayopen;
				YesterdayCloseBuffer[i] = yesterdayclose;
				YesterdayHighBuffer[i] = yesterdayhigh;
				YesterdayLowBuffer[i] = yesterdaylow;
				
				
				
			   PivotArray[i]=Pivot;
            R1Array[i]=R1;
            S1Array[i]=S1;
            R2Array[i]=R2;
            S2Array[i]=S2;
            R3Array[i]=R3;
            S3Array[i]=S3;
			    

	}

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

Comments