Download MetaTrader 5
To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
sdoppke
70
sdoppke 2015.09.10 22: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++;
whroeder1
13600
whroeder1 2015.09.10 22:40  
if (DayOfYear() == DayOfYear()) ...
if (    X       ==     X      ) // Always true.
Search new bar and substitute DayOfYear for Time[0]
sdoppke
70
sdoppke 2015.09.17 14: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
sdoppke
70
sdoppke 2015.09.22 01: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?
whroeder1
13600
whroeder1 2015.09.22 13:15  
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?
sdoppke
70
sdoppke 2015.09.23 13:30  
WHRoeder:
What part of "Search new bar and substitute DayOfYear for Time[0]" was unclear?

The "Search new bar" part.
Keith Watford
Moderator
7887
Keith Watford 2015.09.23 22: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 

whroeder1
13600
whroeder1 2015.09.23 22:48  
sdoppke: The "Search new bar" part.
search
/
To add comments, please log in or register