The error is not in the code you have displayed - its earlier.

If your denominator is zero, you can add small value to denominator such as:

+1e-9

Search the forum (use magnifying glass in upper right corner) to find already existing solutions first as there are many posts & solutions about - Warning 505

This particular division has VOLUME in the denominator. If you apply such indicator to data without volume (such as for example currencies or some indices) then you will divide by zero.

There are also other problems with this code (using obsolete graph0 reserved variable and Plot at the same time - you should NOT do that). If you are using Plot() function (correct) you should NOT be using graph0 reserved variable.

Proper formula would look like this:

function CMF(r1)
{
nom = Sum( V * ( ( C-L )-( H-C )) / ( H-L ), r1);
denom = Sum( V, r1 ); // this can be zero if there is no volume in data
eps = 1e-9; // small value to prevent division by zero in case when volume is zero
ind = nom / (eps + denom);
dynamic_color = IIf( ind> 0, colorGreen, colorRed );
Plot( ind, "Chaikin Money Flow ("+r1+")", dynamic_color, styleHistogram | styleThick);
}