Volume Flow Indicator

I want to use the following scan on the Amibroker Platform. Is there any way to convert it in AFL format?
I want to find any sort of divergence out of this indicator w.r.t price movement.

Chart Picture

study(title = "Volume Flow Indicator [LazyBear]", shorttitle="VFI_LB")

length = input(130, title="VFI length")
coef = input(0.2)
vcoef = input(2.5, title="Max. vol. cutoff")
smoothVFI=input(false, type=bool)

ma(x,y) => smoothVFI ? sma(x,y) : x

inter = log( typical ) - log( typical[1] )
vinter = stdev(inter, 30 )
cutoff = coef * vinter * close
vave = sma( volume, length )[1]
vmax = vave * vcoef
vc = iff(volume < vmax, volume, vmax) //min( volume, vmax )
mf = typical - typical[1]
vcp = iff( mf > cutoff, vc, iff ( mf < -cutoff, -vc, 0 ) )

vfi = ma(sum( vcp , length )/vave, 3)
vfima=ema( vfi, signalLength )

plot(0, color=gray, style=3)
showHisto=input(false, type=bool)
plot(showHisto ? d : na, style=histogram, color=gray, linewidth=3, transp=50)
plot( vfima , title="EMA of vfi", color=orange)
plot( vfi, title="vfi", color=green,linewidth=2)


/// @link https://forum.amibroker.com/t/volume-flow-indicator/25718/2
length = 130;//Param("VFI length",...
coef = 0.2;//Param("Coef",...
vcoef = 2.5;//Param("Max. vol. cutoff", ...
signalLength = 5; //Param(....
smoothVFI = False; //ParamToggle(...
showHisto = True;//ParamToggle(...

typical = Avg;
inter = log( typical ) - log(Ref(typical,-1));
vinter = StDev(inter, 30);
cutoff = coef * vinter * Close;
vave = Ref(MA(Volume, length ),-1);
vmax = vave * vcoef;
vc = Min( Volume, vmax );
mf = typical - Ref(typical,-1);
vcp = IIf( mf > cutoff, vc, IIf( mf < -cutoff, -vc, 0 ) );

x = SafeDivide(Sum(vcp, length),vave);
vfi = IIf(smoothVFI, MA(x, 3), x);
vfima = EMA( vfi, signalLength );
d = vfi-vfima;

Plot( vfima , "EMA of vfi", colorOrange);
Plot( vfi, "vfi", colorGreen, styleLine, Null, Null, 0, 0, 2);
if ( showHisto ) 
	Plot(d, "d", colorGrey40, styleHistogram, Null, Null, 0, 0, 3 );
PlotGrid(0, colorGrey50, 1, 1, True);


1 Like

Thanks, Sir. It is nice working although in the referred picture noise is less to some extent - I do not know why.
Actually I believe Volume is the king in trade. I have also put another request on OBV. That also works great in many cases to feel the divergence. Just see if that can be done or not.
Here is the result on my chart

The VFI was created by current Amibroker user Markos Katsanos and written about in a series of articles in Technical Analysis of Stocks and Commodities (2004). @Tomasz coded it into afl for the traders tip section back then. It would probably be useful for you to read the magazine article to understand its construction and implementation.



@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)

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.

Sir, really it is a good input you have given. I did not know it. You always help people learning the original article which is highly essential. I cannot understand why I cannot open that link


@prasadaraokarri the link works for me. Perhaps you need to be an up to date registered AmiBroker user?

1 Like

May be sir, since I use my old version only.
@fxshrat ....have nicely coded the 1st one. But when I found the 2nd one I felt it more practical. VFI is the same in both cases. But visualization and decision-making would be easier for the 2nd code I gave. Hopefully, @fxshrat or any other expert like you or anybody else would be kind enough to build up the corresponding AFL.

Can any expert help to convert this code to the d\produce the desired result as depicted in the Picture where f 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.

Why don't you try yourself?
You need to learn to do something yourself.

vfi_color = IIf(vfi > Ref(vfi,-1), colorGreen, 
IIf(vfi < Ref(vfi, -1), colorRed, colorGrey50));

Plot( vfi, "vfi", vfi_color, styleLine, Null, Null, 0, 0, 2);


Thanks, @fxchart for your kind support. Definitely, I have learned basic AFL programming but I am not an efficient coder like you people although I am trading over years with a success rate not bad. In fact, professionally I am also not a trader but belong to a completely different domain. Therefore in the forum, I seek experts' help.
I have modified your code for the histogram part a little so that visualization gets better. I have also incorporated the small coding you gave later

Plot( vfi, "vfi", vfi_color, styleLine, Null, Null, 0, 0, 2);
Plot( vfima , "EMA of vfi", colorOrange);
if ( showHisto ) 
//Plot(d, "d", colorGrey40, styleHistogram, Null, Null, 0, 0, 3 );
PlotGrid(0, colorGrey50, 1, 1, True);

and now it looks like this

Now I made it better with visualization....
More Better

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.