@fxshrat ...sir I am trying to find out better visualization. The problem of market prediction becomes very difficult when the price movement remains choppy. During that time VFI also gives a false signal a number of times. To avoid this issue it is always better to visualize the VFI along with some background color variation of smooth moving averages.

In that context of that after finding a lot, I also got a much better chart of VFI a while back. You can please check whether that is better or not compared to the previous one. If it is considered better according to you, is it possible to convert it to AFL?

```
study(title="VFI - Volume Flow Indicator [UTS]", shorttitle="VFI [UTS]", format=format.volume)
// Const
kMaColor = color.aqua
kNeutralColor = color.gray
kBearColor = color.red
kBullColor = color.green
kAlma = "ALMA"
kEma = "EMA"
kSma = "SMA"
kWma = "WMA"
// Input
vfi_length = input(130, title="Length", minval=1)
vfi_coef = input(0.2, title="Coef", minval=0.1)
vfi_volCutoff = input(2.5, title="Volume Cutoff", minval=0.1)
vfi_smoothLen = input(3, title="Smoothing Period", minval=1)
vfi_smoothType = input(kEma, title="Smoothing Type", options=[kAlma, kEma, kSma, kWma])
vfi_showTrend = input(false, title="Visualize Trend")
vfi_showFill = input(true, title="Apply Filling")
vfi_showMa = input(true, title="Show Moving Average")
vfi_maType = input(kSma, title="Moving Average Type", options=[kAlma, kEma, kSma, kWma])
vfi_maLength = input(30, title="Moving Average Length", minval=1)
vfi_almaOffset = input(0.85, title="• ALMA - Offset (global setting)", minval=0.0, maxval=1.0, step=0.05) // more smoothness (closer to 1) vs. more responsiveness (closer to 0)
vfi_almaSigma = input(6.0, title="• ALMA - Sigma (global setting)", minval=0.0, step=0.05) // the larger sigma the smoother ALMA
// Functionality
isRising(sig) =>
sig > sig[1]
isFlat(sig) =>
sig == sig[1]
vfi_trendColor(sig) =>
iff(isFlat(sig), kNeutralColor, iff(isRising(sig), kBullColor, kBearColor))
vfi_color(sig) =>
iff(isFlat(sig), kNeutralColor, iff(sig > 0, kBullColor, kBearColor))
osc_color(sig) =>
iff(sig == 0, kNeutralColor, iff(sig > 0, kBullColor, kBearColor))
smooth(t, sig, len) =>
ma = float(sig) // None
if t == kSma // Simple
ma := sma(sig, len)
if t == kEma // Exponential
ma := ema(sig, len)
if t == kWma // Weighted
ma := wma(sig, len)
if t == kAlma // Arnaud Legoux
ma := alma(sig, len, vfi_almaOffset, vfi_almaSigma)
ma
calc_vfi(fviPeriod, smoothType, smoothLen, coef, vCoef) =>
avg = nz(hlc3)
inter = log(avg) - log(avg[1])
vInter = stdev(inter, 30)
cutOff = coef * vInter * close
vAve = smooth(kSma, volume[1], fviPeriod)
vMax = vAve * vCoef
vC = min(volume, vMax)
mf = avg - avg[1]
vCp = iff(mf > cutOff, vC, iff(mf < -cutOff, -vC, 0))
sVfi = sum(vCp, fviPeriod) / vAve
vfi = smooth(smoothType, sVfi, smoothLen)
value_vfi = calc_vfi(vfi_length, vfi_smoothType, vfi_smoothLen, vfi_coef, vfi_volCutoff)
value_ma = smooth(vfi_maType, value_vfi, vfi_maLength)
color_vfi = vfi_showTrend ? vfi_trendColor(value_vfi) : vfi_color(value_vfi)
color_osc = vfi_showFill ? osc_color(value_vfi) : na
color_ma = vfi_showMa ? kMaColor : na
// Drawings
plot_vfi = plot(value_vfi, title="VFI", color=color_vfi, linewidth=1)
plot_fill = plot(0, color=color_vfi, editable=false)
fill(plot_vfi, plot_fill, title="Oscillator Fill", color=color_osc, transp=75)
hline(0, color=color.gray, title="Zero Line", linewidth=1, linestyle=hline.style_dotted)
plot(value_ma, title="MA", color=color_ma, linewidth=2)
```

N.B.: **Trend Visualisation**

Optional Setting:

If the trend direction is *DOWN* the moving average is painted red. If the trend direction is *UP* the moving average is painted in green.

If the movement is *FLAT* then the color is grey.