MetaStock code for VFI


Vfi formula
PERIOD:= Input("PERIOD FOR Vfi ",5,1300,130);
COEF:=.2;
VCOEF:=Input("MAX VOLUME CUTOFF",0,50,2.5);
INTER:=Log(Typical())-Log(Ref(Typical(),-1));
VINTER:=Stdev(INTER,30);
CUTOFF:=COEF*VINTER*C;
VAVE:=Ref(Mov(V,PERIOD,S),-1);
VMAX:=VAVE*VCOEF;
VC:=If(V < VMAX,V,VMAX);
MF:=Typical()-Ref(Typical(),-1);
Vfi:=Sum(If(MF>CUTOFF, +VC, If(MF <-CUTOFF, -VC,0)),PERIOD)/VAVE;
Mov(Vfi,3,E);

To create the VFI Indicator in MetaStock, click on the indicator builder (fx), click on News, type VFI in the Name box, and enter the code in the Formula box.
Simplified VFI formula

Cum(If( Typ() > Ref(Typ(),-1), +V, If( Typ() < Ref(Typ(),-1), -V, 0) ))

This formula should only be used in the case of IPOs or stocks with less than one year of historical data.

Formula for color-coded volume bars

You can't program colors in MetaStock code, so you'll have to create three different indicators - one for up volume, one for down volume, and one for neutral volume. You should then insert all three in the same inner window. Double-clicking on each will open its properties. Select style/histogram for all, and the colors green, red, or blue for the up volume, down volume, and neutral volume, respectively.

The formula for up volume (green) is:

COEF:=.2;
VCOEF:=Input("MAX VOLUME CUTOFF",0,50,2.5);
INTER:=Log(Typical())-Log(Ref(Typical(),-1));
VINTER:=Stdev(INTER,30);
CUTOFF:=COEF*VINTER*C;
VAVE:=Ref(Mov(V,50,S),-1);
VMAX:=VAVE*VCOEF;
VC:=If(V < VMAX,V,VMAX);
MF:=Typical()-Ref(Typical(),-1);
VCP:=If(MF>CUTOFF,VC,0);
VCP

The formula for down volume (red) is:

COEF:=.2;
VCOEF:=Input("MAX VOLUME CUTOFF",0,50,2.5);
INTER:=Log(Typical())-Log(Ref(Typical(),-1));
VINTER:=Stdev(INTER,30);
CUTOFF:=COEF*VINTER*C;
VAVE:=Ref(Mov(V,50,S),-1);
VMAX:=VAVE*VCOEF;
VC:=If(V < VMAX,V,VMAX);
MF:=Typical()-Ref(Typical(),-1);
VCM:=If(MF<-CUTOFF,VC,0);
VCM

The formula for neutral volume (blue) is:

COEF:=.2;
VCOEF:=Input("MAX VOLUME CUTOFF",0,50,2.5);
INTER:=Log(Typical())-Log(Ref(Typical(),-1));
VINTER:=Stdev(INTER,30);
CUTOFF:=COEF*VINTER*C;
VAVE:=Ref(Mov(V,50,S),-1);
VMAX:=VAVE*VCOEF;
VC:=If(V < VMAX,V,VMAX);
MF:=Typical()-Ref(Typical(),-1);
VCN:=If(MF < CUTOFF AND MF >-CUTOFF,VC,0);
VCN


-M.K.