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);
      }
   }
//+------------------------------------------------------------------+      
 



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_ARROW


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: