daily_open_line
Download scriptThis tool is designed to provide traders with a clear visual reference of the daily opening price on their trading charts. By identifying and marking the specific price point where each new trading day begins, it helps users understand key support and resistance levels established at the start of a session.
Core Functionality
The primary purpose of this script is to track the "Daily Open." Instead of just showing a single point in time, it projects that opening price across the chart for the duration of the day. This allows you to see exactly how the current market price relates to where the day started, which is a common technique used by traders to gauge momentum and sentiment.
How the Logic Works
The script operates using several specific logical steps to ensure the information displayed is accurate:
- Timezone Synchronization: The tool includes a setting that allows you to adjust for different timezones. This ensures that the "start of the day" aligns with your specific local market time or exchange time, rather than defaulting to a generic server time.
- Day Change Detection: The system constantly scans the historical data to identify the exact moment the calendar date flips. When it detects this change, it captures the price at that precise moment (the "Opening Price").
- Price Projection: Once the opening price for a new day is identified, the script carries that specific value forward. It applies this price to all subsequent candles until the next day begins.
- Visual Smoothing: The logic includes a specific instruction to prevent "stair-stepping" or jagged lines on the chart. By managing how the data is passed from one candle to the next, it ensures that the line remains clean and easy to read as you move across the trading history.
User Experience
For the user, this means you won't have to manually calculate or search for where a day started. The indicator automatically draws a horizontal reference line based on the daily open, allowing you to see at a glance whether the market is currently trading above or below the starting price of the day.
//*
//* my_DailyOpen_indicator
//*
//* Revision 1.1 2005/11/13 Midnite
//* Initial DailyOpen indicator
//* based pm
//*
#property copyright "Midnite"
#property link "me@home.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
#property indicator_style1 2
#property indicator_width1 1
double TodayOpenBuffer[];
extern int TimeZoneOfData= 0;
//+------------------------------------------------------------------+
//| 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 lastbar;
int counted_bars= IndicatorCounted();
if (counted_bars>0) counted_bars--;
lastbar = Bars-counted_bars;
DailyOpen(0,lastbar);
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(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