@droskill, inspired by the code posted by @nsm51, here is my implementatiion to be used in a separate pane:
// https://forum.amibroker.com/t/proper-order-cumulative-indicator/39899
price = ParamField( "Price series", 3 ); // by default using Close
period1 = Param( "Period 1 - Short", 10, 5, 100, 1 );
period2 = Param( "Period 2 - Medium", 20, 6, 200, 1 );
period3 = Param( "Period 3 - Long", 30, 7, 300, 1 );
// Calculations
MA1 = MA( price, period1 );
MA2 = MA( price, period2 );
MA3 = MA( price, period3 );
Uptrend = ( MA1 > MA2 ) AND( MA2 > MA3 );
Downtrend = ( MA1 < MA2 ) AND( MA2 < MA3 );
SumUptrendBars = SumSince( Uptrend == 0, Uptrend );
SumDowntrendBars = SumSince( Downtrend == 0, Downtrend );
// Chart
colorLightLemon = colorRGB( 248, 246, 223 );
colorLightGreen = colorRGB( 206, 236, 202 );
colorLightPink = colorRGB( 249, 236, 234 );
SetChartBkGradientFill( colorLightLemon, colorLightYellow );
Plot( SumUptrendBars , "", ColorDarkGreen, styleNoTitle | styleHistogram | styleNoLabel, null, null, 0, -1, -50 );
Plot( -SumDowntrendBars , "", ColorDarkRed, styleNoTitle | styleHistogram | styleNoLabel, null, null, 0, -1, -50 );
Plot( sumUptrendBars > 0 , "", colorLightGreen, styleNoTitle | styleArea | styleOwnScale | styleNoLabel, 0, 1, 0, -1, -100 );
Plot( SumDowntrendBars > 0 , "", colorLightPink, styleNoTitle | styleArea | styleOwnScale | styleNoLabel, 0, 1, 0, -1, -100 );
PlotGrid( 0, colorBlack );
// plot the label on the right side
UpDown = iif(sumUptrendBars, sumUptrendBars, 0);
UpDown = iif(sumDowntrendBars, -sumDowntrendBars, UpDown);
Plot(Updown, "PO", colorBlue, styleNoTitle | styleNoLine);
Title = StrFormat( "{{NAME}} - " + FullName() +
" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
priceSeries = WriteIf(price==C, "CLOSE",
WriteIf(price==O, "OPEN",
WriteIf(price==H, "HIGH",
WriteIf(price==L, "LOW",
WriteIf(price==Avg, "AVERAGE (H+L+C)/3",
WriteIf(price==OI, "VOLUME",
WriteIf(price==OI, "OPEN INT", "OTHER")))))));
if( SelectedValue( SumUptrendBars OR SumDowntrendBars ) )
Title = Title + "\nLandry's Proper Order - " + priceSeries + " - " + WriteIf( SumUptrendBars > 0, StrFormat( "UPTREND #%g", SelectedValue( SumUptrendBars ) ),
StrFormat( "DOWNTREND #%g", SelectedValue( SumDowntrendBars ) ) );
(is there a better way to know which price series is chosen through ParamField()
to avoid the multiple nested WriteIf()
to determine its name?)