HedgeTest_v1

Download script
Author: Copyright � 2005
HedgeTest_v1

This script is designed as a technical analysis tool for the MetaTrader platform. It automatically calculates and visualizes specific price levels—known as "Pivot Points"—which traders use to identify potential support and resistance zones in the financial markets.

Core Functionality

The primary purpose of this tool is to provide a visual roadmap of where the market might encounter difficulty moving higher (resistance) or falling lower (support). It achieves this by analyzing historical price data from previous trading sessions and projecting those levels onto your current chart.

How the Logic Works

The script follows a systematic process to generate these levels:

  • Data Collection: The tool monitors the "High," "Low," and "Close" prices of the preceding trading day. It specifically looks for the moment a new day begins (based on a user-defined time zone) to capture the final data points of the previous session.
  • Pivot Point Calculation: At the start of each new day, the script calculates a central "Pivot" point. This is derived by taking the average of three key values: the previous day's high, the previous day's low, and the previous day's closing price.
  • Support and Resistance Projection: Using that central Pivot point, the script then calculates four additional levels:
    • Resistance Levels (R1, R2): These represent areas where the price may face selling pressure or "ceiling" effects.
    • Support Levels (S1, S2): These represent areas where the price may find a "floor" and struggle to drop further.
  • Dynamic Tracking: As new bars form on your chart, the script continuously updates these levels so you can see exactly where the current price sits in relation to the day's established boundaries.

Key Visual Features

In addition to the standard Pivot levels, the indicator provides several auxiliary data points to help with manual analysis:

  • Today’s Opening Price: Clearly marks where the current trading day started.
  • Reference Targets: It plots specific lines representing the previous day's close, modified by a customizable "Offset" (the distance in pips). This allows traders to set custom target zones relative to the closing price of the previous session.

Summary for the User

Essentially, this script removes the need for manual math. Instead of you having to calculate the averages and ranges of yesterday's trading manually, the tool automatically draws these "boundaries" on your screen. It helps you visualize the "playing field" for the day, showing you where historical price action suggests the market might pause, reverse, or break through.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
HedgeTest_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                              TimeZone Pivots.mq4 |
//|                                 Copyright © 2005,|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8

#property indicator_color1 DarkOrange
#property indicator_color2 Khaki
#property indicator_color3 Khaki
#property indicator_color4 Khaki
#property indicator_color5 Khaki


#property indicator_color6 DarkViolet
#property indicator_color7 Blue
#property indicator_color8 Red
//#property indicator_color4 Gray

//---- input parameters
extern int Offset=14; // Number of pips above/below days open price
extern int TimeZoneOfData=0; // by default if time zone of data is at GMT 0
                             

//---- 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);
SetIndexBuffer(0,PivotArray);
IndicatorShortName("TDPivot");
SetIndexLabel(0,"Pivot");
SetIndexEmptyValue(0, 0.0);
// Resistance 1
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,R1Array);
SetIndexLabel(1,"R1");
SetIndexEmptyValue(1, 0.0);
// Support 1
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,S1Array);
SetIndexLabel(2,"R1");
SetIndexEmptyValue(2, 0.0);
// Resistance 2
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,R2Array);
SetIndexLabel(3,"R2");
SetIndexEmptyValue(3, 0.0);
// Support 2
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,S2Array);
SetIndexLabel(4,"S2");
SetIndexEmptyValue(4, 0.0);

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

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

// Daily High	
SetIndexStyle(6, DRAW_LINE);
SetIndexBuffer(6, YesterdayHighBuffer);
SetIndexLabel(6, "Low Target");
SetIndexEmptyValue(6, 0.0);	
	
// Daily Low	
SetIndexStyle(7, DRAW_LINE);
SetIndexBuffer(7, YesterdayLowBuffer);
SetIndexLabel(7, "High Target");
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;
	
	//---- 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;
				
				 }
				
				//These can be used for any calculations 
				TodayOpenBuffer[i] = todayopen;
				YesterdayHighBuffer[i] = yesterdayclose-(Offset*Point);
				YesterdayLowBuffer[i] = yesterdayclose+(Offset*Point);				

	}

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

Comments