I am using the below AFL and I couldn't figure out why I am getting ïnf. Trying to understand where I went wrong.

```
// Average Delivery PercentS
DQ = (Aux2/Volume)*100;
Avg21 = Ref(MA(DQ,21),-1);
Filter = 1.2;
AddColumn( Aux2 , "Delivery", 1 );
AddColumn( Volume , "Volume", 1 );
AddColumn( DQ , "Percentage", 1.2 );
AddColumn( Avg21 , "AvgVolume",1.2 );
```

Thank you

Somewhere along those last 21 bars that you are averaging, you have INFINITY along the way (due to **division by zero** volume). You should look at the volumes of ALL 21 bars not only the last one.

1 Like

As you can see in the attached screenshot there are no zero volumes in the last 21 bars. Going through the previous posts in the forum used the Nz function and it solved the problem. But I still don't understand what caused the problem.

```
`type or paste code here// Average Delivery PercentS
DQ = (Aux2/Volume)*100;
Avg21 = Ref(MA(Nz(DQ),21),-1);
Filter = 1.2;
AddColumn( Aux2 , "Delivery", 1 );
AddColumn( Volume , "Volume", 1 );
AddColumn( DQ , "Percentage", 1.2 );
AddColumn( Avg21 , "AvgVolume",1.2 );
```

Thank you.

Debugging your own data is YOUR PROBLEM, not anybody else.

Do you know what Nz does? It replaces Nulls and all kind of Not-A-Number, Infinity and all that kind of stuff.

If Nz helps it means that you have Nulls, Nans or Inf in DQ, and Inf in DQ is result of division by zero. You might also have some nonsensical data in Aux2 as well.

**Nz is NOT solution, it is HIDING THE PROBLEM**.

Fix YOUR DATA, don't hide the problems.

Use Quote Editor to look at the data you have. You must have ZERO VOLUME somewhere in your data.

If it easy to check:

Use RANGE "All quotes" and

```
Filter = Volume == 0;
```

If you divide by zero you get infinity.

You should better use SafeDivide function if your denominator gets to zero.

4 Likes