(T_S_R)-Daily Range Display#2a

Download script
Author: Copyright � 2006, MetaQuotes Software Corp.
(T_S_R)-Daily Range Display#2a

This script is designed to provide traders with a visual and numerical overview of daily price action on their charts. It focuses on identifying the current day's price boundaries, the opening price, and calculating a projected "Daily Range" based on historical volatility.

Core Functionality

1. Daily Price Tracking The script identifies and marks the "Open" price for the current day. It automatically detects when a new day begins by checking for a change in the day of the week. Once it finds the opening price, it projects a horizontal line back across the chart so you can clearly see where the market started relative to where it is currently trading.

2. Dynamic Range Calculation (Volatility Analysis) One of the more advanced features of this script is its ability to calculate a projected range. It performs the following steps:

  • Historical Sampling: The script looks back at the high and low prices of several previous days (up to 20 days back).
  • Weighted Averaging: It calculates the average movement of those previous days to determine a "standard" daily volatility.
  • Range Projection: Using this average, it calculates three distinct layers:
    • Current Range: The actual high and low reached today.
    • Expanded Range (Daily 1): The basic boundaries of the current session.
    • Extended Range (Daily 2): A wider boundary (calculated by doubling the average volatility) which helps traders identify potential "overextended" zones or where the price might face significant resistance/support based on typical market behavior.

3. Visual On-Chart Elements If enabled in the settings, the script provides several visual aids:

  • Rectangular Zones: It draws colored boxes on the chart representing these different daily ranges (Current, Expanded, and Extended).
  • Text Labels: It places specific text labels directly on the chart to identify the current High, Low, Open price, and the Top/Bottom of the projected Daily Ranges.
  • Color Coding: Different colors are assigned to these zones to help distinguish between "normal" price action and extended volatility.

4. Real-Time Data Dashboard At the corner of your chart, the script maintains a live text summary. This dashboard provides a quick glance at:

  • The total range of today's movement (in pips/points).
  • The calculated Average Daily Range value.
  • The exact price of the daily Open, High, and Low.
  • The distance in pips from the opening price to the current price.

Summary for the User

Essentially, this tool acts as a "map" for the day's trading. Instead of guessing how far the market might move, the script looks at the last 20 days of history, calculates the average daily "swing," and draws zones on your chart to show you where the price is currently sitting compared to those historical norms. It helps you identify if today's move is standard or if the market is moving into an unusually large range.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
(T_S_R)-Daily Range Display#2a
//+------------------------------------------------------------------+
//|                               (T_S_R)-Daily Range Display#2a.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//|                                (T_S_R)-Daily Range Display#2.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//| Programming : CJA (forex-tsd forum)                              |
//| Develloped for: FXiGoR                                           |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property link      "Display by cja" 
// Thanks to the coders who supplied some of the code Daily_Open Indicator
// & Xdard777 for his MM labels code. 

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_width1 2
extern bool GRAPHICS_ON = false;
extern bool GRAPHICS_TEXT = false;

//---- indicator buffers

#define Daily "Daily"
#define Daily1 "Daily1"
#define Daily2 "Daily2"

extern color DailyColor =Maroon;//C'99,39,11'
extern color DailyColor1 =DarkGreen;//C'0,49,09'
extern color DailyColor2= C'0,44,09';

double TodayOpenBuffer[];
extern int TimeZoneOfData= 0;

//---- input parameters
int shift=0,i2=0,WorkTime=0,Periods=0,CurPeriod=0,nTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  	SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
	SetIndexBuffer(0,TodayOpenBuffer);
	SetIndexLabel(0,"Open");
	SetIndexEmptyValue(0,0.0); 
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
 {
  int lastbar;
   int counted_bars= IndicatorCounted();
   
   if (counted_bars>0) counted_bars--;
   lastbar = Bars-counted_bars;	
   DailyOpen(0,lastbar);
CreateHL();
}

void CreateObj(string objName, double start, double end, color clr)
  {
   ObjectCreate(objName, OBJ_RECTANGLE, 0, iTime(NULL,1440,0), start, Time[0], end);
   ObjectSet(objName, OBJPROP_COLOR, clr);
   ObjectCreate(objName, OBJ_RECTANGLE, 0, iTime(NULL,1440,0), 0, Time[0],0);
   ObjectSet(objName, OBJPROP_COLOR, clr);
   }
   void DeleteObjects()
   {
   ObjectDelete(Daily);
   ObjectDelete(DailyColor);
   ObjectDelete(Daily1);
   ObjectDelete(DailyColor1);
   ObjectDelete(Daily2);
   ObjectDelete(DailyColor2);
   
   }
   void CreateHL()
   {
   DeleteObjects();
  double HI2 = iHigh(NULL,1440,0);
  double LOW2 = iLow(NULL,1440,0); 
  double HI3 = iHigh(NULL,1440,1);
  double LOW3 = iLow(NULL,1440,1);
  double HI4 = iHigh(NULL,1440,0);
  double LOW4 = iLow(NULL,1440,0);
  double HI5 = iHigh(NULL,1440,2);
  double LOW5 = iLow(NULL,1440,2);
  double HI6 = iHigh(NULL,1440,3);
  double LOW6 = iLow(NULL,1440,3);
  double HI7 = iHigh(NULL,1440,4);
  double LOW7 = iLow(NULL,1440,4);
  double HI8 = iHigh(NULL,1440,5);
  double LOW8 = iLow(NULL,1440,5);
  double HI9 = iHigh(NULL,1440,6);
  double LOW9 = iLow(NULL,1440,6);
  double HI10 = iHigh(NULL,1440,7);
  double LOW10 = iLow(NULL,1440,7);
  double HI11 = iHigh(NULL,1440,8);
  double LOW11 = iLow(NULL,1440,8);
  double HI12 = iHigh(NULL,1440,9);
  double LOW12 = iLow(NULL,1440,9);
  double HI13 = iHigh(NULL,1440,10);
  double LOW13 = iLow(NULL,1440,10);
  double HI14 = iHigh(NULL,1440,11);
  double LOW14 = iLow(NULL,1440,11);
  double HI15 = iHigh(NULL,1440,12);
  double LOW15 = iLow(NULL,1440,12);
  double HI16 = iHigh(NULL,1440,13);
  double LOW16 = iLow(NULL,1440,13);
  double HI17 = iHigh(NULL,1440,14);
  double LOW17 = iLow(NULL,1440,14);
  double HI18 = iHigh(NULL,1440,15);
  double LOW18 = iLow(NULL,1440,15);
  double HI19 = iHigh(NULL,1440,16);
  double LOW19 = iLow(NULL,1440,16);
  double HI20 = iHigh(NULL,1440,17);
  double LOW20 = iLow(NULL,1440,17);
  double HI21 = iHigh(NULL,1440,18);
  double LOW21 = iLow(NULL,1440,18);
  double HI22 = iHigh(NULL,1440,19);
  double LOW22 = iLow(NULL,1440,19);
  double HI23 = iHigh(NULL,1440,20);
  double LOW23 = iLow(NULL,1440,20);
  
  double OPEN = iOpen(NULL,1440,0);
  double CLOSE = iClose(NULL,1440,0);
  
  double ONE = (HI3-LOW3)/2;
  
  double FIVE = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8))/10;
                   
                
  double TEN = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
                  (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13))/20;
                    
  double TWENTY = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
               (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13)+
               (HI14-LOW14)+(HI15-LOW15)+(HI16-LOW16)+(HI17-LOW17)+(HI18-LOW18)+
               (HI19-LOW19)+(HI20-LOW20)+(HI21-LOW21)+(HI22-LOW22)+(HI23-LOW23))/40; 
                                              
  double AV = (FIVE+TEN+TWENTY)/3;// New SettingAV = (FIVE+TEN+TWENTY)/3;
  
  double AV2 = ((FIVE+TEN+TWENTY)/3)*20000;
  
  double HIDaily = iHigh(NULL,1440,0)-(AV);
  double LOWDaily = iLow(NULL,1440,0)+(AV);
  double HIDaily1 = iHigh(NULL,1440,0); 
  double LOWDaily1 =iLow(NULL,1440,0); 
  double HIDaily2 = iHigh(NULL,1440,0)-(AV)*2; 
  double LOWDaily2 =iLow(NULL,1440,0)+(AV)*2; 
  
    

if (GRAPHICS_TEXT == true)
{

//Today's High
 if(ObjectFind("HIDaily3") != 0)
{
ObjectCreate("HIDaily3", OBJ_TEXT, 0, Time[0], HI4);
ObjectSetText("HIDaily3", "            High ", 9, "Verdana", YellowGreen);
}
else
{
ObjectMove("HIDaily3", 0, Time[0], HI4);
}

//Todays Low 
 if(ObjectFind("HIDaily4") != 0)
{
ObjectCreate("HIDaily4", OBJ_TEXT, 0, Time[0], LOW4);
ObjectSetText("HIDaily4", "           Low ", 9, "Verdana", YellowGreen);
}
else
{
ObjectMove("HIDaily4", 0, Time[0], LOW4);
}

//Open
 if(ObjectFind("HIDaily5") != 0)
{
ObjectCreate("HIDaily5", OBJ_TEXT, 0, Time[0], OPEN);
ObjectSetText("HIDaily5", "             Open ", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily5", 0, Time[0], OPEN);
}

//Bottom of Daily Range
 if(ObjectFind("HIDaily6") != 0)
{
ObjectCreate("HIDaily6", OBJ_TEXT, 0, Time[8],HIDaily2);
ObjectSetText("HIDaily6", "           Bottom Daily Range", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily6", 0, Time[8], HIDaily2);
}
//TOP of Daily Range
 if(ObjectFind("HIDaily7") != 0)
{
ObjectCreate("HIDaily7", OBJ_TEXT, 0, Time[7],LOWDaily2);
ObjectSetText("HIDaily7", "           Top Daily Range", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily7", 0, Time[7], LOWDaily2);
}
}
   {
   if (GRAPHICS_ON == true)
   {
if( (WorkTime != Time[0]) || (Periods != Period()) ) {
CreateObj(Daily, HIDaily, LOWDaily, DailyColor);
CreateObj(Daily1, HIDaily1, LOWDaily1, DailyColor1);
CreateObj(Daily2, HIDaily2, LOWDaily2, DailyColor2);}
}

} 

Comment("\n",  "TODAYS RANGE: ", (HI2-LOW2)/Point,"\n","\n","AVG. Daily Average; ",AV2,"\n","\n","Open: ",  OPEN,"\n","\n", "Today's Hi: ", HI2,"  Low: ", LOW2,"\n", "\n", "Pips from Open: ", (CLOSE-OPEN),"\n",
                    "\n","Top Daily Range; ",(LOWDaily2),"\n","\n","Bottom Daily Range; ",(HIDaily2));
                    

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

int DailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec= TimeZoneOfData * 3600;
   double barsper30= 1.0*PERIOD_M30/Period();
   bool ShowDailyOpenLevel= True;
   // lastbar+= barsperday+2;  // make sure we catch the daily open		 
   lastbar= MathMin(Bars-20*barsper30-1, lastbar);

	for(shift=lastbar;shift>=offset;shift--){
	  TodayOpenBuffer[shift]= 0;
     if (ShowDailyOpenLevel){
       if(TimeDayOfWeek(Time[shift]-tzdiffsec) != TimeDayOfWeek(Time[shift+1]-tzdiffsec)){      // day change
         TodayOpenBuffer[shift]= Open[shift];         
         TodayOpenBuffer[shift+1]= 0;                                                           // avoid stairs in the line
       }
       else{
         TodayOpenBuffer[shift]= TodayOpenBuffer[shift+1];
       }
	  }
   }
      return(0);
}

Comments