ATR Levels Indicator Daily to Weekly Opening

SwitchTrader

Trader
Apr 23, 2018
9
0
12
UK
Hi All,
I have this ATR indicator originally compiled by Bill Jones. What I am trying to do is to get it to open at 00:00 Hours every Sunday which is market open for me. As those in the know will see it's opening daily just now. I have managed to get the ATR changed from Daily to Weekly but as for what to change for the time frame I am stuck. I can change the opening times easily enough. Could someone show me where I should be looking and what I need to change? Would it be possible add an input to get it to open Monthly, Weekly and Daily even? Here's the code I have with the ATR Period already changed.

MQL4:
//+------------------------------------------------------------------+
//|                                                   ATR Marks.mq4  |
//|                                                   Bill Jones     |
//|                                            Colorado Springs, CO  |
//+------------------------------------------------------------------+
#property copyright "2014 - Bill Jones"
 
#property indicator_chart_window
//----
input int ATRPeriod=20;     // ATR Period Parameter
//----
double   H4,L4,fullatr,shiftnbr;
int      dayshift,dayshiftold=-5;
int      NbrDigits;
bool     ErrFlag=true;      // True = print an error
datetime OldBar=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("ATRHigh Line");
   ObjectDelete("ATRLow Line");
   ObjectDelete("ATR Label");
   ObjectDelete("ATRDay Line");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if(IndicatorCounted() < 1) return(0);
   if(Time[0] == OldBar)      return(0);
   OldBar=Time[0];
 
//----
   if(Period()>1440) // Day chart is the largest to display values on.
     {
      if(ErrFlag)
        {
         ErrFlag=false;
         Print("Error - Chart period is greater than 1 day.");
        }
      return(-1); // then exit
     }
   NbrDigits=Digits-1;    // Digits must be either 3 or 5.  2 & 4 Digit accounts do not work here.
   if(NbrDigits>2)
      shiftnbr=10000;
   else
      shiftnbr=100;
 
   int BarsPerChart=WindowBarsPerChart()-5;         // Don't check all of the bars
 
   dayshift=0;
   while(dayshift<BarsPerChart)
     {
      if(TimeToStr(Time[dayshift],TIME_MINUTES)=="00:00") break;  // Find the 5pm NY bar.
      dayshift++;
     }
 
   if(dayshift == dayshiftold) return(0);
   dayshiftold = dayshift;
 
   ObjectDelete("ATRHigh Line");
   ObjectDelete("ATRLow Line");
   ObjectDelete("ATR Label");
   ObjectDelete("ATRDay Line");
 
   fullatr=iATR(Symbol(),PERIOD_W1,ATRPeriod,1);
   L4 = Close[dayshift] - fullatr;
   H4 = Close[dayshift] + fullatr;
//----
 
//----
   if(ObjectFind("ATRDay Line")!=0)
     {
      ObjectCreate("ATRDay Line",OBJ_VLINE,0,Time[dayshift],0);
      ObjectSet("ATRDay Line",OBJPROP_COLOR,Teal);
      ObjectSet("ATRDay Line",OBJPROP_WIDTH,1);
     }
 
//----
   if(ObjectFind("ATRHigh Line")!=0)
     {
      ObjectCreate("ATRHigh Line",OBJ_TREND,0,Time[dayshift],H4,Time[0],H4);
      ObjectSet("ATRHigh Line",OBJPROP_COLOR,Teal);
      ObjectSet("ATRHigh Line",OBJPROP_WIDTH,1);
     }
 
//----
   if(ObjectFind("ATRLow Line")!=0)
     {
      ObjectCreate("ATRLow Line",OBJ_TREND,0,Time[dayshift],L4,Time[0],L4);
      ObjectSet("ATRLow Line",OBJPROP_COLOR,Teal);
      ObjectSet("ATRLow Line",OBJPROP_WIDTH,1);
     }
 
//----
   if(ObjectFind("ATR Label")!=0)
     {
      ObjectCreate("ATR Label",OBJ_TEXT,0,Time[dayshift+5],H4);
      ObjectSetText("ATR Label","ATR: "+DoubleToStr((fullatr*shiftnbr),0),10,"Verdana",White);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Thanks in advance for your help?
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
16,829
981
144
Odessa
www.earnforex.com
It is not that easy to modify it to show a Weekly open ATR level. Currently it uses a cycle with this condition to find the day start bar:
MQL4:
      if(TimeToStr(Time[dayshift],TIME_MINUTES)=="00:00") break;  // Find the 5pm NY bar.
You need to modify it to find the bar that fits your definition of "Sunday open".
 

Enivid

Administrator
Staff member
Nov 30, 2008
16,829
981
144
Odessa
www.earnforex.com
This one does what you asked for. You can set the day of the week (Sunday by default), hour and minute (00:00 by default) and it will find that candle and place the weekly ATR lines starting from there.
 

Attachments

  • ATR Marks.mq4
    3.8 KB · Views: 50