This script is a specialized charting tool designed to provide visual trading levels based on the opening price of previous daily candles. It helps traders identify key price zones by projecting specific mathematical offsets from the start of each trading day.
Core Functionality
The primary purpose of this tool is to automatically map out a series of horizontal levels across your chart. Instead of manually calculating prices, the script looks back at historical daily data and identifies the "Opening Price" for each day. It then projects four distinct levels based on these opening values.
Key Features & Logic
- Daily Open Tracking: The script retrieves the opening price from the Daily (D1) timeframe. It does this systematically, allowing you to see where each day started even when viewing lower timeframes like minutes or hours.
- Directional Orientation: A core feature of the logic is a "toggle" setting. Depending on your preference, you can choose whether the levels project upwards or downwards from the daily opening price.
- In one mode, it adds values to the opening price (bullish perspective).
- In the other mode, it subtracts values from the opening price (bearish perspective).
- Mathematical Offsets: The script uses four specific numerical points to create the levels: 34, 89, 144, and 233. These are plotted as distinct lines on your chart, providing a consistent grid of reference points.
- Historical Lookback: You can customize how many days of data the script should analyze. This allows you to focus on recent price action or view a much longer historical perspective.
Visual Representation
The tool organizes these levels into different visual styles (solid lines, dots, and dashed lines) so that they are easy to distinguish at a glance. By providing these "Day Fib" levels, the script helps traders visualize potential support and resistance areas derived directly from daily market behavior.
//+------------------------------------------------------------------+
//| DayOpenFib.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Lime
#property indicator_color3 Lime
#property indicator_color4 Lime
#property indicator_color5 Lime
#property indicator_color6 Lime
double yc[];
double l1[]; //38
double l2[]; //89
double l3[]; //144
double l4[]; //233
//double l5[]; //233
extern int HowManyDays = 100;
extern bool up=true;
int init()
{
//---- indicators
//----
SetIndexBuffer(0, yc);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,2);
SetIndexLabel(0, "Yesterday Close");
SetIndexBuffer(1, l1);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID,2);
SetIndexLabel(1, "Day Fib 38");
SetIndexBuffer(2, l2);
SetIndexStyle(2, DRAW_LINE, STYLE_DOT);
SetIndexLabel(2, "Day Fib 89");
SetIndexBuffer(3, l3);
SetIndexStyle(3, DRAW_LINE, STYLE_DASHDOTDOT);
SetIndexLabel(3, "Day Fib 144");
SetIndexBuffer(4, l4);
SetIndexStyle(4, DRAW_LINE, STYLE_SOLID,3);
SetIndexLabel(4, "Day Fib 233");
//SetIndexBuffer(5, l5);
//SetIndexStyle(5, DRAW_LINE);
//SetIndexLabel(5, "Line 5");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int i=0,j=0;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
datetime dailyTime[];
double dailyClose[],dailyOpen[];
bool newEndDay=false;
ArrayCopySeries(dailyTime,MODE_TIME,Symbol(),PERIOD_D1);
ArrayCopySeries(dailyOpen,MODE_OPEN,Symbol(),PERIOD_D1);
for (i=0;i<limit;i++){
if ( j < HowManyDays && Period() < PERIOD_D1){
if (newEndDay) {newEndDay=false; continue;}
yc[i] = dailyOpen[j];
if (up) {
l1[i] = dailyOpen[j] + 34*Point;
l2[i] = dailyOpen[j] + 89*Point;
l3[i] = dailyOpen[j] + 144*Point;
l4[i] = dailyOpen[j] + 233*Point;
}else{
l1[i] = dailyOpen[j] - 34*Point;
l2[i] = dailyOpen[j] - 89*Point;
l3[i] = dailyOpen[j] - 144*Point;
l4[i] = dailyOpen[j] - 233*Point;
}
if (Time[i+1] < dailyTime[j]) {
j++;
newEndDay=true;
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments