I am having an issue with an AFL where I am calculation the ratio between two numbers. In essence, I am looking for the ratio of stocks that are up 25% in the quarter to stocks that are down 25% in the quarter. I have been able to successfully create a plot of each of the numbers (i.e. chart showing the number of stocks up 25% in the quarter). However, when I try to use AddtoComposite with a PlotForeign on the ratio, I keep getting no results. I do get the 505 warning, and have added +1e-9 to the denominator but that does not seem to help. I can't seem to figure out what I am doing wrong after scouring this site and reading the knowledge base and other areas.

I run this code as an explore and then want to use the foreign symbol created to plot the ratio on a chart. On the chart, the values are all -nan(ind), even with the +1e-9.

Looking to the experts on the forum here for help with what I am doing wrong.

//Market Monitor - 25% Quarterly Ratio
//Run as Explore going back for 4-months; apply chart
//Ratio of the 25% Up in QTR and 25% Down in QTR
Ratio25 = ((100 * ((Close - LLV(Close, 63)) / LLV(Close, 63)) >= 25 AND MA(Close, 20) * MA(Volume, 20) >=250000))
/ (((100+1e-9) * ((Close - HHV(Close, 63)) / HHV(Close, 63)) <= (-25) AND MA(Close, 20) * MA(Volume, 20) >=250000));
AddToComposite(Ratio25, "~~25%QtrRatio", "C", atcFlagEnableInExplore | atcFlagResetValues );
PlotForeign("~~25%QtrRatio", "25% Up/Down Ratio", colorGreen, styleLine | styleDots);```

Make a cleaner code to see the light at the end of the tunnel.
And you should rather store numerator and denominator to separate fields and then in the end via SetForeign calculating Ratio. Otherwise you would get wrong ratio.

Now it should work.

//Market Monitor - 25% Quarterly Ratio
//Run as Explore going back for 4-months; apply chart
//Ratio of the 25% Up in QTR and 25% Down in QTR
ma_cond = MA(Close*V, 20) >= 25000;
hh = HHV(Close, 63);
ll = LLV(Close, 63);
num = 100 * (C - ll) / ll >= 25 AND ma_cond;
denom = 100 * (C - hh) / hh <= -25 AND ma_cond;
AddToComposite(num, atcname = "~~25%QtrRatio", "H", flags = atcFlagEnableInExplore | atcFlagResetValues );
AddToComposite(denom, atcname, "L", flags );
SetForeign(atcname, 2);
Ratio25 = Nz(H / L);
RestorePriceArrays();
Plot( Ratio25, "25% Up/Down Ratio", colorGreen, styleLine | styleDots );

Thank you so much - Iām new to coding having only dabbled starting in my 40ās. Help is much appreciated - I have learned a lot just by looking at that code and how you have organized it. Thanks again for the help.