# HHV-LLV div by zero

Hi

Whenever I use the HHV-LLV to compute stochastic I get div by zero error
I have got this on different scenarios
I have searched for the existing topics, and I saw SafeDivide as a suggestion
My question is if I am using obsolete syntax perhaps
Looking at the chart for %FVX it should not be evaluating the denominator zero I think, so I thought it is a mistake in my code

``````// IntermarketFiveYearNoteBasic.afl
//
// The BuyPrice and SellPrice come from the
SellPrice = C;
// The indicators and signals are computed from the
// Five Year Note, Yahoo Ticker "FVX
ForeignC = Foreign("%FVX","C");
// Compute the RSI
ForeignRSI = RSIa(ForeignC,15);
// Compute the Stochastic of the ForeignRSI
ForeignStochRSI = 100 * (ForeignRSI - LLV(ForeignRSI,24)) / (HHV(ForeignRSI,24) - LLV(ForeignRSI,24));
ForeignStochRSI = EMA(ForeignStochRSI,3);
// The Buy and Sell signals will be taken from the
// crossing of the StochRSI indicator with itself, smoothed
Sm = Param("Sm",3,1,100,1);
FStRSISm = DEMA(ForeignStochRSI,Sm);
Sell= Cross(FStRSISm,ForeignStochRSI);
e = Equity();
// Plotting the "current symbol"
Plot(C,"C",colorBlack,styleCandle);
// Plotting the indicator created from the Five Year Note
Plot(ForeignStochRSI,"FStRSI",colorRed,styleline |styleLeftAxisScale);
Plot(FStRSISm,"FStRSISm",colorGreen, styleLine| styleLeftAxisScale);
// Plotting the equity of trading the
// current symbol based on the Five Year Note
Plot(e,"Equity",colorRed,styleline |styleOwnScale);
GraphXSpace = 10;
``````

You need to check divisor to prevent division by zero or use SafeDivide function.

Also please always do a SEARCH before posting:
https://forum.amibroker.com/search?q=SafeDivide
https://forum.amibroker.com/search?q=division%20by%20zero

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.