_Daily-Weekly Open

Download script
Author: djindyfx@sbcglobal.net
_Daily-Weekly Open

This tool is designed to provide traders with a clear visual reference of specific price levels on their trading charts. Specifically, it identifies and displays the opening prices for both the current day and the current week, allowing you to see at a glance where the market started during these key timeframes.

How it Works

The script automatically monitors the price history of your chosen currency pair or asset. It looks for specific "transition moments"—the exact point in time when a new trading day begins or when a new trading week starts. When the tool detects these shifts, it captures the opening price at that exact moment and projects it forward as a horizontal line across your screen.

Key Features & Behavior

  • Daily Open Reference: The script identifies the beginning of each new day. It places a dotted line on your chart representing the price at which the market opened for that day. This helps in identifying intraday trends and support or resistance levels established since the morning session began.
  • Weekly Open Reference: Similarly, the tool tracks the start of the trading week (typically Monday). It draws a dash-dot line showing the weekly opening price, which is a significant level for many traders who look for long-term momentum or weekly reversals.
  • Timeframe Compatibility: The tool includes built-in logic to ensure it displays correctly depending on the chart you are viewing. For example:
    • The Weekly Open line will only appear if you are viewing a timeframe of Daily (D1) or lower (e.g., H4, H1, M15).
    • The Daily Open line will only appear if you are viewing a timeframe of 4-hour (H4) or lower.
  • Dynamic Updates: As the market moves and new days or weeks begin, the tool automatically updates its lines to reflect the most recent opening prices, ensuring your visual aids stay current with live market data.

By highlighting these two critical price points, the script helps remove the manual work of looking up previous prices, providing a cleaner workspace where you can more easily judge whether the current market price is trading above or below major session beginnings.

Miscellaneous
Implements a curve of type %1
9 Views
1 Downloads
0 Favorites
_Daily-Weekly Open
//+------------------------------------------------------------------+
//|                                            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 Blue

//---- buffers
double dailyopen[];
double weeklyopen[];
double line;
double d,w,p;

//+------------------------------------------------------------------+
//| 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;
   p=Period();
//----

   if(counted_bars<0) return(-1);
   
   limit=(Bars-counted_bars)-1;

// - Weekly Open Line Draw
   if(counted_bars==0)
     {//0
      if (p>PERIOD_D1)return(-1);
         ObjectCreate("Weekly Open",OBJ_HLINE,0,0,0);
     }//0
    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
       
       weeklyopen[i]=w;
       //Comment("Weekly Open  ", weeklyopen[i]);
      }//0

// - Daily Open Line Draw   
   if(counted_bars==0)
     {//0
      if (p>PERIOD_H4)return(-1);
         ObjectCreate("Daily Open",OBJ_HLINE,0,0,0);
     }//0
   for(i=limit; i>=0; i--)
       {
       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;
      /*
      Comment("Daily Open     ", dailyopen[i],"\n",
             "Weekly Open  ", weeklyopen[i]);
      */
      } 

//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments