problem with iTime on GOLD

 

Hi all, I use the following code in the majors, and it works well. 


datetime timeDailyOpen=iTime(Symbol(),PERIOD_D1,0);
   
  
int currentDailyBars=iBarShift(Symbol(),PERIOD_H1,timeDailyOpen,true);

If I apply the same code on GOLD it doesnt' work.

My broker is GMT+2.

The opening bar for the majors is 0:00, for GOLD the opening is 1:00.

How can I edit the code fot GOLD? Thank you!

 
Alberto Tortella:

Hi all, I use the following code in the majors, and it works well. 


If I apply the same code on GOLD it doesnt' work.

My broker is GMT+2.

The opening bar for the majors is 0:00, for GOLD the opening is 1:00.

How can I edit the code fot GOLD? Thank you!

Try....

if(Symbol() == XAUUSD) timeDailyOpen = timeDailyOpen + 3600;


...but, what "Time" exactly are you looking for... "Server" Time... "Local" Time....? The time on your computer "Local" Time is not the same as the markets...

In what context are you wanting to use this value?

All you are basically asking for is the "Bar Number" of the first bar of a New Day based on your computers "Local" time... (if I am correct).... I don't see the value for that...

 
   datetime timeDailyOpen=iTime(Symbol(),PERIOD_D1,0);
   int currentDailyBars=iBarShift(Symbol(),PERIOD_H1,timeDailyOpen,true);
   if(currentDailyBars==-1)
      currentDailyBars=iBarShift(Symbol(),PERIOD_H1,timeDailyOpen,false)-1;

This should work for all symbols.

Note that it only calculates closed bars, same as your code.

 

Yes I only need to find the closed H1 bars number for the current day.

Thank you I will try on Monday!

 
Keith Watford:

This should work for all symbols.

Note that it only calculates closed bars, same as your code.

I seem it works well thank you!

 
Keith Watford:

This should work for all symbols.

Note that it only calculates closed bars, same as your code.

Alberto Tortella:

I seem it works well thank you!


   HI KEITH , can you explain where this code for gold can be further used .

  

 
paul macques:

   HI KEITH , can you explain where this code for gold can be further used .

  

It is not code specifically for Gold.

It will work for any symbol to find the number of closed H1 bars since midnight.

Reason: