Hi,
Below is a short code which demonstrates the use of ValueWhen() in a
Boolean expression with a compressed array creating an uncompressed array.
In the attached picture (which won't show when browsing the Yahoo group)
we can see the compressed arrays cMyHigh and cMyLow only plotting over
the final portion of the chart (because they are compressed, and have
fewer bars than the native timeframe). Prior to this area, they are
{EMPTY}.
However, the boolean expression:
IIf( cMyHigh AND mvw_1, cMyHigh, 0)
creates an array that is not compressed in the same way.
Instead it leads with zeros from the beginning of the chart.
This is despite the fact that only compressed arrays are used in the calc.
Is this normal? Is this appropriate?
Is there a "trick" that can be used so that the expression comes out
with leading zeros in exactly the same size as the compressed array
(cMyHigh, in this case) that when into it, and is {EMPTY} before that?
- Progster
----------------------------------------
/*
HTF_Plot_Test_03.afl
Shows use of ValueWhen() in Boolean expression with a compressed
array creating an uncompressed array.
*/
TFBase = Interval() ;
TFMult = 5 ;
EMA_Length = 20 ;
MyHigh = High ;
MyLow = Low ;
// Plot raw lines on base TF
Plot_Raw = ParamToggle( "Plot_Raw", "No|Yes", 0 );
if(Plot_Raw){
Plot( MyHigh, "MyHigh", colorBlue, styleLine ) ;
Plot( MyLow, "MyLow", colorYellow, styleLine ) ;
}
TimeFrameSet( TFBase * TFMult ) ;
cMyHigh = High ;
cMyLow = Low ;
// Plot compressed HTF lines on base TF
/* The results of this is not sensical in absolute terms, but if you
disregard date/time
you can visually examine collections of such compressed plots to
verify the relationships
between them.
*/
Plot_HTF_Comp = ParamToggle( "Plot_HTF_Comp", "No|Yes", 1 );
if(Plot_HTF_Comp){
Plot( cMyHigh, "cMyHigh", colorRed, styleLine ) ;
Plot( cMyLow, "cMyLow", colorWhite, styleLine ) ;
}
// Plot the results of ValueWhen() statements
Plot_ValueWhen = ParamToggle( "Plot_ValueWhen", "No|Yes", 0 );
if(Plot_ValueWhen){
mvw_1 = ValueWhen( (cMyHigh - Ref(cMyHigh, -1)) > 5, 1, 1 ) ;
// 1, after the first instance match
Plot( IIf( cMyHigh AND mvw_1, CMyHigh, 0), "cMyHigh AND mvw_1",
colorViolet, styleThick ) ;
}
TimeFrameRestore() ;