Question about formulate to calculate last N numbers in a series of numbers

 

I‌ would like to index the last 5 minutes from any current point

i‌f current minute is 50 (CurMin) then last 5  (N) by index:  

‌1 = 45‌
2 = 46
3 = 47
4 = 48‌
5 = 49 

I‌t's just CurMin-N+Index

But if current minute is 2 (CurMin) then last 5 (N) by index:

‌1 = 57
2 = 58
3 = 59
4 = 0

5 = 1 ‌

‌How can this be put in a formula? I think I need to work with MathMod().

T‌hanks.

 
Line_Trader: I‌ would like to index the last 5 minutes from any current point

You don't index time. Simply subtract 5 minutes (300) from current time (TimeCurrent.)

You index bars. Once you have the time you can find the M1 bar that corresponds with iBarShift.

Reason: