Download MetaTrader 5

Gold low high of the day start at 23:55, I need it to start at 00:00

To add comments, please log in or register
Whoseen
49
Whoseen  

Hi,

I've made an indicator that draw a fibonacci from the low of the day to the high of the day or invert depending on the trend.

Everything work great but now with the GOLD. If you go on m5 you will see that the day dont start at 00:00 but at 23:55. How can I add

5min to gold with this... 

SwingHigh = iHigh(Symbol(),PERIOD_D1,0);

SwingLow = iLow(Symbol(),PERIOD_D1,0); 

I attached the mq4 file

Thank you

 

Whoseen 

Files:
gold.jpg 161 kb
normal.jpg 150 kb
Keith Watford
Moderator
10541
Keith Watford  

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


Daniel Laverdiere
1388
Daniel Laverdiere  
Keith Watford:

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


I use : if ((Hour() == 0) && (Minute() == 0) && (Seconds() == 0) ...

or if (Day() != PreviousDay) ... 

Try my EA used for XAUEUR H1 default params is best. 

Nedd the source? let me know
Files:
Goldex.ex4 12 kb
honest_knave
Moderator
2293
honest_knave  
forexcue.com:

I use : if ((Hour() == 0) && (Minute() == 0) && (Seconds() == 0) ...

Try my EA used for XAUEUR H1 default params is best. 

Nedd the source? let me know

You need to be careful with this logic.

If you don't get a tick coming in at the exact second of midnight, this logic will not trigger.

If you get 2 or more ticks coming in at the exact second of midnight, it will fire multiple times. 

Keith Watford
Moderator
10541
Keith Watford  
Keith Watford:

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


forexcue.com:

I use : if ((Hour() == 0) && (Minute() == 0) && (Seconds() == 0) ...

Try my EA used for XAUEUR H1 default params is best. 

Nedd the source? let me know

As there is not a bar present for midnight, your if() will never return true.

Your code is only useful for checking against the current time, so no good for drawing objects on earlier bars.

honest_knave
Moderator
2293
honest_knave  
Keith Watford:

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


You could further refine this using a 'while' loop rather than an 'if' statement, for cases when it isn't only 1 bar short of midnight.
honest_knave
Moderator
2293
honest_knave  
Keith Watford:

As there is not a bar present for midnight, your if() will never return true.

Your code is only useful for checking against the current time, so no good for drawing objects on earlier bars.

I agree this is not suitable for the OP, but the logic might trigger if it were located in OnTimer and a different instrument had updated Hour/Minute/Seconds.
Keith Watford
Moderator
10541
Keith Watford  
Keith Watford:

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


honest_knave:
You could further refine this using a 'while' loop rather than an 'if' statement, for cases when it isn't only 1 bar short of midnight.

It shouldn't be necessary to use a loop.

If there is not a bar with the searched for time, iBarShift will return the next earlier bar, so it will be the last bar before midnight.

shift - 1 will be the first bar after midnight.

honest_knave
Moderator
2293
honest_knave  
Keith Watford:

It shouldn't be necessary to use a loop.

If there is not a bar with the searched for time, iBarShift will return the next earlier bar, so it will be the last bar before midnight.

shift - 1 will be the first bar after midnight.

Quite right, I didn't think that one through!
Whoseen
49
Whoseen  
Keith Watford:

As there is not a bar present for midnight, you may adapt your code with


      OpenTime = iTime(NULL, PERIOD_D1, 0);
      int shift=iBarShift(Symbol(),0,OpenTime);
      if(Time[shift]!=OpenTime)
         OpenTime=Time[shift-1];


Thank you this perfectly worked!! :). Dont know if you can help me with something else @Keith Watford

the red fibonacci is for downtrend and the green one is for uptrend of the day. Sometime it show the worng one,

exemple : red fib for for uptrend. I just change time frame and come back at the initiale one and it come back

to the correct fib, in that case the green one. Do you see something wrong on the code about that?

thank you 

Keith Watford
Moderator
10541
Keith Watford  
Whoseen:

Thank you this perfectly worked!! :). Dont know if you can help me with something else @Keith Watford

the red fibonacci is for downtrend and the green one is for uptrend of the day. Sometime it show the worng one,

exemple : red fib for for uptrend. I just change time frame and come back at the initiale one and it come back

to the correct fib, in that case the green one. Do you see something wrong on the code about that?

thank you 

Sorry, but I work with Fibonacci so rarely that I have to go through the documentation and relearn how to do it. Didn't you get an answer to this in your other topic?
12
To add comments, please log in or register