Opening_Range_MTF

Download script
Author: � Kris
Opening_Range_MTF

The Opening Range Multi-Timeframe indicator is designed to provide traders with visual clarity regarding market volatility and potential price targets during the start of a new trading hour. It works by identifying the "Opening Range" (the high and low price action) over a specific period at the beginning of each hour and projecting where price might travel based on those boundaries.

Core Logic and Functionality

1. Timeframe Filtering The script is specifically optimized for fast-paced trading. It operates most effectively on lower timeframes (specifically 1-minute, 5-minute, and 15-minute charts). If a user attempts to view it on higher timeframes (like hourly or daily), the indicator will remain inactive to ensure data accuracy.

2. Dynamic Data Adjustment To ensure consistency across different speeds of trading, the tool automatically adjusts its "look-back" period based on your chart's timeframe. For example, it analyzes a different amount of historical bars on a 1-minute chart compared to a 15-minute chart. This ensures that regardless of the view, the indicator is capturing the same relative "opening" momentum.

3. Opening Range Identification At the start of every new hour, the script scans the preceding price action to identify two critical values:

  • Opening Range High: The peak price reached during the initial movement.
  • Opening Range Low: The lowest price reached during the initial movement.

4. Signal and Target Projection Once the high and low of the opening range are established, the tool calculates several projected levels for both upward (Buy) and downward (Sell) movements:

  • Breakout Signals: It establishes a "Signal" line slightly beyond the opening high and low. This acts as a confirmation zone; if the price breaks these points, it suggests a potential trend shift.
  • Profit Targets: From those signal points, the script projects two distinct target levels (Target 1 and Target 2). These are based on predefined distances that represent potential profit-taking zones or areas of expected exhaustion.

Visual Representation

The indicator simplifies complex calculations into easy-to-read visual cues directly on your chart:

  • Arrows/Markers: It places specific markers to highlight the Buy Signals, Sell Signals, and the various Target levels.
  • Color Coding: Different colors are used to distinguish between "Buy" objectives (shades of blue/cyan) and "Sell" objectives (shades of red/orange), allowing for a quick glance at market opportunities.
  • Dynamic Updates: As new prices form, the labels update automatically to show the current projected targets relative to the most recent opening range.

Summary for the Trader

In short, this tool automates the process of "marking the map." Instead of manually calculating where the high and low were at the start of the hour and guessing where the price might go next, the script identifies those boundaries automatically and draws your potential entry signals and profit targets on the screen in real-time.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
Opening_Range_MTF
//+------------------------------------------------------------------+
//|                                            Opening_Range_MTF.mq4 |
//|                         Copyright © 2008, kris.pivo[at]gmail.com |
//|                                                      16 Nov 2008 |
//+------------------------------------------------------------------+
#property copyright "© Kris"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 C'000,100,000'    // Buy Target 2
#property indicator_color2 C'000,150,000'    // Buy Target 1
#property indicator_color3 C'000,200,000'    // Buy Signal
#property indicator_color4 C'100,100,100'    // Opening Range High
#property indicator_color5 C'100,100,100'    // Opening Range Low
#property indicator_color6 C'200,000,000'    // Sell Signal
#property indicator_color7 C'150,000,000'    // Sell Target 1
#property indicator_color8 C'100,000,000'    // Sell Target 2
//---- Parameters
extern int SigConfirm =  4;
extern int TargetOne  = 25;
extern int TargetTwo  = 50;
//---- variables
int DataPeriod;
int LookBackTF;
//---- buffers
double OpenH1[];  // Buy Target 2
double OpenH2[];  // Buy Target 1
double OpenHS[];  // Buy Signal
double OpenHi[];  // Opening Range High
double OpenLo[];  // Opening Range Low
double OpenLS[];  // Sell Signal
double OpenL1[];  // Sell Target 1
double OpenL2[];  // Sell Target 2
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
	//---- indicators
	SetIndexStyle(0,DRAW_ARROW);
	SetIndexArrow(0,160);
	SetIndexBuffer(0,OpenH2);
	
	SetIndexStyle(1,DRAW_ARROW);
	SetIndexArrow(1,160);
	SetIndexBuffer(1,OpenH1);
	
	SetIndexStyle(2,DRAW_ARROW);
	SetIndexArrow(2,167);
	SetIndexBuffer(2,OpenHS);
	
	SetIndexStyle(3,DRAW_ARROW);
	SetIndexArrow(3,160);
	SetIndexBuffer(3,OpenHi);
	
	SetIndexStyle(4,DRAW_ARROW);
	SetIndexArrow(4,160);
	SetIndexBuffer(4,OpenLo);
	
	SetIndexStyle(5,DRAW_ARROW);
	SetIndexArrow(5,167);
	SetIndexBuffer(5,OpenLS);
	
	SetIndexStyle(6,DRAW_ARROW);
	SetIndexArrow(6,160);
	SetIndexBuffer(6,OpenL1);
	
	SetIndexStyle(7,DRAW_ARROW);
	SetIndexArrow(7,160);
	SetIndexBuffer(7,OpenL2);
	
   switch(Period())
      {
      case PERIOD_M1:  DataPeriod = 5;  LookBackTF = 5; break;
      case PERIOD_M5:  DataPeriod = 15; LookBackTF = 3; break;
      case PERIOD_M15: DataPeriod = 30; LookBackTF = 2; break;
      }

	string short_name = "Opening Range";
	IndicatorShortName(short_name);
	return(1);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
	ObjectDelete("OR-H2");
	ObjectDelete("OR-H1");
	ObjectDelete("OR-HS");
	ObjectDelete("OR-LS");
	ObjectDelete("OR-L1");
	ObjectDelete("OR-L2");
	Comment(""); 
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

double prevL=0, prevH=0, prevC=0, prevO=0;
double ORHS, ORHi, ORLo, ORLS;
double ORH1, ORH2, ORL1, ORL2;
int thisHour = -1;

int start() {
	if (Period() > 15) return(0);		//Chart cannot be higher than M15
	
	int counted_bars=IndicatorCounted();
	if (counted_bars >0) counted_bars--;
	int limit=Bars-counted_bars;
	int period = MathCeil(60 / Period());

	for (int i = limit-1; i>=0; i--)
	   {
		if (i + period < Bars && TimeMinute(iTime(NULL,0,i)) == 0 && thisHour != TimeHour(iTime(NULL,0,i)) )
		   {
			thisHour = TimeHour(iTime(NULL,0,i));
			prevH = High[Highest(NULL, 0, MODE_HIGH, DataPeriod, i+1-LookBackTF)]; 
			prevL = Low [Lowest (NULL, 0, MODE_LOW,  DataPeriod, i+1-LookBackTF)];
         ORHi = prevH;
         ORLo = prevL;
         ORHS = ORHi + SigConfirm * Point;
         ORLS = ORLo - SigConfirm * Point;
         ORH1 = ORHS + TargetOne  * Point;
         ORH2 = ORHS + TargetTwo  * Point;
         ORL1 = ORLS - TargetOne  * Point;
         ORL2 = ORLS - TargetTwo  * Point;
   		}
		if (ORHi > 0)
		   {
			OpenH2[i] = ORH2;
			OpenH1[i] = ORH1;
			OpenHS[i] = ORHS;
			OpenHi[i] = ORHi;
			OpenLo[i] = ORLo;
			OpenLS[i] = ORLS;
			OpenL1[i] = ORL1;
			OpenL2[i] = ORL2;
			}
		}	
   DoLabel( "OR-H2", OpenH2[0], indicator_color1 );
   DoLabel( "OR-H1", OpenH1[0], indicator_color2 );
   DoLabel( "OR-HS", OpenHS[0], indicator_color3 );
   DoLabel( "OR-LS", OpenLS[0], indicator_color6 );
   DoLabel( "OR-L1", OpenL1[0], indicator_color7 );
   DoLabel( "OR-L2", OpenL2[0], indicator_color8 );
   Comment("Opening Range"); 
	return(0); }
	
void DoLabel( string dName, double dValue, color dColor )
   {
   if (ObjectFind(dName) != 0)
      {
      ObjectCreate(dName,OBJ_ARROW,0,Time[0],dValue);
      ObjectSet(dName,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
      ObjectSet(dName,OBJPROP_COLOR,dColor);  
      } 
   else
      {
      ObjectMove(dName,0,Time[0],dValue);
      }
   }
//+------------------------------------------------------------------+      
 

Comments