Issue: I'm getting a -nan(ind) returned when running ADX(7) in an exploration for a few US tickers (e.g. FNB), though it plots fine on a chart. For most other tickers it works fine in exploration.
Context:
Revalidating an old EOD system using AmiBroker 6.3 and Norgate Platinum (US stocks).
AFL code unchanged; database rebuilt from scratch from Norgate
90% signals match exactly, investigating discrepencies
FNB appears to have the same data as before.
DB settings same: 10,000 bars, no padding, Capital Reconstructions enabled.
Question:
Given that ADX(7) for FNB used to be successfully output on exploration, but now returns -nan, , what could be causing this? Any tips on narrowing it down?
If anyone has Norgate Platinum data, it would help my investigation if you could run this exploration on FNB and see if you get any values in ADX(7). Thanks.
NaN is "not a number". It is typically result of operation such as 0/0 or infinity/infinity or square root from negative number.
The ADX (Average Directional Index) indicator may produce NaN (Not a Number) results due to a division by zero, specifically from a 0/0 situation that might occur in FLAT market.
Here's why and how that happens:
ADX Formula Summary
The ADX is based on the Directional Movement Index (DMI) system, which involves these components:
Numerator: |0 - 0| = 0
Denominator: 0 + 0 = 0
➡️ This leads to 0 / 0, which is undefined, i.e., NaN.
This can happen during periods of no price movement (flat market), or when you have PADDING turned ON and your data has huge holes that get filled by previous bar close price leading to "flat" region (no price movement)
Thanks Tomasz,
My system uses ADX(7) as a filter. Because it generated a signal in the past for FNB, and the code hasn't changed, I am working on the assumption there is a setting I've missed that would account for it. My Norgate plugin has No Padding set. I'm using Amibroker 6.3 and can't find any padding-related setting that might influence this. I know that I can change the AFL code to handle the problem, but that isn't what I'm trying to achieve. I'm trying to replicate past signals to assure the integrity of my set up.
Are there any Amibroker settings that would affect how ADX behaves?
I have found a backup of the entire Amibroker folder from 2019. Are the general settings accessible in a file? If so, I could compare them with my current setup.
Securities like FNB had rather illiquid periods in the history (the early 1990s show this - many days of no change) so using ADX on a short time period is likely to cause these issues.
I'd say your previous backtest was run on a period where it didn't go back so far.
In addition to the Nz function, you may want to incorporate a liquidity filter too.