andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 15:03:38 GMT
Not sure where to post this! From AB Help 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 Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
bi = BarIndex();
XLong = (bi % 200) == 0; XShort = ((bi+100) % 200) == 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);
zL = ValueWhen( zLongEntry > 0 || zShortEntry > 0, zLongEntry); zS = ValueWhen( zLongEntry > 0 || zShortEntry > 0, zShortEntry); nL = ValueWhen( !IsNull(nShortEntry) || !IsNull(nLongEntry), nLongEntry); nS = ValueWhen( !IsNull(nShortEntry) || !IsNull(nLongEntry), 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);
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 _ Did I miss somethig ?
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 15:05:20 GMT
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 6, 2016 16:28:48 GMT
If you write this
zS = ValueWhen( zShortEntry > 0, zShortEntry); nS = ValueWhen( !IsNull(nShortEntry), nShortEntry);
Then both return value.
If you write this
zS = ValueWhen( zLongEntry > 0, zShortEntry); nS = ValueWhen( !IsNull(nLongEntry), nShortEntry);
then 1st one returns zero, 2nd one returns empty.
if you write this
zS = ValueWhen( zLongEntry > 0 OR zShortEntry > 0, zShortEntry); nS = ValueWhen( !IsNull(nLongEntry) OR !IsNull(nShortEntry), nShortEntry);
Then first returns zero, 2nd one returns value.
If you write this
zS = ValueWhen( zLongEntry > 0 OR zShortEntry > 0, zShortEntry); nS = ValueWhen( !(IsNull(nLongEntry) OR IsNull(nShortEntry)), nShortEntry);
Then 1st returns zero, 2nd one returns empty.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 6, 2016 16:32:29 GMT
In the third one I actually expect both returning a value since 1st example (short check only) returns value for both (ValueWhen keeps true occurrence). But instead in the third one 1st line returns zero.
I'm a bit puzzled myself.
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 16:35:17 GMT
Thank you , I complete miss the NOT OR NOT in expression but still do not get what I expect
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 17:06:57 GMT
I still does not understand
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)) OR (NOT IsNull(nLongEntry)); zcond = zLongEntry > 0 || 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);
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 6, 2016 18:06:19 GMT
Anderson,
I'm puzzled too. Try AB support.
For this one
zcond = zLongEntry > 0 || zShortEntry > 0;
I actually expected value output larger than zero since it is "OR" and zShortEntry > 0 being true if you apply it alone without the other condition. So I don't understand the zero output if ValueWhen is used.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 6, 2016 21:30:39 GMT
AndWilson, why do you expect Null for nS = ValueWhen( ncond, nShortEntry) ?
The logical link is OR not AND.
Since nS = ValueWhen( !IsNull(nShortEntry), nShortEntry) returns true and nS = ValueWhen( !IsNull(nLongEntry), nShortEntry) returns false So it is ... = true OR false. So it returns value.
On the other hand the actual result I do not understand is why does
zS = ValueWhen( zLongEntry > 0 OR zShortEntry > 0, zShortEntry) return zero? Since ValueWhen( zShortEntry > 0, zShortEntry) returns true and as such returns value so the former one (zLongEntry > 0 OR zShortEntry > 0) should return value also since the linking is OR and one condition returning true.
So that's the actual one I do not understand.
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 21:40:30 GMT
fxshrat
zS = ValueWhen( zLongEntry > 0 OR zShortEntry > 0, zShortEntry) return zero?
returns zero because whenever zLongEntry > 0 , zShortEntry will be zero and when zShortEntry > 0 , zLongEntry will be zero
|
|
andwilson
Private Group
Posts: 43
Received Likes: 13
|
Post by andwilson on May 6, 2016 21:56:04 GMT
Using NULL values I expected the chart at the bottom, but what I get is the top one, continuous lines 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 NULL nLongEntry = IIf(XLong, C, Null); nShortEntry = IIf(XShort, C, Null);
ncond = NOT (IsNull(nShortEntry) AND IsNull(nLongEntry));
nL = ValueWhen( ncond, nLongEntry); nS = ValueWhen( ncond, nShortEntry);
Plot(nL, "\nnullLong", colorGreen, styleDashed | styleThick); Plot(nS, "nullShort", colorRed, styleDashed | styleThick);
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);
zcond = zLongEntry > 0 OR zShortEntry > 0;
zL = ValueWhen( zcond, zLongEntry); zS = ValueWhen( zcond, zShortEntry);
zL = IIf(zL > 0, zL, Null); zS = IIf(zS > 0, zS, Null);
Plot(zL, "\nzeroLong", colorGreen, styleDashed | styleThick); Plot(zS, "zeroShort", colorRed, styleDashed | styleThick);
|
|