Hi Howard,
I have used the valuewhen function but the output data is disorganized and sometimes incorrect. I am using the following AFL code with the Explore utility:
Code:Filter=1; AddColumn(O,"Open", 1.6); AddColumn(H,"High", 1.6); AddColumn(L,"Low", 1.6); AddColumn(C,"Close", 1.6); /*AddColumn(V,"Volume",1.0); AddColumn(OI,"Open Interest",1.0); */ AddColumn(TimeFrameGetPrice("H",inDaily,0), "HHV", 1.6); AddColumn(ValueWhen(TimeFrameGetPrice("H",inDaily,0)==H, DateTime()), "Date/Time", formatDateTime);
The have set the Explore utility on a 5-min periodicity under 'General settings' as I want the result to return which 5 min bar the daily high had occurred on.
This is an example of the output data:
View attachment 61235
From the example above, it seems as though the DateTime() function is waiting for the Explore utility to actually reach the correct bar before it prints the correct data. I am not sure why it is doing this when it should already have the correct data when it compared the High array to the TimeFrameGetPrice array.
How can I fix this?
Cheers
Output value of Valuewhen is constant till a new true conditions appears. Then new constant value steps in based on that new true condition.
Code:
Filter = 1;
AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */
DH = TimeFrameGetPrice( "H", inDaily, 0 );
AddColumn( ValueWhen( DH == H, H ), "HHV", 1.6 );
AddColumn( ValueWhen( DH == H, DateTime() ), "Date/Time", formatDateTime );
But if you just wanna have output of datetimes where high of day occurred you don't need to use that code and valuewhen. Simply set Filter = H == DH; as seen in my example.