Daily-Weekly Open
Download scriptThis tool is designed to provide traders with a clear visual reference of key price levels on their charts, specifically highlighting the opening prices for both the current trading day and the current trading week. By automatically identifying these milestones, the script helps traders understand where the market began its most recent session, which is often used as a psychological and structural reference point in technical analysis.
How the Logic Works
The script continuously monitors the price history of your active chart to detect specific transitions in time. It operates through two primary detection methods:
1. Daily Opening Price Tracking The logic scans the timeline to identify the exact moment the calendar day changes. Whenever it detects a shift from one day to the next, it captures the "Open" price at that specific starting point. It then projects this price as a horizontal line across your chart, allowing you to see how the current price relates to the beginning of the day's trading activity.
2. Weekly Opening Price Tracking In addition to daily movements, the script looks for the transition into a new trading week (specifically identifying Monday). When the switch from the previous week to the current week occurs, the script captures that opening price and projects it as a separate horizontal line.
Visual Presentation
To ensure the data is easy to read without cluttering your workspace:
- Distinct Styles: The script uses two different line styles (dotted and dash-dot) so you can easily differentiate between the daily and weekly levels at a glance.
- Dynamic Updating: The lines are not static; they automatically move and update as the market progresses to reflect the most recent opening prices.
- Clear Labeling: The indicator provides clear labels on your chart, ensuring you know exactly which line represents the Daily Open and which represents the Weekly Open.
By providing these two levels simultaneously, the tool helps traders quickly identify "value zones"—allowing for a better understanding of whether the market is trading above or below the key price points established at the start of the day and week.
//+------------------------------------------------------------------+
//| Daily-Weekly Open.mq4 |
//| djindyfx@sbcglobal.net |
//| http://www.learncurrencytrading.com/fxforum/blogs/djindyfx/ |
//+------------------------------------------------------------------+
#property copyright "djindyfx@sbcglobal.net"
#property link "http://www.learncurrencytrading.com/fxforum/blogs/djindyfx/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
//---- buffers
double dailyopen[];
double weeklyopen[];
double line;
double d,w;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_DOT,1);
SetIndexBuffer(0,dailyopen);
SetIndexStyle(1,DRAW_LINE,STYLE_DASHDOT,1);
SetIndexBuffer(1,weeklyopen);
string dopen, wopen;
dopen = "Daily Open";
wopen = "Weekly Open";
IndicatorShortName(dopen);
IndicatorShortName(wopen);
SetIndexLabel(0,dopen);
SetIndexLabel(1,wopen);
SetIndexDrawBegin(0,1);
//SetIndexDrawBegin(1,1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//ObjectDelete("Weekly Open");
//ObjectDelete("Daily Open");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
//----
if(counted_bars==0)
{//0
//d=Period();
//if (d>240)return(-1);
ObjectCreate("Weekly Open",OBJ_HLINE,0,0,0);
ObjectCreate("Daily Open",OBJ_HLINE,0,0,0);
}//0
if(counted_bars<0) return(-1);
limit=(Bars-counted_bars)-1;
for(i=limit; i>=0; i--)
{//0
if(1==TimeDayOfWeek(Time[i]) && 1!=TimeDayOfWeek(Time[i+1]))
{//1
w=Open[i];
ObjectMove("Weekly Open",0,Time[i],line);
}//2
if (TimeDay(Time[i]) !=TimeDay(Time[i+1]))
{//3
d=Open[i];
ObjectMove("Daily Open",0,Time[i],line);
}//3
weeklyopen[i]=w;
dailyopen[i]=d;
}//0
//----
return(0);
}
//+------------------------------------------------------------------+
Comments