Identification of a new day

 

Ok. So I am trying to create a test that identifies if it is a new day. I am trying to do this through testing, on M1, to see if the date of the previous bar is less than the current bar. I have started with this:

                                    double Yesterday = TimeToStr(iTime(Symbol(),PERIOD_M1,1),TIME_DATE);
                                    double Today = TimeToStr(iTime(Symbol(),PERIOD_M1,0),TIME_DATE);

Will this return the dates for each of the bars indicated?

I have complied, and for some reason, (which I cannot understand as of yet) it gives me an error saying '=' - incompatible types. It does this for the Yesterday =, rather than then Today =.

Why would this be? Is this a good way of identifying a new day if the following test below is used?

                if(Yesterday < Today)
                    {

Does anyone have any suggestions? As some may know, I am VERY new to coding, so if you could explain it, I may be able to learn, rather than end up confused!

Thanks. 

 
NewCoder47:

Ok. So I am trying to create a test that identifies if it is a new day. I am trying to do this through testing, on M1, to see if the date of the previous bar is less than the current bar. I have started with this:

Will this return the dates for each of the bars indicated?

I have complied, and for some reason, (which I cannot understand as of yet) it gives me an error saying '=' - incompatible types. It does this for the Yesterday =, rather than then Today =.

Why would this be? Is this a good way of identifying a new day if the following test below is used?

Does anyone have any suggestions? As some may know, I am VERY new to coding, so if you could explain it, I may be able to learn, rather than end up confused!

Thanks. 

TimeToStr returns what kind of variable ?  what kind of variable does iTime() return ?  why would the date/time value for bar 1 ever not be less than the value for bar 0 ?
 
Once you have the answers to my questions and you have figured out what you have done wrong and why . .  you should look at this function:  TimeDayOfWeek()
 
RaptorUK:
TimeToStr returns what kind of variable ?  what kind of variable does iTime return ?  why would the date/time value for bar 1 ever not be less than the value for bar 0 ?


Ok. Thanks for the hints, I just changed it to a string value, which appears to report the date I am after. Its reporting the dates, rather than the times. There will be one minute every day, in which the dates do not match, and the previous bar will be less than the current bar.

                                    string Yesterday = TimeToStr(iTime(Symbol(),PERIOD_M1,1),TIME_DATE);
                                    string Today = TimeToStr(iTime(Symbol(),PERIOD_M1,0),TIME_DATE);

 One question I do have is can an if(...) statement test using a string value?

                if(Yesterday < Today)
                    {
 
NewCoder47:


 One question I do have is can an if(...) statement test using a string value?

Probably . . . but I don't think this will achieve what you are looking for . . .  look at TimeDayOfWeek()  it will do exactly what you need and with very simple code.
 
You can also play around with Hour( ). Are you interested in server time or local time?
 
But me i just look out the window if i see sun i know its a new day
 
You obviously don't live in the UK:-)
tonny:
But me i just look out the window if i see sun i know its a new day
 
btw new idea alarm clock ea alerts you when its a certain time coming up
 
NewCoder47:

Ok. So I am trying to create a test that identifies if it is a new day. ...

static datetime today;

if (today != iTime (Symbol(), PERIOD_D1, 0))
   {
   today = iTime (Symbol(), PERIOD_D1, 0);
   Print ("Its a new day ",TimeToStr(iTime (Symbol(), PERIOD_D1, 0)));
   }
 
static int reset;

if(Hour()==0&&reset==1){
 Alert("Happy new day!");
 reset=0;
}
if(Hour!=0) reset=1;

Ha ha mine is shorter

Reason: