Hi,
I want to explore for:
filter = (cumVolume at peak) - (cumVolume at previous peak) > 0;
Should be an easy one for the AB experts. Here’s the code, thanks.
function SumSince2( condition, array )
{
CumA = Cum( array );
return CumA - ValueWhen( condition, CumA ) + ValueWhen( condition, array ) ;
}
optimizerSetEngine("cmae");
z =param("1",2,.0001,2,.000001) ;
// count bars since last peak or trough
pkb = PeakBars( c, z ); //BarsSince(z)-3;//
trb = TroughBars( c, z ); //BarsSince(y)-3;//
// identify peaks
pk = pkb == 1;
tr = trb == 1;
// define Plot color
color = IIf( Ref(pkb < trb,-1), colorRed, colorGreen );
// calculate cumulated volume
cumVolume = SumSince2( pk OR tr, Volume);
Plot( cumVolume, "cumulated Volume", color, styleHistogram | styleOwnScale, 2 );
dist = ATR(1)/2;//
for( i = 0; i < BarCount-1; i++ )
{
if( tr[ i+1 ] ) PlotText( NumToStr(CumVolume[ i ]/1000,1,1) +" ", i-1, L[ i ] - dist[i], colordarkRed );
if( pk[ i+1 ] ) PlotText( NumToStr(CumVolume[ i ]/1000,1,1) +" ", i-1, h[ i ] + dist[i], colorgreen );
}
// Filter = .... ??
AddColumn(V*C,"");
Plot( Zig(Close,z), "Zig", u, styleThick,Null,Null,0,3,1);
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();