prior_day_open_close_line
Download scriptThis tool is designed to provide traders with a clear visual reference for the opening price of each trading day. By identifying and displaying this specific price level, it helps users quickly recognize significant psychological and technical boundaries on their charts.
Core Functionality
The script automatically scans through your historical chart data to detect the exact moment a new day begins. Once it identifies the start of a new trading session, it captures the "Opening Price" at that specific moment.
How the Logic Works
- Day Change Detection: The tool monitors the time progression on your chart. It looks for the transition between one calendar day and the next.
- Price Mapping: When a change in date is detected, the script records the opening price of that new day. For all subsequent bars within that same day, it carries that opening price forward horizontally across the screen.
- Visual Smoothing: To ensure the chart remains clean and easy to read, the logic is designed to prevent "stair-stepping" or jagged lines. It ensures a smooth visual representation of the price level from the start of the day until the next one begins.
- Customizability: The script accounts for different time zones and allows for adjustments in how the data is displayed, ensuring that the daily open aligns correctly with your specific market data.
Practical Use
By highlighting the daily opening price as a horizontal reference, this tool allows you to see at a glance whether the current market price is trading above or below the day's starting point. It serves as a foundational layer for technical analysis, helping traders manage their entries and exits based on the daily range.
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_style1 4
#property indicator_width1 1
double TodayOpenBuffer[];
extern double TimeZoneOfData=0;
extern double Horizontaloffset=20;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TodayOpenBuffer);
SetIndexLabel(0,"Open");
SetIndexEmptyValue(0,0.0);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
int lastbar=Bars-counted_bars;
if(counted_bars==0) lastbar-=1+1;
DailyOpen(1,lastbar);
return (0);
}
//+------------------------------------------------------------------+
//| DailyOpen |
//+------------------------------------------------------------------+
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(TimeDay(Time[shift]-tzdiffsec)!=TimeDay(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