# 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;

Switch ( tn )
{

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

//  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.

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.