# Indicator - Trade Volume / Ticks using DataN

Questions about MultiCharts and user contributed studies.
x3p0
Posts: 9
Joined: 29 Feb 2008
Contact:

### Indicator - Trade Volume / Ticks using DataN

Hi Everyone,

I am trying to build an indicator that should plot the average volume per up tick in a given bar (5 min chart). Given that ticks and volunes are defined in the "volume based on", I have two datas:
Data1 - volume based on ticks
Data2 - volume based on trade volume

I can compile the code below without any error, but when I insert the indicator on the chart, I get an error message. Is there any point I am missing? Tks

variables: var1(0),var2(0),var3(0);

var1 = UpTicks of data1;
var2 = UpTicks of data2;
var3 = var2/var1;

plot1(var1,"1");
plot2(var2,"2");
plot3(var3,"3");

TJ
Posts: 7098
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2029 times

a screen shot would help.
Last edited by TJ on 25 Aug 2008, edited 1 time in total.

TJ
Posts: 7098
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2029 times
if you do not get an uptick on a bar, you will have a division by zero error.

x3p0
Posts: 9
Joined: 29 Feb 2008
Contact:
That's so obvious.... How haven't I thougt about before????
You solved the problem.
thanks!

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times
replace var3 with something like this:

if var1 <> 0 then var3 = var2/var1 else var3 = var2/var1[1];
it won't be 100% accurate when var1 = 0 but it might be close enough.
You could also use the prev value of val3 when var1 = 0;
Whenever doing a division, make sure the denominator can't be zero.

A tip from a programmer friend of mine- When working with multiple data streams, set the variable to zero of the data stream being referenced - example.
var2(0,data2);