GMT offset problem, looking for some help..

 

My EA uses a GMT offset extern int. Oanda is 4 hours behind GMT. The GMT integer is therefore set to -4.

However, this causes a problem as the EA recognises the hard coded time (2:00am) - GMT (-4) as (-2) so there is no trade.

I need the EA to recognise 2 (hard coded time) -4 (GMT offset) as 22. Perhaps this is done by limiting possible hours??

The time in the code below will never be 2 with a -4 GMToffset, as the hardcoded hour (2) - (4) is recognised as -2 NOT 22.

extern int GMToffset = -4;

void Time() {
  int hour = TimeHour(TimeCurrent())-GMToffset;
   if (hour == 2) 
}
 

Try this . . .

if (hour<0) hour = 24-hour;
 
RaptorUK:

Try this . . .


That would work if the GMT offset was always -4, but it could be -6, -8, etc.

If we had 24-6, the trade would trigger at 18 which would be the equivalent of 24 (0)GMT.

The trade should trigger at the hour 2am.

Perhaps if could use the following:


if (hour<0) hour = 26-GMToffset;
 
gangsta1:

That would work if the GMT offset was always -4, but it could be -6, -8, etc.

If we had 24-6, the trade would trigger at 18 which would be the equivalent of 24 (0)GMT.


Why would it ? What does this do ?

if (hour == 2) 

this is what I was suggesting . . .

extern int GMToffset = -4;

void Time() {
  int hour = TimeHour(TimeCurrent())-GMToffset;
  if (hour<0) hour = 24-hour;

   if (hour == 2) 
}
 
RaptorUK:

Why would it ? What does this do ?

this is what I was suggesting . . .


THis is what I have got and it will not work:

void Time() {
  int hour = TimeHour(TimeCurrent())-GMToffset;
   if (hour<0) hour = 24-hour;
   if (hour == 2) {
      IfOrderDoesNotExist();
   }
}


Hour == 2 is the hour to place the trade.
 

I think I see your issue . . . .

extern int GMToffset = -4;


  int hour = TimeHour(TimeCurrent())-GMToffset;


//  hour will always be positive  TimeHour(TimeCurrent()) -  -4
 
RaptorUK:

I think I see your issue . . . .


That's not the issue. If I set the offset to -1 which makes the trade time 2-1=1 then the EA will place a trade at 1, an hour before.
 
gangsta1:

That's not the issue. If I set the offset to -1 which makes the trade time 2-1=1 then the EA will place a trade at 1, an hour before.
Nope, 2 - - 1 = 3
 
RaptorUK:
Nope, 2 - - 1 = 3

I am currently printing comments to the journal and you are right. Strange that because when I set the gmt to -1, the EA was trading 1 hour before the current time..
 

Remove the - (minus) from here . . .

extern int GMToffset = -4;

or here . . .

  int hour = TimeHour(TimeCurrent())-GMToffset;
 
RaptorUK:

Remove the - (minus) from here . . .

or here . . .


Working on it now, will remove from within the code.

Do you know if the GMT shift needs to stay the same all year round on Alpari?

They are on GMT+2 at the moment and I am getting good results with a GMT shift of +2.

However, when they change to GMT+1 in the winter I am concerned that I may need to change the GMT shift to GMT+1.

Not sure if I need to keep the GMT+2 shift as the results are good all year round with this setting, but maybe when I test when Alapri is GMT+1, the results would be the same with a shift of GMT+1 rather than GMT+2.

Reason: