If true then +1 - resets to 0 tomorrow

Back to topics list To post a new topic, please log in or register
avatar
25
sdoppke 2015.09.11 00:28
 

Hi there I am trying to track an even that when true the count will increment 1 and provide totals for the day, then reset when the (server time) day ends.


I thought was pretty simple by placing the below code after the event proves true, but the counts are too high to be correct so the code is clearly flawed.


Any help would be appreciated. :)


if (DayOfYear()==DayOfYear())DB_Orders_Closed++;
avatar
12985
WHRoeder 2015.09.11 00:40 #
 
if (DayOfYear() == DayOfYear()) ...
if (    X       ==     X      ) // Always true.
Search new bar and substitute DayOfYear for Time[0]
avatar
25
sdoppke 2015.09.17 16:39 #
 

I was having a tough time with understanding and figuring a way with the reco above.  So with further effort I came up with this method: The problem is the count seems to take place (+1) then after a few seconds, returns to 0.  Would anyone be able to guide me to understand what I am doing wrong?

int DB_Orders_Closed;

int start()
{
if(Hour()==0&&Minute()<2){DB_Orders_Closed=0;};//to reset the value to 0 daily

//code to close orders
DB_Orders_Closed++;//to increment after the orders close
avatar
25
sdoppke 2015.09.22 03:01 #
 
sdoppke:

I was having a tough time with understanding and figuring a way with the reco above.  So with further effort I came up with this method: The problem is the count seems to take place (+1) then after a few seconds, returns to 0.  Would anyone be able to guide me to understand what I am doing wrong?


Still struggling with this one, would anyone know how to correct this?
avatar
12985
WHRoeder 2015.09.22 15:15 #
 
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?
avatar
25
sdoppke 2015.09.23 15:30 #
 
WHRoeder:
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?

The "Search new bar" part.
avatar
Moderator
3404
GumRai 2015.09.24 00:28 #
 
sdoppke:

The "Search new bar" part.
   static datetime bar_time=0;
   if(bar_time!=Time[0])
     {
      bar_time=Time[0];
      //Code to be executed once per bar
     }

Once per bar 

   static int day_of_year=0;
   if(day_of_year!=DayOfYear())
     {
      day_of_year=DayOfYear();
      //Code to be executed once per day
     }

 Once per day

Note that if you change time frames or re-initialise an indicator for any reason, the static variable will be re-set.

In an EA it will only be reset if the EA is removed and re-Attached or the terminal is re-started 

 

 

avatar
12985
WHRoeder 2015.09.24 00:48 #
 
sdoppke: The "Search new bar" part.
search

Back to topics list  

To add comments, please log in or register