Differences between charting and explore with AMA

When I use the following code in a chart it calculates a value correctly, however when I use it in an explore for some (but not all) tickers it calculates a value of “inf”.

fast = 2/(2+1);
slow = 2/(30+1);
dir=abs(close-ref(close,-10));
vol=sum(abs(close-ref(close,-1)),10);
ER=dir/vol;
sc =( ER*(fast-slow)+slow)^2;KAMA = ama( close, sc ); 
Plot( C, "Close", colorblack , styleLine );
Plot( KAMA, "KAMA", ParamColor( "Color", colorYellow ), styleLine );
Filter=True;
AddColumn(KAMA,"KAMA");
AddColumn(SC,"SC");
AddColumn(dir,"Direction");
AddColumn(vol,"Volatility");
AddColumn(ER,"EfficiencyRatio");
AddColumn(isnan(kama),"BadKama");
AddColumn(fast,"fast");
AddColumn(slow,"slow");
AddColumn(close,"close");

Sample for ticker XXII on 16 Sep, 2022
image

Explore Output
|Ticker|Date/Time|KAMA|SC |Direction|Volatility|EfficiencyRatio|BadKama|fast |slow|close|
|XXII 16/09/2022 inf 0.04 0.11| 0.49| 0.22| 0.67 0.06| 1.23|
Another anomaly. Using isnan(Kama) returns null rather than the expected true
QuickAFL is enabled for both chart and analysis

@kfbfnet, if the price is stale (same) for 10 days (your selected period) both the dir and vol will be zero so the ER=dir/vol; will return inf.

You could try to obviate it with the NZ() function:

// Converts Null/Nan/Infinity values to zero (or user defined value)
ER=NZ(dir/vol);

(but this may not be the correct way to address the problem by this specific indicator).

By the way, I see the same result both in exploration and in the chart (if you zoom enough to encompass the exploration range).

Please, check the function IsFinite() to use in your exploartion instead of IsNan().

1 Like

Hi Beppe,

Thanks for that insight. It appears that in batch if any incidence of EC is inf, it effects all subsequent values but not (at least for me) in the chart even when I expand the display to months.
image
I'm on V 6.40.4 are you on the same?

Your solution of use of NZ() seems to do the trick though.

Thanks for your help

@kfbfnet I think the difference is due to the fact that when I tested the code I had the QuickAFL disabled in the exploration settings.
Testing with a previous version (6.30.5 - 32bit) will result differently in the exploration: instead of inf the "bad" KAMA values are null.

AMA is recursive calculation (infinite response filter). Any bad values anywhere (like infinity) would propagate / affect all subsequent bars. Therefore you must remove bad values before feeding them to AMA.

1 Like

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