Sunday night price bars - page 2

 
rgctoronto:

WHRoeder only says to read the manual.  As I said I've already read the manual before I even posted my question in Post #6.  All those time & date functions return with real time values, not past values.  My question is how do I find past values ?   but I guess this isn't the forum for asking such help - sorry.

You should read better

Forum on trading, automated trading systems and testing trading strategies

Sunday night price bars

whroeder1, 2017.01.11 15:49


  1. You posted in a MT5 section. I don't know of a DayOfWeek() function in MT5.
  2. If you meant to post in the MT4 section, Perhaps you should read the manual. TimeDayOfWeek - Date and Time - MQL4 Reference

TimeDayOfWeek - Date and Time - MQL4 Reference
TimeDayOfWeek - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeDayOfWeek - Date and Time - MQL4 Reference
 

I did read better.  I wish you could understand my problem better.  The examples given in the manual show that the date is specified manually, rather than the system code determining that date.  If I have to tell it the exact date of every Sunday for the last 5 years, I'll be writing 260 lines of code to tell it every Sunday date.  That doesn't make sense.

All I'm asking is a little help - i.e. how do I get the function to go through each bar on the chart to determine its DayOfWeek, as opposed to writing 260 lines of code telling the code which days are Sundays ?

Sorry to be a pain.  If you ever come over to the Tradestation forums, I'll help you write any code you want, but I'm floundering here with this C language stuff.

 
rgctoronto: WHRoeder only says to read the manual. 
  1. I did not. I gave you a link (#7) to the actual function to look at past values.
  2. We're not going to code it for you.
    We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
 

Sorry - I was implying that I read the manual, and have tried the "actual" function you linked to.  I've been toying with that same function for 2 days, but I'm getting nowhere.  What I don't understand is how to have it tell me past values, because the only example it gives is when you manually tell it the Gregorian date.  And really, what's the point of that.  I want the program to figure them out so I don't have to write 260 lines testing for every Sunday for 5 years.

I'm not asking you to code my program.  I'm just asking you to throw me a bone, to get me over this hurdle that I'm obviously missing something, maybe due to my unfamiliarity with the C language.   You asked me to post my coding attempt.  OK here's one of many attempts.  Thanks

#property indicator_chart_window
int dayweek;

int start(){
   //find index of bar shown at leftmost side of screen
   int i = Bars-IndicatorCounted()-1;
   if( i > 3000 )
       i = 3000;

   //work from leftmost bar to rightmost bar
   while(i>=0)
   {
      dayweek = TimeDayOfWeek(D'2017.01.01');     // of course, this only gives me one of 250 dates, and prints "0" on EVERY bar
                                                  // I don't know how to get the DayOfWeek off each bar, incrementally, as it loops through the "While" loop
      if (dayweek == 0)
      {
      ObjectCreate("note1"+i,OBJ_TEXT,0,Time[i],High[i]+300*Point);
      ObjectSetText("note1"+i,IntegerToString(dayweek),10,"Tahoma",Gold);
      }
      
      i--;
   }
        
   return(0);
   }
 

You can modify this code

int OnInit()
  {
//--- mark sundays

   for(int i=0;i<Bars(Symbol(),PERIOD_CURRENT);i++)
     {
      switch(TimeDayOfWeek(iTime(Symbol(),PERIOD_CURRENT,i)))
        {
         case 0:// Sunday
           ObjectCreate(0,TimeToString(iTime(Symbol(),PERIOD_CURRENT,i),TIME_DATE),OBJ_VLINE,0,iTime(Symbol(),PERIOD_CURRENT,i),0);
            break;

         case 1:// Monday

            break;

         case 2:// Tuesday

            break;

         case 3:// Wednesday

            break;

         case 4:// Thursday

            break;

         case 5:// Friday

            break;

         case 6:// Saturday

            break;
        }
     }
//---
   return(INIT_SUCCEEDED);
  }
Maybe use PERIOD_D1 otherwise you'd be getting way to much multiple lines if you run it on a lower frame or you would get error 4200 overload since the line already existed.
 
That's terrific.  Thanks ever so much, Marco.
Reason: