DayOpen
Download scriptOverview
This script is designed for the MetaTrader 4 platform to provide traders with a clear visual reference for the "Daily Open" price. It identifies the specific price point at which each new trading day begins and projects that level onto your chart. By visualizing this key psychological and technical milestone, it helps traders better understand the daily price range and identify potential support or resistance levels.
How the Logic Works
The script operates by constantly scanning the historical price data of the currency pair or asset you are currently viewing. Here is a step-by-step breakdown of its internal logic:
- Time Monitoring: The tool looks at the timestamp of every price candle on your chart. It specifically watches for "breaks" in time—moments where the day changes from one to the next.
- Price Identification: Every time the script detects that a new day has started, it captures the exact "Opening Price" of that first candle.
- Data Storage: Once the opening price for a new day is identified, the script remembers this value. It then carries that specific price forward across all subsequent candles until the next day begins.
- Visual Mapping: The tool performs two visual actions simultaneously:
- It draws a continuous line across the chart history, marking where each day's opening price sat.
- It creates an on-screen text label titled "Daily Open" to clearly identify the data being displayed.
Key Features for Traders
- Dynamic Updating: The script automatically recalculates as new candles form, ensuring that you are always seeing the current day's opening price relative to the previous days.
- Historical Context: Instead of just showing you today's open, it maps out the openings for previous days, allowing you to see how the market has reacted to those levels over time.
- Clean Visualization: The information is presented as a clean white line on your chart window, minimizing clutter while providing essential data for your trading strategy.
Technical Compatibility Note
The script includes a safety check to ensure it runs effectively on lower timeframes (such as 1-minute, 5-minute, or 15-minute charts). If the timeframe is too large, the script will pause to prevent unnecessary processing, ensuring your platform remains responsive.
//+------------------------------------------------------------------+
//| DayOpen.mq4 |
//|
//+------------------------------------------------------------------+
#property copyright "orBanAway"
#property link ""
#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
//---- input parameters
//---- buffers
double PBuffer[];
string Pivot="Daily Open";
int fontsize=10;
double P;
double x;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectDelete("Daily Open");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE,0,2,White);
SetIndexBuffer(0,PBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="Daily Open";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,1);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
//---- indicator calculation
if (counted_bars==0)
{
x=Period();
if (x>240) return(-1);
ObjectCreate("Daily Open", OBJ_TEXT, 0, 0,0);
ObjectSetText("Daily Open", " Daily Open",fontsize,"Arial",Red);
}
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
// if(counted_bars>0) counted_bars--;
limit=(Bars-counted_bars)-1;
for (i=limit; i>=0;i--)
{
if (TimeDay(Time[i])!=TimeDay(Time[i+1]))
{
P=(Open[i]);
ObjectMove("Daily Open", 0, Time[i],P);
}
PBuffer[i]=P;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments