problem starting EA during NY/LONDON overlap

 

Hello everyone, I have an EA based on making trades on daily chart.
The problem is that whenever i start it, the journal doesn't send me a report of the EA being initialized at a specific time.

Here is my code with printf statements. Only the "ea is not ready" string is being shown.

bool MarketHours()
  {

   if(Hour()>13 && Hour()<21){
   printf("ea ready");
   return(true);}
   else {
   printf("ea not ready"); //I only get this string in the journal
   return(false);}

  }
 

What is the Timezone of the broker? Does it coincide with those hours?

Remember that the "Hour()" function returns the Server time and not your local time, so maybe you will need to offset that so that it matches the required time.

 
FMIC:

What is the Timezone of the broker? Does it coincide with those hours?

Remember that the "Hour()" function returns the Server time and not your local time, so maybe you will need to offset that so that it matches the required time.

The Broker's  timezone is GMT+2, mine is GMT+1. But the problem is that, the daily chart seems like not taking into account the Hour() function, therefore my EA is unable to start at a precise hour. That's my problem actually. 
 

I don't believe that the Hour() function does not work on Daily charts! However your function may be only triggered once a day at the beginning of the bar if your code is detecting a New Bar and only executing it then.

Is that the case? Are you using a New Bar detection in order to only run certain parts of the code only once per bar?

If so, try calling it directly from the OnTick() event, just to see if that is the case.

Also, have you tested your EA on an Hourly Chart just to check if it behaves differently?

 
FMIC:

I don't believe that the Hour() function does not work on Daily charts! However your function may be only triggered once a day at the beginning of the bar if your code is detecting a New Bar and only executing it then.

Is that the case? Are you using a New Bar detection in order to only run certain parts of the code only once per bar?

If so, try calling it directly from the OnTick() event, just to see if that is the case.

Also, have you tested your EA on an Hourly Chart just to check if it behaves differently?

Yes I have a function for New Bar detection inside OnTick(), tested already on hourly chart and the journal there is showing correct initialization of EA.
 

Well, you have just described the problem and the solution. If you are indeed running the code within the "New Bar" code block, then it is NOT going to work for time-frames higher than H1.

You have to run that "MaretHours()" detection code outside of that "New Bar" block, either at every Tick or create an equivalent "New Hour" detection code block for that function.

 
FMIC:

Well, you have just described the problem and the solution. If you are indeed running the code within the "New Bar" code block, then it is NOT going to work for time-frames higher than H1.

You have to run that "MaretHours()" detection code outside of that "New Bar" block, either at every Tick or create an equivalent "New Hour" detection code block for that function.

It's outside actually.
 
trisperon:
It's outside actually.

Given that it works on the H1 Chart and not on the Daily chart, then the "MarketHours()" function is definitely not being called on every tick or maybe there is other logic that is affecting its impact.

So, without any other code provided by you for us to be able to analyse and see where the logic problem may be, it will probably be impossible for us to be able to help you further.

What I can suggest, is that you run the code in DEBUG mode via MetaEditor, or add plenty of "Print()" statements at various points, in order to be able to trace the execution and thus detect where the logic may be failing.

Alternatively, if you know another coder that you trust enough to share you code with, have them have a look at it. An extra pair of eyes may be able to see the problem!

Reason: