Your incorrect output in analysis comes from the fact that you are applying EOD interval in Analysis. In your analysis you should set the **same** interval as of chart. And you should add Interval column then you know which interval you have set there in analysis.

```
AddTextColumn(Interval(2), "Interval", 1);
```

Then this one is flawed

```
if (colorBrightGreen )
{
F61 = L1 + (Range *0.618);
}
else
{
F61 = H1 - (Range *0.618);
};
```

It should be

```
Range = (H1 - L1) * 0.618;
F61 = IIf(LowFirst, L1 + Range, H1 - Range);
```

This one makes no sense too

```
Filter = colorBrightGreen OR colorRed;
```

Colors are not true/false arrays. They are type number.

So instead you should use Filter such as this

`Filter = newday;`

Here is (almost) completely rewritten code (also removing your loop).

```
/// @link https://tinyurl.com/uglfnsp
daysback = 3;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));
Plot( C, "Price", colorDefault, styleBar );
dn = DateNum();
newday = dn != Ref( dn, -1);
bars_today = BarsSince(newday)+1;
ll = Valuewhen(newday, Ref(LowestSince(newday, L, daysback), -1));
bars_ll = Valuewhen(newday, Ref(LowestSinceBars(newday, L, daysback), -1))+bars_today;
Plot( ll, "LL", colorRed, styleStaircase | styleDashed );
hh = Valuewhen(newday, Ref(HighestSince(newday, H, daysback), -1));
bars_hh = Valuewhen(newday, Ref(HighestSinceBars(newday, H, daysback), -1))+bars_today;
Plot( hh, "HH", colorGreen, styleStaircase | styleDashed );
dt = DateTime();
bi = BarIndex();
qfdb = Status("quickaflfirstdatabar");
dt_at_low = Ref(dt, -bars_ll);
bar_at_low = Ref(bi, -bars_ll);
bars_since_ll = bi-bar_at_low;
dt_at_high = Ref(dt, -bars_hh);
bar_at_high = Ref(bi, -bars_hh);
bars_since_hh = bi-bar_at_high;
printf("Datetime of High before yesterday: %s\n", DateTimeToStr(SelectedValue(dt_at_high)));
printf("Datetime of Low before yesterday: %s\n", DateTimeToStr(SelectedValue(dt_at_low)));
printf("Bars since High before yesterday: %g\n", bars_since_hh);
printf("Bars since Low before yesterday: %g\n", bars_since_ll);
//printf("Bar of Low before yesterday: %g\n", bar_at_low);
//printf("QuickAFL bar of Low before yesterday: %g\n", qfdb+bar_at_low);
///// Extended Code ////////////////////////////////////
_SECTION_BEGIN("N-Day High Low");
function fxLookupArray(dt, array) {
// e.g. getting LLV/HHV, Lowest/HighestSince backwards
// by fxshrat@gmail.com
local i, n, bi, dt_list, flag, nullcnt, result;
bi = BarIndex();
result = Null;
flag = dt != Ref(dt,-1);
dt_list = SparseCompress(flag, dt);
nullcnt = NullCount(dt_list);
for ( n = nullcnt; n < BarCount; n++ ) {
i = Lookup(bi, dt_list[n]);
result[i] = array[i];
}
return ValueWhen(array == result, array);
}
L1 = fxLookupArray(dt_at_low, L);
H1 = fxLookupArray(dt_at_high, H);
Plot(ValueWhen(dt == SelectedValue(dt_at_high), H), "Swing High", colorYellow , styleDashed | styleStaircase);
Plot(ValueWhen(dt == SelectedValue(dt_at_low), L), "Swing Low", colorBlue, styleDashed | styleStaircase);
PlotShapes((L == L1) * shapesmallCircle, colorBlue, 0, L1, 0 );
PlotShapes((H == H1) * shapesmallCircle, colorYellow, 0, H1, 0 );
_SECTION_END();
LowFirst = bars_since_ll > bars_since_hh;
HighFirst = bars_since_hh > bars_since_ll;
Color = IIf(LowFirst, colorBrightGreen, colorRed);
TextColor = IIf(LowFIrst, colorBlack, colorWhite);
Range = (H1 - L1) * 0.618;
F61 = IIf(LowFirst, L1 + Range, H1 - Range);
Filter = newday;
AddTextColumn(Interval(2), "Interval", 1);
AddColumn(H1," 3D-Hi ",1.4);
AddColumn(L1," 3D-Lo ",1.4);
AddColumn(IIf(LowFirst, 'L', 'H'), " Lo / Hi - First ", formatChar, TextColor, Color, 100);
AddColumn(F61," FL0.618 - Level ",1.2);
```