Download MetaTrader 5
To add comments, please log in or register
Enable MQL5 Storage to store your source codes. It is free!
strontiumDog
263
strontiumDog 2016.09.12 15:34 

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

honest_knave
970
honest_knave 2016.09.12 15:44  

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

strontiumDog
263
strontiumDog 2016.09.12 15:46  
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.
strontiumDog
263
strontiumDog 2016.09.12 15:59  

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

Fernando Carreiro
1571
Fernando Carreiro 2016.09.12 16:07  
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!

honest_knave
970
honest_knave 2016.09.12 16:09  

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);
/
To add comments, please log in or register