Download MetaTrader 5

If true then +1 - resets to 0 tomorrow

To add comments, please log in or register
sdoppke
71
sdoppke  

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++;
whroeder1
15577
whroeder1  
if (DayOfYear() == DayOfYear()) ...
if (    X       ==     X      ) // Always true.
Search new bar and substitute DayOfYear for Time[0]
sdoppke
71
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?

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
sdoppke
71
sdoppke  
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?
whroeder1
15577
whroeder1  
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?
sdoppke
71
sdoppke  
WHRoeder:
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?

The "Search new bar" part.
Keith Watford
Moderator
10569
Keith Watford  
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 

whroeder1
15577
whroeder1  
sdoppke: The "Search new bar" part.
search
To add comments, please log in or register