Different TimeZone Bars Range In Higher TimeFrames?

 

Hi, I've been customizing a Pivot Points indicator and I think I need to get the calculations in a different way.

The indicator uses a variable to set a "hours shift" from the server. For example: I use a server that show me the charts in GMT hour, so I set the indicator to calculate the pivot points using 10pm GMT as close time (instead of 12am).

To do this it just take all the bars inside a loop like this:


i = Bars - IndicatorCounted() - 1;
while(i >= 0){}


In the charts smaller than 1H it's easy to do the calculations, since each day range will have at least 24 bars I just set each day range to start/finish at any hour I want, but in the 4H the indicator cannot get the correct day range (with the shifter hours), because for example it can't get the close price for 10pm, only 8pm or 12pm (in a GMT server).


This makes the indicator to recalculate the pivots and they are not correct because they are calculated in a different time range.


Is there a way to calculate the pivots always on the 1H chart and show those on all the other timeframes?

Or maybe there is a better way to get the day ranges with a shifted timezone.


I need your advice, even when coding mql4 is easy for me (it's pretty much like C), I am burning my brain trying to figure out how to get this indicator working properly.

 
Here is the source I am using.
Files:
pp.mq4  9 kb
 

I've managed to make this:


int start()
{
int i = iBars(Symbol(),PERIOD_H1)-1;
int Count;
while(i >= 0)
{
if( PivotDay( Time[i+1], ShiftHrs ) != PivotDay( Time[i], ShiftHrs ) )
{
Count = iBarShift( NULL, 0, PivotDayStartTime ) - i;
PDayClose = iClose(NULL,PERIOD_H1,i+1);
PDayHigh = High[ iHighest( NULL, 0, MODE_HIGH, Count, i+1 ) ];
PDayLow = Low[ iLowest( NULL, 0, MODE_LOW, Count, i+1 ) ];
Pivot[i] = ( PDayHigh + PDayLow + PDayClose ) / 3;

PivotDayStartTime = Time[i];
}
else // no change to pivot levels
{
Pivot[i] = Pivot[i+1];
}
BarTime = Time[i];
i--;
}
return(0);
}


int PivotDay( datetime BarTime, datetime ShiftHrs )
{
int PDay = TimeDayOfWeek( BarTime + ShiftHrs * 3600 );

if( PDay == 0 ) PDay = 1; // Count Sunday as Monday
//if( PDay == 6 ) PDay = 5; // Count Saturday as Friday

return( PDay );
}


But the drawing of the calculations works well only on the 1H chart, because Pivot[] is an array assigned to a buffer and it's been filled into the 1H bars loop.

How could I get those calculations drawn on any timeframe?

 

If you want the calculations to be based on PERIOD_H1, then call the functions with PERIOD_H1 instead of zero which will then base it on the CURRENT time-frame displayed.


PDayHigh = High[ iHighest( NULL, PERIOD_H1, MODE_HIGH, Count, i+1 ) ];

PDayLow = Low[ iLowest( NULL, PERIOD_H1, MODE_LOW, Count, i+1 ) ];




 
You are right, but still it wont work on other timeframes because I am setting Pivot[] buffer on the 1H bars loop.
Reason: