Help with coding pivot levels to swap time from GMT

 

Hi, I was wondering if anyone could help.


I have code for a daily pivot level indicator, it works fine but I have a uk broker

the pivots are drawn from 00:00 GMT and I would like them to be drawn from 22:00 GMT, does anyone know how best I do this?

I assume I just change the defined start time but I have no idea how to do this, I can provide the code if needed.


kind regards,

josh 

 

You probably have to rewrite the code to work on H1 (hourly) basis instead of D1, that's not easily done especially when the chart runs on a different timeframe.

 
Joshua Lee:

Hi, I was wondering if anyone could help.


I have code for a daily pivot level indicator, it works fine but I have a uk broker

the pivots are drawn from 00:00 GMT and I would like them to be drawn from 22:00 GMT, does anyone know how best I do this?

I assume I just change the defined start time but I have no idea how to do this, I can provide the code if needed.


kind regards,

josh 

For MT4 / MT5 ? 

 
For MT5, there were some nice ones ready made on MT4 but unfortunately I have to use MT5
Lorentzos Roussos:

For MT4 / MT5 ? 

 

we have been given one from work but it has diagonal connecting lines between each days pivots (hopefully that makes sense) and it just makes the charts look messy and cluttered

unfortunately the code is hidden on it so I was unable to change this

the one at work has an option to change the start hour (I set it to -2), so I assume this is what you mean

lippmaje:

You probably have to rewrite the code to work on H1 (hourly) basis instead of D1, that's not easily done especially when the chart runs on a different timeframe.

 
Here is what ive got so far, im just unable how to work out the time shift or if I need to add some code
Joshua Lee:
For MT5, there were some nice ones ready made on MT4 but unfortunately I have to use MT5
Files:
 
Joshua Lee:

Nice . Try this one , i got a little confused in the day change part because of no sleep -not for this code- in the Change function , so i commented it out .

#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots   9
//--- plot PivotPoint
#property indicator_label1  "PivotPoint"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDarkKhaki
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot R1
#property indicator_label2  "R1"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrMediumVioletRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot R2
#property indicator_label3  "R2"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrCrimson
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot R3
#property indicator_label4  "R3"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- plot S1
#property indicator_label5  "S1"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrCadetBlue
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- plot S2
#property indicator_label6  "S2"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrCornflowerBlue
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1
//--- plot S3
#property indicator_label7  "S3"
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrDodgerBlue
#property indicator_style7  STYLE_SOLID
#property indicator_width7  1
enum pp_method
{
pp_standard=0,//Standard
pp_woodie=1,//Woodie
pp_camarilla=2,//Camarilla
pp_fibonacci=3//Fibonacci
};
input pp_method PP_Calculation_Method=pp_standard;//Pp Method : 
input string PP_Split="00:00";//Pp split time HH:MM
//--- indicator buffers
double         PivotPointBuffer[];
double         HighCollects[];
double         LowCollects[];
double         R1Buffer[];
double         R2Buffer[];
double         R3Buffer[];
double         S1Buffer[];
double         S2Buffer[];
double         S3Buffer[];
int ChangeMinutes=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,PivotPointBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,R1Buffer,INDICATOR_DATA);
   SetIndexBuffer(2,R2Buffer,INDICATOR_DATA);
   SetIndexBuffer(3,R3Buffer,INDICATOR_DATA);
   SetIndexBuffer(4,S1Buffer,INDICATOR_DATA);
   SetIndexBuffer(5,S2Buffer,INDICATOR_DATA);
   SetIndexBuffer(6,S3Buffer,INDICATOR_DATA);
   SetIndexBuffer(7,HighCollects,INDICATOR_DATA);
   SetIndexBuffer(8,LowCollects,INDICATOR_DATA);
   ArraySetAsSeries(PivotPointBuffer,true);
   ArraySetAsSeries(R1Buffer,true);
   ArraySetAsSeries(R2Buffer,true);
   ArraySetAsSeries(R3Buffer,true);
   ArraySetAsSeries(S1Buffer,true);
   ArraySetAsSeries(S2Buffer,true);
   ArraySetAsSeries(S3Buffer,true);
   ArraySetAsSeries(HighCollects,true);
   ArraySetAsSeries(LowCollects,true);
   PlotIndexSetInteger(7,PLOT_DRAW_TYPE,DRAW_NONE);
   PlotIndexSetInteger(8,PLOT_DRAW_TYPE,DRAW_NONE);
   ChangeMinutes=HhMmStringToMinutes(PP_Split);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
  if(!ArrayGetAsSeries(time)){ArraySetAsSeries(time,true);}
  if(!ArrayGetAsSeries(open)){ArraySetAsSeries(open,true);}
  if(!ArrayGetAsSeries(close)){ArraySetAsSeries(close,true);}
  if(!ArrayGetAsSeries(high)){ArraySetAsSeries(high,true);}
  if(!ArrayGetAsSeries(low)){ArraySetAsSeries(low,true);}
  int loopito=rates_total-prev_calculated-2;
  if(loopito<0){loopito=0;}
  for(int i=loopito;i>=0;i--)
  {
  //propagate 
    HighCollects[i]=HighCollects[i+1];
    LowCollects[i]=LowCollects[i+1];
    PivotPointBuffer[i]=PivotPointBuffer[i+1];
    R1Buffer[i]=R1Buffer[i+1];
    R2Buffer[i]=R2Buffer[i+1];
    R3Buffer[i]=R3Buffer[i+1];
    S1Buffer[i]=S1Buffer[i+1];
    S2Buffer[i]=S2Buffer[i+1];
    S3Buffer[i]=S3Buffer[i+1];
  if(high[i]>HighCollects[i]||HighCollects[i]==EMPTY_VALUE){HighCollects[i]=high[i];}
  if(low[i]<LowCollects[i]||LowCollects[i]==EMPTY_VALUE){LowCollects[i]=low[i];}
  bool day_changed=DidDayChange(time,i,ChangeMinutes);
  if(day_changed)
    {
    CalculatePP(PP_Calculation_Method,HighCollects[i+1],LowCollects[i+1],close[i+1],PivotPointBuffer,R1Buffer,R2Buffer,R3Buffer,S1Buffer,S2Buffer,S3Buffer,i);
    HighCollects[i]=high[i];
    LowCollects[i]=low[i];
    }
  }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

bool DidDayChange(const datetime &time[],int i,int change_minutes)
{
MqlDateTime recent,old;
bool to_recent=TimeToStruct(time[i],recent);
  if(to_recent)
  {
  bool to_old=TimeToStruct(time[i+1],old);
    if(to_old)
    {
    //if(recent.day_of_year>old.day_of_year){return(true);}
    int recent_minutes=recent.min+recent.hour*60;
    int old_minutes=old.min+old.hour*60;
    if(old_minutes>recent_minutes){change_minutes+=1440;recent_minutes+=1440;}
    if(old_minutes<change_minutes&&recent_minutes>=change_minutes){return(true);}
    } 
  }
return(false);
}

int HhMmStringToMinutes(string hhmm)
{
int minutes=0;
ushort usep=StringGetCharacter(":",0);
string results[];
int k=StringSplit(hhmm,usep,results);
if(k==1){minutes=(int)(StringToInteger(results[0]));}
if(k>1){minutes=(int)(StringToInteger(results[0])*60+StringToInteger(results[1]));}
return(minutes);
}

void CalculatePP(pp_method method,
                 double high,
                 double low,
                 double close,
                 double &pp[],
                 double &r1[],
                 double &r2[],
                 double &r3[],
                 double &s1[],
                 double &s2[],
                 double &s3[],
                 int i)
{
    //standard pivot points 
    if(method==pp_standard)
    {
    pp[i]=(high+low+close)/3;
    r1[i]=(2*pp[i])-low;
    s1[i]=(2*pp[i])-high;
    r2[i]=pp[i]+(high-low);
    s2[i]=pp[i]-(high-low);
    r3[i]=high+2*(pp[i]-low);
    s3[i]=low-2*(high-pp[i]);
    }
    //standard pivot points ends here 
    //woodie pivot points 
    if(method==pp_woodie)
    {
    pp[i]=(high+low+2*close)/4;
    r1[i]=(2*pp[i])-low;
    s1[i]=(2*pp[i])-high;
    r2[i]=pp[i]+(high-low);
    s2[i]=pp[i]-(high-low);
    r3[i]=pp[i]+2*(high-low);
    s3[i]=pp[i]-2*(high-low);    
    }
    //woodie pivot points ends here 
    //camarilla pivot points 
    if(method==pp_camarilla)
    {
    pp[i]=(high+low+close)/3;
    r1[i]=close+((high-low)*1.0833);
    s1[i]=close-((high-low)*1.0833);
    r2[i]=close+((high-low)*1.1666);
    s2[i]=close-((high-low)*1.1666);
    r3[i]=close+((high-low)*1.2500);
    s3[i]=close-((high-low)*1.2500);    
    }
    //camarilla pivot points ends here   
    //fibonacci pivot points 
    if(method==pp_fibonacci)
    {
    pp[i]=(high+low+close)/3;
    r1[i]=pp[i]+((high-low)*0.382);
    s1[i]=pp[i]-((high-low)*0.382);
    r2[i]=pp[i]+((high-low)*0.618);
    s2[i]=pp[i]-((high-low)*0.618);
    r3[i]=pp[i]+(high-low);
    s3[i]=pp[i]-(high-low);        
    }
    //fibonacci pivot points ends here    
}
                 
                 
 
Also ,redundant passes occur in the live bar as 2 fellow coders will point out in the near future :) [_]o cheers
Reason: