Intra Day Volatility Adjustment to ATR

Looking for the best way (i.e. Switch Statement) to adjust ATR for “Time of Day” based on “X” Minute Bars:

For Example, using 15 Minute Bars and Normalized% = ATR(N) / Close

The Intra Day Volatility Pattern is shaped a bit like a “U”, where the First 2-4 & Last 2-4 “15 Minute” Bars have most of the action and middle of the day is usually pretty quiet or dead.

U.S. Equities = 26 “15 Minute” Bars in Normal Regular Trading Day.

Without adjusting for the “U” shape then measuring Unusual Intra Day Volatility is misleading.

Two parts:

  1. Know the Typical Values Above / Below Normal that make the “U” shape (Time of Day Array calculation, assume that is done already.

  2. Adjust the ATR based on the Time of Day.

ATRraw = ATR(50) / Close;

tn = TimeNum();

Switch ( tn )

Case 94459:
    ATRadj = ATRraw / 2.5;       // Dividing by "2.5" means First Bar of Day 2.5x more Volatile than Normal
Case 95959:
    ATRadj = ATRraw / 2.1;

//  ect..... to 26 Cases


Case Statement does not allow a TimeNum (tn) - Error 6: must be Numeric or Boolean type.
Cannot use array, use [ ] - How?

If Case must be Numeric (Case1:, Case2:, ect, then how to pass through “tn”)?

Adjusting the ATR% needs to be done for EVERY IntraDay Bar, so it is quite a large piece of code, especially as the Size of the Minute Bars gets smaller, the number of bars in a normal, regular US Equity Market day gets quite large:
30 Minute Bar = 13
15 Minute Bar = 26
5 Minute Bar = 78
1 Minute Bar = 390

How to loop through a Switch Statement, using TimeNum () “tn” to dictate which “Case” to use?
… and to make code take on different Minute Bar Sizes?

Any help appreciated.

Moderator comment: Your post contained UNFORMATTED code and I had to fix it. Next time follow the forum rules and format the code properly or your post will be rejected.

The problem is not that tn is a TimeNum, the problem is that tn is an array rather than a single value. You could make the switch statement work by looping through all the bars and using tn[bar] instead of tn. However, given that you want to use different time intervals, a switch statement is probably not your best option, as you need to specify discrete values in each “case” clause. Using nested IIf statements would allow you to avoid looping, and also define time ranges for which an adjustment factor would be valid.

Thanks for the advice.

Assuming only ONE Minute Time Frame (i.e. 26 of 15 Minute Bars):
Any example on a Switch Statement that loops through all the bars of tn [bar]?

Any example of Nested “IIf” Statements?

Nesting “IIf” Statements seems to work OK if a reasonable amount of Bars in day (i.e. 13 of 30 Minute Bars for U.S. Equities), but anybody have a more efficient way, especially if trying to adjust volatility (ATR%) for 1 or 5 Minute Bars (78 & 390 Bars, respectively) ?

As @mradtke told you - use IIF() it is array function and there is nothing faster than array function for changing values bar-by-bar. Array (vector) based solutions are always better/faster.