Problem with valueWhen for future reference

#1
I am trying to fetch value from bars that are towards the right of the chart. That means if I am in bar number 10 then I want to fetch the value in bar number 11 and onwards. For example I want to fetch the low of the bar that has high equal to 199.7. I use valueWhen with the third parameter set to 0. It works in most places but fails in others. The code is as below. I have attached the data file of SBI here https://easyupload.io/ezyua0. You can try it in 1 minute timeframe. I have checked in exploration also. for the first instance it is returning null. You can see the trace in pic below. The bar with the yellow dot has high equal to 199.7. It was expected that valueWhen returns low of that bar but instead it returned null. Why?

valueWhenError.png


But later in the chart it starts working. see the picture below.
valueWhenError2.png


Code:
_TRACE("!CLEAR!");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ))) );
PlotOHLC( O, H, L, C, "Traded", colorRed, styleBar , Null, Null, 0, 1, 1);
_SECTION_END();

h1=199.7;
cond=H==h1;
val2=ValueWhen(cond, L, 0);
_TRACE("val2="+val2);

PlotShapes( IIF( cond, shapeSmallCircle, shapeNone), coloryellow, 0, L-ATR(5)); //
Filter=1;
AddColumn(ValueWhen(cond, L, 0), "ValueWhen(H=="+h1+", L, 0)");
 
Last edited:

Romeo1998

Well-Known Member
#2
I am trying to fetch value from bars that are towards the right of the chart. That means if I am in bar number 10 then I want to fetch the value in bar number 11 and onwards. For example I want to fetch the low of the bar that has high equal to 199.7. I use valueWhen with the third parameter set to 0. It works in most places but fails in others. The code is as below. I have attached the data file of SBI here https://easyupload.io/ezyua0. You can try it in 1 minute timeframe. I have checked in exploration also. for the first instance it is returning null. You can see the trace in pic below. The bar with the yellow dot has high equal to 199.7. It was expected that valueWhen returns low of that bar but instead it returned null. Why?

View attachment 45732

But later in the chart it starts working. see the picture below.
View attachment 45733

Code:
_TRACE("!CLEAR!");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ))) );
PlotOHLC( O, H, L, C, "Traded", colorRed, styleBar , Null, Null, 0, 1, 1);
_SECTION_END();

h1=199.7;
cond=H==h1;
val2=ValueWhen(cond, L, 0);
_TRACE("val2="+val2);

PlotShapes( IIF( cond, shapeSmallCircle, shapeNone), coloryellow, 0, L-ATR(5)); //
Filter=1;
AddColumn(ValueWhen(cond, L, 0), "ValueWhen(H=="+h1+", L, 0)");
I think u want output like this :)
good luck :)
1616394462565.png


Code:
_TRACE("!CLEAR!");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ))) );
PlotOHLC( O, H, L, C, "Traded", colorRed, styleBar , Null, Null, 0, 1, 1);
_SECTION_END();

h1=199.7;
cond=H==h1;
val2=ValueWhen(cond, L);
t2 = ValueWhen(cond,TimeNum());
cond2 = TimeNum()==t2;

_TRACE("val2="+val2);

PlotShapes( IIF( cond AND cond2 , shapeSmallCircle, shapeNone), coloryellow, 0, L-ATR(5)); //
Filter=cond AND cond2;
AddColumn(L, "When H=="+h1+",  L = ", 1.2);
 
#3
Thanks for responding romeo But this is not the answer.
Imagine this. The time is 12:00 . Value is computed at 12:00. I refer the bar at 11:00 ref (var, -barRef11) and from here I want the value that was computed at 12:00. It is called refering to future. It is possible with valueWhen with the 3rd parameter set to 0.
This is working in mostly but failing in first 300 odd bars of the chart. Why ?
 
#6
BUG Confirmed in amibroker!!! WORKAROUND FOUND
Workaround is to set the first element of the concerned array variable to 1 or higher. In our case that variable is cond. See the code below.
When this was reported (with supporting code and data) to amibroker support Mr TOMAS JANESKO (developer amibroker) he flat out refused to acknowledge the bug. Mr.TOMAS arrogantly claims there are no defects in Amibroker whereas the truth is something else.
If a limitation is not documented then it is a Bug. Period.


Code:
/*
AMIBROKER AFL ValueWhen(EXPRESSION, ARRAY, n = 1) BUG WORKAROUND
ValueWhen() when used for referencing future (3rd parameter set to 0) does not work for the first occurance of the EXPRESSION
When this was reported with supporting code and data to amibroker support Mr TOMAS JANESKO (developer amibroker) he flat out refused to acknowledge the bug
Mr.TOMAS arrogantly claims there are no defects in Amibroker whereas the truth is something else
*/

_TRACE("!CLEAR!");
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ))) );
PlotOHLC( O, H, L, C, "Traded", colorRed, styleBar , Null, Null, 0, 1, 1);
_SECTION_END();

h1=199.7;
cond=H==h1;
val2=ValueWhen(cond, L, 0);
_TRACE("val2="+val2);

//Due to Bug in amibroker valueWhen() fails for the first occurance of the expression when referencing future
//WORKAROUND set the first element of concerned array variable to 1 or higher
cond[0]=1;
val3=ValueWhen(cond, L, 0);
_TRACE("val3="+val3);


PlotShapes( IIF( cond, shapeSmallCircle, shapeNone), coloryellow, 0, L-ATR(5)); //
Filter=1;

//see the difference between val2 and val3 in exploration
AddColumn(val2, "ValueWhen(H=="+h1+", L, 0)");

AddColumn(val3, "with workaround ValueWhen(H=="+h1+", L, 0)");
valueWhenExplore2.png
 
Last edited:

trash

Well-Known Member
#7
You just proved that you are a completely incompetent dimwit.
Read about Dunning Kruger effect https://en.wikipedia.org/wiki/Dunning–Kruger_effect

ValueWhen does **not** have a bug.
You (and the other two nuts Romeo1998 (again) and optionwriter) just do **not** understand how it works.

Code:
val2=ValueWhen(cond, L, 0);
That line means if there is
Code:
cond == TRUE
then get the Low of the **next** TRUE occurrence of **cond**.

Before the first cond being TRUE there wasn't another TRUE cond so of course val2 becomes **NULL**!

The function tells you already by its name: Give the VALUE WHEN expression is TRUE. What's so hard to understand about it???
So your so called "workaround" is total nonsense (as far as ValueWhen is concerned).

Try understanding picture (if you can):
23.png
 
Last edited:

Romeo1998

Well-Known Member
#8
You just proved that you are a completely incompetent dimwit.
Read about Dunning Kruger effect https://en.wikipedia.org/wiki/Dunning–Kruger_effect

ValueWhen does **not** have a bug.
You (and the other two nuts Romeo1998 (again) and optionwriter) just do **not** understand how it works.

Code:
val2=ValueWhen(cond, L, 0);
That line means if there is
Code:
cond == TRUE
then get the Low of the **next** TRUE occurrence of **cond**.

Before the first cond being TRUE there wasn't another TRUE cond so of course val2 becomes **NULL**!

The function tells you already by its name: Give the VALUE WHEN expression is TRUE. What's so hard to understand about it???
So your so called "workaround" is total nonsense (as far as ValueWhen is concerned).

Try understanding picture (if you can):
View attachment 46044
Hello Sir, how r u ? :)
Thank you for always correcting and guiding us :)
Please take care of you and family, and remain safe from virus :)
My good wishes with u
tenor (28).gif
 
#9
You just proved that you are a completely incompetent dimwit.
Read about Dunning Kruger effect https://en.wikipedia.org/wiki/Dunning–Kruger_effect

ValueWhen does **not** have a bug.
You (and the other two nuts Romeo1998 (again) and optionwriter) just do **not** understand how it works.

Code:
val2=ValueWhen(cond, L, 0);
That line means if there is
Code:
cond == TRUE
then get the Low of the **next** TRUE occurrence of **cond**.

Before the first cond being TRUE there wasn't another TRUE cond so of course val2 becomes **NULL**!

The function tells you already by its name: Give the VALUE WHEN expression is TRUE. What's so hard to understand about it???
So your so called "workaround" is total nonsense (as far as ValueWhen is concerned).

Try understanding picture (if you can):
View attachment 46044
OK agreed that *next* true occurrence means that valuewhen does not work for future references when no true occurrence has occurred yet. But isnt that a limitation? Why the *f*uck was it not documented.
My workaround is perfect and you are a arrogant little *hit that needs a beating.

Without my workaround (for which i should get credit) referencing future values (1st occurrence) using valuewhen is impossible. Prove me wrong if you can u imbecile.
 

Similar threads