Quick question regarding some pivot point code.

 

Hi

I have an EA and I have this code:

double Pivot(string up_dn){int time = StrToTime("22:00"),shift;
   if(TimeCurrent()<=time){
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,1)+22*3600,false);
   }else{
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,0)+22*3600,false);
   }
   int    count    = 1440/Period();
   double PDayHigh = iHigh(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_HIGH,count,shift));
   double PDayLow  = iLow (Symbol(),Period(),iLowest (Symbol(),Period(),MODE_LOW ,count,shift));
   double Pivot    = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;    // Pivot point
   double Range = PDayHigh - PDayLow;
   pivot[0] = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;
   pivot[1] = PDayHigh - PDayLow;
   pivot[2] = 2 * pivot[0] - PDayLow;                     // R1
   pivot[3] = pivot[0] + Range;                           // R2
   pivot[4] = pivot[2] + Range;                           // R3
   pivot[5] = 2 * pivot[0] - PDayHigh;                    // S1
   pivot[6] = pivot[0] - Range;                           // S2
   pivot[7] = pivot[5] - Range;                           // S3

I have set it so it calculates the pivots at 2200 GMT +0, the problem I am having is that it calculates on the open of the 2200 candle, I am new to coding and cant seem to be able to get it to calculate on the close of the 2200 candle (or open of the next candle).

Can anyone give me a hand with this? I have coded this with the help of a friend that is more experienced but I would like to try to fix it.

Thanks

Antony

 

Hi

Would this help:

double Pivot(string up_dn){int time = StrToTime("22:00"),shift;
   if(TimeCurrent()<=time){
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440+1,1)+22*3600,false);
   }else{
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440+1,0)+22*3600,false);
   }

The +1 will cause the EA to read from the next candle after 2200?

Thanks

Antony

 

y not StrToTime("23:00"),shift;

 

Hi

I did think of that but it means that on the 1 min chart, 60 bars would have passed before the pivots would be correct, so for one hour the pivots would be wrong on the 1 min and for my stratergy the pivots play an almost critical role.

My thoughts were to start the calculation on the close of the 2200 bar or even the open of the next bar, same thing really in terms of the pivots.

Thanks

Antony

 

Confused - What time are you calculating the piviot? On the bar during the 22:00 hour the close will be the current price, when 23:00 is reached you will then have a 22:00 close price!

 

Hi

My EA works on mulitple time frames, but the new pivot point day starts on the first bar after 2200, so if it were on the 5 min chart the calculation will be on the close of the 2200 bar which will be 2205, for the 15min chart it will be 2215.

What if I used condition statements for each time frame ie if 30mins calculate at 2230?

Thanks

Antony

 

So your saying "If{ bar closed and time> 22:00 } // then calculate piviot points?

 

Yes that would do it I think, i am new to coding so how would I best integrate that with my original coding?

Thanks

Antony

 

Would this work:

double Pivot(string up_dn){int time = StrToTime("22:00"),shift;
   if{Close[0]> 22:00 
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,1)+22*3600,false);
   }else{
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,0)+22*3600,false);
   }

   int    count    = 1440/Period();
   double PDayHigh = iHigh(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_HIGH,count,shift));
   double PDayLow  = iLow (Symbol(),Period(),iLowest (Symbol(),Period(),MODE_LOW ,count,shift));
   double Pivot    = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;    // Pivot point
   double Range = PDayHigh - PDayLow;
   pivot[0] = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;
   pivot[1] = PDayHigh - PDayLow;
   pivot[2] = 2 * pivot[0] - PDayLow;                     // R1
   pivot[3] = pivot[0] + Range;                           // R2
   pivot[4] = pivot[2] + Range;                           // R3
   pivot[5] = 2 * pivot[0] - PDayHigh;                    // S1
   pivot[6] = pivot[0] - Range;                           // S2
   pivot[7] = pivot[5] - Range;                           // S3

Thanks

Antony

 

No - for simplisity of understanding I did not put in the when not to calculate the Piviot values.

Not familiar with the iBarShift() function.

Someone else here can provide better coding more quickly than I. I will have to have a think about the code needed for a while.

 

The code you posted works as far as I can tell as you seem to want it too and is independant of chart time period

double Pivot(string up_dn)
   {
   int time = StrToTime("22:00"),shift;
   
   if(TimeCurrent()<=time){ //compares data type datetime with integer but should do what is required which is to use todays date after 10pm
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,1)+22*3600,false); // Look for the bar whos time is nearest to yesterdays date 10pm 
   }else{
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,0)+22*3600,false);// Look for the bar whos time is nearest to todays date 10pm 
   }
   int    count    = 1440/Period(); //number of bars to search to find highest high etc.
   double PDayHigh = iHigh(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_HIGH,count,shift));
   double PDayLow  = iLow (Symbol(),Period(),iLowest (Symbol(),Period(),MODE_LOW ,count,shift));
   double Pivot    = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;    // Pivot point
   double Range = PDayHigh - PDayLow;
   pivot[0] = (PDayHigh + PDayLow + iClose(Symbol(),Period(),shift)) / 3;
   pivot[1] = PDayHigh - PDayLow;
   pivot[2] = 2 * pivot[0] - PDayLow;                     // R1
   pivot[3] = pivot[0] + Range;                           // R2
   pivot[4] = pivot[2] + Range;                           // R3
   pivot[5] = 2 * pivot[0] - PDayHigh;                    // S1
   pivot[6] = pivot[0] - Range;                           // S2
   pivot[7] = pivot[5] - Range;                           // S3

I would be tempted to change

if(TimeCurrent()<=time)

so that the time you are checking for includes todays date and then do the comparason with Time[0]

double Pivot(string up_dn)
{ 
   int shift ; 
   datetime time= iTime(Symbol(),1440,0)+22*3600 ;
   
   if( Time[0] <= time )
   { 
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,1)+22*3600,false);// Look for the bar whos time is nearest to yesterdays date 10pm 
   }else{
      shift = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,0)+22*3600,false);//// Look for the bar whos time is nearest to todays date 10pm
   }

Thus only when Time[0] is strictly greater than todays date plus 22 hours will the code calculate the piviot values using todays date to get the last 24 hours piviot values.

Reason: