Adding two StaticVar with array containing Null value and numbers

I try to add two StaticVar containing Null values and numbers from two charts (the same symbol and interval), something like this:
"StaticVar1": 20,null,-10,0,null,6,0
"StaticVar2": null,2,0,-5,0,null
But I get array with values -20 000 000 000.
Values 0 are very important, that I can't use Nz().
How can I do this properly?

What value were you hoping to get when you add 20 + null?

You are right. I was wrong. I was thinking that null+null=null :slight_smile:

@jcorniko, I will do something like:

ab = IIf( IsNull(a) OR IsNull(b), Null, a + b);

(a and b are 2 arrays)


thanks, this is it! :heart:

Null + Null should give you Null that how Nulls are supposed to work, see:

x = Null;
y = Null;

z = x + y;

printf("What you get is " + z );

But the question is as always: WHAT FORMULA did you use to add static variables?

Rememer: ALWAYS to include the formula. Please follow this advice: How to ask a good question

Please note that embedding Nulls anywhere else than at the beginning of the array is NOT expected by default. If you manually embedded Nulls in the middle, you have to instruct AmIBroker to watch for them using option:

SetOption("EveryBarNullCheck", True );

Otherwise it will check for Nulls only at the beginning of the array when Nulls are expected (due to the nature of array functions that may return Nulls until first value is available)

As per User manual: AFL Function Reference - SETOPTION

EveryBarNullCheck - allows to turn on checking for Nulls in arithmetic operations on every bar in the array(by default it is OFF - i.e. AmiBroker checks for nulls that appear in the beginning of the arrayand in the end of the array and once non-null value is detected it assumes no further holes (nulls) in the middle). Turning "EveryBarNullCheck" to True allows to extend these checks to each and every barwhich is the way 4.74.x and earlier versions worked.
Note however that turning it on gives huge performance penalty (arithmetic operations are performed even 4x slower when this option is ON, so don't use it unless you really have to).

As manual says, such Nulls placed randomly in the middle of arrays are not checked by default for speed reasons (because checking for them prevents SSE2/AVX vectorization).

Plot( Close, "", Colorblack, styleBar );

cond1 = IIf( Close > Ref( Close, -5 ), 1, Null );
Plot( cond1, "cond", colorpalegreen, styleHistogram + styleOwnScale );
StaticVarSet( "sv1", cond1 );
StaticVarSet( "sv2", cond1 );

v1 = StaticVarGet( "sv1" ) + StaticVarGet( "sv2" );
Plot( v1, "v1", colorRed, styleHistogram + styleLeftAxisScale );

Real solution: SetOption("EveryBarNullCheck", True );

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