Hello,
That is CORRECT behavior.
Every AFL function SKIPS all NULLs that appear in the beginning of any argument array.
Best regards,
Tomasz Janeczko
amibroker.com
>From AB Help
SYNTAX ValueWhen(EXPRESSION, ARRAY, n = 1)
RETURNS ARRAY
FUNCTION Returns the value of the ARRAY when the EXPRESSION was true on the n -th most recent occurrence.
Note: this function allows also 0 and negative values for n - this enables referencing future
It says "Returns the value of the ARRAY when the EXPRESSION was true"
but when array has NULL values, valuewhen will never return NULL value after first time EXPRESSION is true
The code below demonstrate that
===================================================
SetBarsRequired(sbrAll);
===================================================
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
bi = BarIndex();
XLong = (bi % 100) == 0;
XShort = ((bi+50) % 100) == 0;
Plot(XLong, "XLong", colorGreen, styleHistogram | styleOwnScale);
Plot(XShort, "XShort", colorRed, styleHistogram | styleOwnScale);
// else zero
zLongEntry = IIf(XLong, C, 0);
zShortEntry = IIf(XShort, C, 0);
// else NULL
nLongEntry = IIf(XLong, C, Null);
nShortEntry = IIf(XShort, C, Null);
ncond = NOT (IsNull(nShortEntry) AND IsNull(nLongEntry));
zcond = zLongEntry > 0 OR zShortEntry > 0;
zL = ValueWhen( zcond, zLongEntry);
zS = ValueWhen( zcond, zShortEntry);
nL = ValueWhen( ncond, nLongEntry);
nS = ValueWhen( ncond, nShortEntry);
Plot(nL, "\nnullLong", colorGreen, styleNoLine | styleOwnScale | styleNoLabel);
Plot(nS, "nullShort", colorRed, styleNoLine | styleOwnScale | styleNoLabel);
Plot(zL, "\nzeroLong", colorGreen, styleNoLine | styleOwnScale | styleNoLabel);
Plot(zS, "zeroShort", colorRed, styleNoLine | styleOwnScale | styleNoLabel);
Plot(ncond, "\nncond", colorGreen, styleNoLine | styleOwnScale | styleNoLabel);
Plot(zcond, "zcond", colorRed, styleNoLine | styleOwnScale | styleNoLabel);
if select bar is placed after a green vertical line (XLong is true) I expect to see
nullShort == NULL and zeroShort == 0
but instead I get
nullShort == (number) and zeroShort == 0
Anyone ?
Posted by: Tomasz Janeczko <groups@amibroker.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (5) |
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
EmoticonEmoticon