Getting strange -9.999999e+09 values in shifted arrays instead of "Null"

( using Version 6.38.0 x64 )

Hello everyone,
I am getting some strange -9.999999e+09 values in my arrays when executing the code below. From values of 0 to 511 for the variable lengthA/lengthB, everything is working fine and I am getting either the value "Null" or the actual bar index numbers of the highs I am trying to find, as a result in the arrays. In the arrays: hhvPeakBarsX1, hhvPeakAvailFromBarsX1, hhvPeakBarsCompX1 and hhvPeakAvailFromBarsCompX1 you can see that everything is fine as it should be, either "Null" or the bar index number of the found highs.

But for values of lengthA > 511 its different, thats why I included a second version of the code with lengthB == 512.
In the arrays: hhvPeakAvailFromBarsX2 and hhvPeakAvailFromBarsCompX2 you can see that I get these strange -9.999999e+09 values instead of "Null" values, please look at the screenshots.
It also happens for other values of lengthA/lengthB > 512 like 513, 514, 515 etc...

These -9.999999e+09 values mess up the neat compressed array hhvPeakAvailFromBarsCompX2 and the not compressed array hhvPeakAvailFromBarsX2 as you can see in the screenshots.

Why does this happen for values of lengthA/lengthB >= 512 and how can I avoid this happening so that I can get my highs compressed at the end of the compressed arrays like for hhvPeakAvailFromBarsX1 and hhvPeakAvailFromBarsCompX1 where lengthA/lengthB is <= 511 ? thanks a lot for your help

In my understanding adding or subtracting any value to or from "Null" value should result in "Null" value again and not in -9-999999e+09.
And If I used 0 instead of "Null" value in hhvPeakBarsX, I cannot shift my arrays the way I do for hhvPeakAvailFromBarsX because adding or subtracting anything from 0 results in a different number than 0.

bi = BarIndex();

a = 1;
lengthA = 511;

VarSet( "hhvPeakBarsX" + a, IIf( Ref( HHVBars( H, ( lengthA * 2 ) + 1 ) == lengthA, lengthA ) && bi >= lengthA, bi, Null ) );
VarSet( "hhvPeakAvailFromBarsX" + a, Ref( VarGet( "hhvPeakBarsX" + a ), - lengthA ) + lengthA );
VarSet( "hhvPeakBarsCompX" + a, SparseCompress( VarGet( "hhvPeakBarsX" + a ), VarGet( "hhvPeakBarsX" + a ) ) );
VarSet( "hhvPeakAvailFromBarsCompX" + a, SparseCompress( VarGet( "hhvPeakAvailFromBarsX" + a ), VarGet( "hhvPeakAvailFromBarsX" + a ) ) );

b = 2;
lengthB = 512;

VarSet( "hhvPeakBarsX" + b, IIf( Ref( HHVBars( H, ( lengthB * 2 ) + 1 ) == lengthB, lengthB ) && bi >= lengthB, bi, Null ) );
VarSet( "hhvPeakAvailFromBarsX" + b, Ref( VarGet( "hhvPeakBarsX" + b ), - lengthB ) + lengthB );
VarSet( "hhvPeakBarsCompX" + b, SparseCompress( VarGet( "hhvPeakBarsX" + b ), VarGet( "hhvPeakBarsX" + b ) ) );
VarSet( "hhvPeakAvailFromBarsCompX" + b, SparseCompress( VarGet( "hhvPeakAvailFromBarsX" + b ), VarGet( "hhvPeakAvailFromBarsX" + b ) ) );

strange999999_001 strange999999_002

There isn't anything strange in AmiBroker.

It is your code. And AB is doing what you tell it.

Null is -1e10.
You add e.g. lengthB to Ref( VarGet( "hhvPeakBarsX" + b ), - lengthB ).
So if hhvPeakBarsX is Null then you get that number of your picture.

BTW, first argument of SparseCompress should be true/false array (returning zero or one). Right now there's not any like that.

1 Like
  1. so why does it give me Null values when lengthA/lengthB is anything from 0 to 511 and -9.999999e+09 when lengthA/lengthB is >= 512 ?

  2. because I get these -9.999999e+09 values and not Null, SparseCompress gives me the messed up arrays which I cannot use for further processing. So how do I avoid this happening ???

  3. when I add any number to Null it gives me Null for a normal variable and not -9.999999e+09 so why not in this case ?

It occurs when you add something to Null elements that are in between two non-Null elements.

Filter = 1;

bi = BarIndex();
lengthB = 512;

AddColumn(IIf(bi%2==0, 0, Null)+lengthB,"1", 1);
AddColumn(IIf(bi%2==1, 0, Null)+lengthB,"2", 1);
AddColumn(IIf(bi>=0 AND bi<10, Null, 0)+lengthB,"3", 1);
AddColumn(IIf(bi> 0 AND bi<10, Null, 0)+lengthB,"4", 1);
AddColumn(IIf(bi>10 AND bi<BarCount-1, Null, 0)+lengthB,"5", 1);
AddColumn(IIf(bi>10, Null, 0)+lengthB,"6", 1);


Simply do as been told and check for true/false condition and add when not Null.
Simple as that.

lengthB = 512;

hhvbars2 = Ref(HHVBars(H, lengthB * 2 + 1) == lengthB, lengthB);
hhvPeakBarsX2 = IIf(hhvbars2 AND bi >= lengthB, bi, Null );
hhvPeakAvailFromBarsX2 = Ref(hhvPeakBarsX2, -lengthB);
hhvPeakBarsCompX2 = SparseCompress(!IsNull(hhvPeakBarsX2), hhvPeakBarsX2);
hhvPeakAvailFromBarsCompX2 = SparseCompress(!IsNull(hhvPeakAvailFromBarsX2), hhvPeakAvailFromBarsX2+lengthB);

So similar for first code:

Filter = 1;

bi = BarIndex();
lengthB = 512;

AddColumn(IIf(bi%2==0, lengthB, Null),"1", 1);
AddColumn(IIf(bi%2==1, lengthB, Null),"2", 1);
AddColumn(IIf(bi>=0 AND bi<10, Null, lengthB),"3", 1);
AddColumn(IIf(bi> 0 AND bi<10, Null, lengthB),"4", 1);
AddColumn(IIf(bi>10 AND bi<BarCount-1, Null, lengthB),"5", 1);
AddColumn(IIf(bi>10, Null, lengthB),"6", 1);


1 Like

@fxshrat already provided almost all information, so just a few words
why is so:
Null is supposed to be present ONLY at the beginning of the array.
And AmiBroker only checks for Nulls at the beginning.
After first non-null element, it does not check, because such checks are very expensive performance wise (since any check involves "if" statement and as many ifs as elements in array, "if" translates to processor jump and jumps are bad since they take at least 3x more time than addition).

AmiBroker functions (except SparseExpand and deliberate IIF with Nulls) would never give you Null anywhere else than in the beginning.

If you are deliberately creating arrays with Nulls in the middle and expect Nulls in the middle to be checked you have to use:

SetOption("EveryBarNullCheck", True );

This has performance cost that every array arithmetic operator is 2-3 times slower.


Thanks a lot, this solved my problem (; always much appreciated, especially notes about performance and efficiency.

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