# VOLUME FLOW (VFI) INDICATOR from Markos Katsanos #### markos

##### Well-known member
VIP
This is from the same article as the FVE Indicator that is meant for short term trading. If someone could port this... much obliged.
Website: http://mkatsanos.com/VFI.html
Code:
``````Amibroker Code

Period = Param("VFI Period", 130, 26, 300, 10 );
Smooth=Param( "SMOOTH", 3, 1, 10, 1 );
MAP=Param( "MA Period", 30, 20, 100, 10 );
Coef = 0.2;
VCoef = Param("Vol Cutoff", 2.5, 1, 5, .5 );
inter = log( Avg ) - log( Ref( Avg, -1 ) );Vinter = StDev(inter, 30 );
Cutoff = Coef * Vinter * Close;Vave = Ref( MA( V, Period ), -1 );
Vmax = Vave * Vcoef;Vc = Min( V, VMax );MF = Avg - Ref( Avg, -1 );
VCP = IIf( MF > Cutoff, VC, IIf ( MF < -Cutoff, -VC, 0 ) );
VFI1 = Sum( VCP , Period )/Vave;
VFI =EMA( VFI1, smooth ); MAVFI=MA(VFI,MAP);

dynamic_color = IIf( VFI >= 0, colorGreen, colorRED ) ;
Plot( VFI, "VFI(" + PERIOD + ")", dynamic_color, styleThick );
Plot( MAVFI, "",coloryellow, styleDashed );
PlotGrid( 0, colorBlueGrey );``````

The VFI is based on the popular On Balance Volume (OBV) but with three very important modifications:

• Unlike the OBV, indicator values are no longer meaningless. Positive readings are bullish and negative bearish.
• The calculation is based on the day's median instead of the closing price.
• A volatility threshold takes into account minimal price changes and another threshold eliminates excessive volume.
• The indicator takes into account only the latest 6 month volume action and not the entire data loaded in the chart. #### BenTen

Staff
VIP
• markos #### horserider

##### Well-known member
VIP
@markos VolumeFlowIndicator is already A ToS indicator.

• markos
D

#### dolomick

##### Member
Can anyone combine this with the default RelativeVolumeStDev study in TOS for me? I am open to different implementation ideas, but I was thinking maybe the Relative volume would be centered on the zero line of the Volume Flow indicator. Combined would be very useful and take less lower screen space.

T

#### tomsk

##### Well-known member
VIP
@dolomick This is actually quite a good idea! Per your request I combined the TOS Volume Flow Indicator with the Relative Volume StDev study with the following characteristics. If a spike > 2 standard deviation is detected on the Relative Volume StDev, a GREEN dot is plotted. When this event happens, a label is displayed and an audible alert will be generated. In order to verify the results, also load the standard TOS Relative Volume StDev that displays on a lower chart. You'll see that the signals match up nicely. Have fun!

Code:
``````# Volume Flow with Relative Volume StDev Spike > 2 StDev
# tomsk
# 1.11.2020

# This study combines the TOS Volume Flow Indicator with the Relative Volume StDev study
# If a spike > 2 standard deviation is detected on the Relative Volume StDev, a GREEN dot is plotted.
# When this event happens, a label is displayed and an audible alert will be generated

declare lower;

# Volume Flow Indicator

input VFlength = 130;
input maxVolumeCutOff = 2.5;

assert(maxVolumeCutOff > 0, "'max volume cut off' must be positive: " + maxVolumeCutOff);

def cutOff = 0.2 * stdev(log(hlc3) - log(hlc3), 30) * close;
def hlcChange = hlc3 - hlc3;
def avgVolume = Average(volume, 50);
def minVolume = Min(volume, avgVolume * maxVolumeCutOff);
def dirVolume = if hlcChange > cutOff
then minVolume
else if hlcChange < -cutOff
then -minVolume
else 0;

plot VFI = ExpAverage(sum(dirVolume, VFlength) / avgVolume, 3);
plot ZeroLine = 0;

VFI.setDefaultColor(Color.Magenta);
ZeroLine.setDefaultColor(Color.Gray);

# Relative Volume StDev Spike > 2 StDev

input RVlength = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, RVlength)) / StDev(volume, RVlength);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);

plot RVSpike = if IsNaN(close) then Double.NaN
else if RelVol > numDev then 0
else Double.NaN;
RVSpike.SetPaintingStrategy(PaintingStrategy.Points);
RVSpike.SetLineWeight(5);
RVSpike.SetDefaultColor(Color.Green);
AddLabel(!isNaN(RVSpike), "Relative Volume Spike > 2 StDev", Color.Yellow);
# End Volume Flow with Relative Volume StDev Spike > 2 StDev``````

• Rojo Grande
D

#### dolomick

##### Member
Thanks so much! I had another idea and had actually deleted this post as I didnt want to create too much work, but since it’s done I will use it for sure!
My related idea was to add the relative volume std dev study to this https://usethinkscript.com/threads/...th-hot-percent-for-thinkorswim.389/#post-2542

I am again open to how to best implement, but I do think it would be useful to have a way to indicate if the relative vol std deviation is over 2, over 3, over 4, etc. for any given volume bar. I think a label would get overlooked, so ideally something near the actual volume bar. Maybe a bubble with relative vol std dev value in it at the relevant volume bar? I think that would make a great study even greater.

A

#### anycolour

##### Member
@dolomick This is actually quite a good idea! Per your request I combined the TOS Volume Flow Indicator with the Relative Volume StDev study with the following characteristics. If a spike > 2 standard deviation is detected on the Relative Volume StDev, a GREEN dot is plotted. When this event happens, a label is displayed and an audible alert will be generated. In order to verify the results, also load the standard TOS Relative Volume StDev that displays on a lower chart. You'll see that the signals match up nicely. Have fun!

Code:
``````# Volume Flow with Relative Volume StDev Spike > 2 StDev
# tomsk
# 1.11.2020

# This study combines the TOS Volume Flow Indicator with the Relative Volume StDev study
# If a spike > 2 standard deviation is detected on the Relative Volume StDev, a GREEN dot is plotted.
# When this event happens, a label is displayed and an audible alert will be generated

declare lower;

# Volume Flow Indicator

input VFlength = 130;
input maxVolumeCutOff = 2.5;

assert(maxVolumeCutOff > 0, "'max volume cut off' must be positive: " + maxVolumeCutOff);

def cutOff = 0.2 * stdev(log(hlc3) - log(hlc3), 30) * close;
def hlcChange = hlc3 - hlc3;
def avgVolume = Average(volume, 50);
def minVolume = Min(volume, avgVolume * maxVolumeCutOff);
def dirVolume = if hlcChange > cutOff
then minVolume
else if hlcChange < -cutOff
then -minVolume
else 0;

plot VFI = ExpAverage(sum(dirVolume, VFlength) / avgVolume, 3);
plot ZeroLine = 0;

VFI.setDefaultColor(Color.Magenta);
ZeroLine.setDefaultColor(Color.Gray);

# Relative Volume StDev Spike > 2 StDev

input RVlength = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, RVlength)) / StDev(volume, RVlength);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);

plot RVSpike = if IsNaN(close) then Double.NaN
else if RelVol > numDev then 0
else Double.NaN;
RVSpike.SetPaintingStrategy(PaintingStrategy.Points);
RVSpike.SetLineWeight(5);
RVSpike.SetDefaultColor(Color.Green);
AddLabel(!isNaN(RVSpike), "Relative Volume Spike > 2 StDev", Color.Yellow);
# End Volume Flow with Relative Volume StDev Spike > 2 StDev``````

I like this. But your indicator has a setting for "Allow negative values" which is "No" by default. Does this mean that the Volume Flow line will not get into negative numbers (as it should normally) when there is negative/selling volume flow? What I'm asking is should I leave it on "No" or turn it to "yes." Thank you! #### horserider

##### Well-known member
VIP
@dolomick At least for the Relative Volume StDev Spike > 2 StDev the same information can be seen with the hot percent triangle. If you check it will plot at the same bars depending on the % you set.

D

#### dolomick

##### Member
Really enjoying this study and I am trying to add the force index to it, but I am having some problems getting it to display. I can get either the volume flows to display, or the force index, but not both at the same time. I just copied the Force Index code into the Volume Flow with standard deviation code so that is where I am at currently.

Code:
``````# Volume Flow with Relative Volume StDev Spike > 2 StDev
# tomsk
# 1.11.2020

# This study combines the TOS Volume Flow Indicator with the Relative Volume StDev study
# If a spike > 2 standard deviation is detected on the Relative Volume StDev, a GREEN dot is plotted.
# When this event happens, a label is displayed and an audible alert will be generated

declare lower;

# Volume Flow Indicator

input VFlength = 14;
input maxVolumeCutOff = 2.5;

input VFlength2 = 14;

assert(maxVolumeCutOff > 0, "'max volume cut off' must be positive: " + maxVolumeCutOff);

def cutOff = 0.2 * stdev(log(hlc3) - log(hlc3), 30) * close;
def hlcChange = hlc3 - hlc3;
def avgVolume = Average(volume, 50);
def minVolume = Min(volume, avgVolume * maxVolumeCutOff);
def dirVolume = if hlcChange > cutOff
then minVolume
else if hlcChange < -cutOff
then -minVolume
else 0;

plot VFI = ExpAverage(sum(dirVolume, VFlength) / avgVolume, 3);
plot ZeroLine = 0;
plot VFI2 = ExpAverage(sum(dirVolume, VFlength2) / avgVolume, 3);
VFI2.setDefaultColor(Color.Orange);
VFI.setDefaultColor(Color.Magenta);
ZeroLine.setDefaultColor(Color.Gray);

# Relative Volume StDev Spike > 2 StDev

input RVlength = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, RVlength)) / StDev(volume, RVlength);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);

plot RVSpike = if IsNaN(close) then Double.NaN
else if RelVol > numDev then 0
else Double.NaN;
RVSpike.SetPaintingStrategy(PaintingStrategy.Points);
RVSpike.SetLineWeight(5);
RVSpike.SetDefaultColor(Color.Green);
AddLabel(!isNaN(RVSpike), "Relative Volume Spike > 2 StDev", Color.Yellow);
# End Volume Flow with Relative Volume StDev Spike > 2 StDev

#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
# Force Index
# I removed the "declare lower" and changed the length to  "length3" but it is not working.

input length3 = 13;

plot FI = ExpAverage(data = (close - close) * volume, length3);
FI.SetDefaultColor(GetColor(8));`````` #### horserider

##### Well-known member
VIP
Scaling problem. FI scale is compressing the other plots. Try multiplying the FI value by a decimal factor.

D

#### dolomick

##### Member
Scaling problem. FI scale is compressing the other plots. Try multiplying the FI value by a decimal factor.
Tried it and same problem exists. Maybe I'm doing it wrong but it did make the vertical axis numbers change so I think I did it right.

M

#### mashume

##### Active member
VIP
@dolomick -- I replaced the code for the last added indicator (from inputlength3 on...) with this:
Code:
``````input length_force = 13;
input force_mult = 0.0001;
plot FI = ExpAverage(data = (close - close) * volume, length_force) * force_mult;``````
I'm sure there's a more intelligent way to calculate the force_mult so that it would be dynamic, as in my testing I found I occasionally had to change it by an order of magnitude (both larger sometimes and smaller others), but I leave that to you (it's a ratio between the FI values which tend to be very large) and the others (which are many times smaller... usually). I simply decided to make it an input so that I could alter it without having to edit the script.

Hope it helps. And thanks for taking a swing at it yourself. We learn best by doing, eh?

Mashume

P.S. While I found this combination of indicators interesting, can you give some idea of what you were looking for, signals you thought you might find, or any other insight into the process you were going through in tying these together? :-D

Last edited:
D

#### dolomick

##### Member
@mashume Thanks so much. I found volume flow indicator can be a leading indicator and help establish overall trend or help show future direction, but I like to have it set at 9 and 21 volume flow length for a shorter and longer term view of the situation. I found that by adding Force index as an oscillator sort of like the awesome oscillator (set to numerical, then select the vertical lines for the "draw as" input), it allows me to see reversals or "forceful" moves. I pair it with the cumulative delta indicator that has been posted here, and the force index helps me find the reversal points. Another use I have found is that if I see a large force index bar against the prevailing trend, it is often a good scalping opportunity to scalp back in the direction of the prevailing trend. I am fond of volume based indicators as they have almost no lag, and they are generally under-used in my opinion.

• mashume #### horserider

##### Well-known member
VIP
Cannot get this to work correctly. However it will plot the studies together without worrying about changing an input. The main idea of seeing the force index spikes should still work.
Code:
``````script normalizePlot {
input data = close;
input newRngMin =  -1;
input newRngMax = 1;
def hhData = HighestAll( data );
def llData = LowestAll( data );
plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

script fiScale{
input Length3 = 13;
input volume = volume;
input data = close;
def FI = ExpAverage((data - data) * volume, Length3);
plot fis  = FI;
}

plot fis = normalizePlot (fiScale("data" = close , "volume" = volume, "length3" = Length3), -20, 20);``````

• mashume % change watchlist column based on volume and shares? Questions 0