ADX() function returns infinite value

I cannot figure out why this adx() function return inf only in my 5 minute timeframe, and only for this 1 stock: Agilent Technologies. If I use any other timeframes, I won't get the inf to show up, if I change to a different symbol and run it on the 5 minute timeframe, I won't get the inf to show up. It only happens at this particular stock and at the 5 minute time frame. Why ???

// For debugging ...
if(Status("ActionEx") == actionExplore){
		Filter = 1;
		AddTextColumn(FullName(), "Ticker Name");
		AddColumn(O, "Open", 1.2);
		AddColumn(H, "High", 1.2);
		AddColumn(L, "Low", 1.2);
		AddColumn(C, "Close", 1.2);
		AddColumn(ADX(14), "ADX(14)", 1.2);
		AddColumn(PDI(14), "PDI(14)", 1.2);
		AddColumn(MDI(14), "MDI(14)", 1.2);
}

ADX 2

ADX 1

Any help will be greatly appreciated, thanks.

It is because HLC are equal for certain period within array (as you can see in your output).
ADX uses true range in its caclulations. So it becomes zero at those array indexes. Then TR (sum) is used as denominator. So it becomes division by zero.

So use Nz() convert to zero then.

if(Status("ActionEx") == actionExplore){
		Filter = 1;
		AddTextColumn(FullName(), "Ticker Name");
		AddColumn(O, "Open", 1.2);
		AddColumn(H, "High", 1.2);
		AddColumn(L, "Low", 1.2);
		AddColumn(C, "Close", 1.2);
		AddColumn(Nz(ADX(14)), "ADX(14)", 1.2);
		AddColumn(Nz(PDI(14)), "PDI(14)", 1.2);
		AddColumn(Nz(MDI(14)), "MDI(14)", 1.2);
}
1 Like

Thank you kindly fxshrat. I tried running the same ticker in a different period range, with HLC not equal and I still get the inf values. btw, if I plot the ADX(14) instead as a plot in the 5 minute chart, I won't get any inf error message at all, I got a beautiful graph.

ADX 3

As I said, it only happen at this particular stock, A, and at the 5 minute timeframe.

If I plot the ADX() function instead, in the 5 minute chart, I don't get the inf error.

ADX 5

function EqualToNull(array) {
	return IIf(array==Ref(array,-1), Null, array);
}

H = EqualToNull(H);
L = EqualToNull(L);
C = EqualToNull(C);

_adx = ADX(14);
_pdi = PDI(14);
_mdi = MDI(14);

RestorePriceArrays();


if(Status("ActionEx") == actionExplore){
		Filter = 1;
		AddTextColumn(FullName(), "Ticker Name");
		AddColumn(O, "Open", 1.2);
		AddColumn(H, "High", 1.2);
		AddColumn(L, "Low", 1.2);
		AddColumn(C, "Close", 1.2);
		AddColumn(_adx, "ADX(14)", 1.2);
		AddColumn(_pdi, "PDI(14)", 1.2);
		AddColumn(_mdi, "MDI(14)", 1.2);
}

Because it is partial array, see QuickAFL.

1 Like

Thank you ! now it is working great, thank you again.

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