Best way to calculate bars in a week

 

Hello

I'm working on a bespoke missed weekly pivots calculation.  If the user pulls such onto an M5 chart, as I process the Bars, if the Time of the last bar (i+1) is Sunday and the time of 'this' bar is Monday, I know i+1 is the last of last week.

What I was thinking of doing was then counting back to the first bar of 0000-0005 of the previous Monday and calc my pivot for last week from there.  I was wondering what the best way to calc this would be. My thought:

7200 / Period()

or is there a build-in I can use that I havent find yet?


Thanks

 

Why don't you just use iBarShift to find the bar that relates to the time you want, then retrieve the value using iHigh / iLow / iClose / iOpen? Or just use the values from the D1 or W1 chart?

Perhaps I've missed what you're trying to achieve

 
honest_knave:

Why don't you just use iBarShift to find the bar that relates to the time you want, then retrieve the value using iHigh / iLow / iClose / iOpen?

 

 

 

I thought of that, and I have the Time of the end bar of the stretch of time (remember pivot is high and low of the period (a week's worth of M5 candles) and the close of the last one all /3.  In order to get the first bar of that week in order to begin looking for the highs and lows is what I am looking for.
 

OK to answer the title, the best way appears to be what I put in my OP.

 
strontiumDog: OK to answer the title, the best way appears to be what I put in my OP.

Why not just look at the Weekly bars instead? The bar's iTime() of the weekly bar, is thus the beginning of the week, and with the aid of the iBarShift(), you can find the first M5 bar for the week

Also, the OHLC values from the Weekly bars already gives you what you need to calculate the pivot points. No need to go through all those M5 bars to do it!

 

I'm still missing what you're after I'm afraid. I don't understand what the relevance of the M5 chart is?

If you want the high, low and close of last week why don't you use: 

   double LastWkHigh =iHigh(NULL,PERIOD_W1,1),
          LastWkLow  =iLow(NULL,PERIOD_W1,1),
          LastWkClose=iClose(NULL,PERIOD_W1,1);
Reason: