And here is a modification of the second code from top of this page using dynamic count of symbols.
I'm gonna ask AmiBroker whether it is the absolute correct way as I'm not working with composites pretty often.
If using it in analysis window then you may also check "pad and align" setting.
I'm gonna ask AmiBroker whether it is the absolute correct way as I'm not working with composites pretty often.
If using it in analysis window then you may also check "pad and align" setting.
Code:
<code>[COLOR=#008000]// Exploration ######################################################################################
[/COLOR]
WL = [COLOR=#800080]0[/COLOR]; [COLOR=#008000]// WL number
[/COLOR]Periods = [COLOR=#800080]50[/COLOR]; [COLOR=#008000]// MA periods
[/COLOR]
category = [B]categoryWatchlist[/B];
categoryname = [COLOR=#0000ff][B]CategoryGetName[/B][/COLOR]( category, WL );
compositename = [COLOR=#800080]"~PercentAboveMA_Composite_"[/COLOR] + categoryname;[COLOR=#008000]// tilde required at start of comp name
[/COLOR]
atcmode = [B]atcFlagDefaults[/B] | [B]atcFlagEnableInExplore[/B];
[B]Filter[/B] = [COLOR=#0000ff][B]InWatchList[/B][/COLOR]( WL ) [COLOR=#800040][B]AND[/B][/COLOR] [COLOR=#0000ff][B]Status[/B][/COLOR]( [COLOR=#800080]"lastbarinrange"[/COLOR] );
[COLOR=#800040][B]if[/B][/COLOR] ( [COLOR=#0000ff][B]Status[/B][/COLOR]( [COLOR=#800080]"actionex"[/COLOR] ) == [B]actionExplore[/B] )
{
[COLOR=#008000]// sum up true conditions
[/COLOR] above = [B]Close[/B] > [COLOR=#0000ff][B]MA[/B][/COLOR]( [B]Close[/B], Periods );
[COLOR=#008000]// count symbols based on availability of data
[/COLOR] count = [COLOR=#800040][B]NOT[/B][/COLOR] [COLOR=#0000ff][B]IsNull[/B][/COLOR]( [B]C[/B] );
[COLOR=#0000ff][B]AddToComposite[/B][/COLOR]( above, compositename, [COLOR=#800080]"C"[/COLOR], atcmode );
[COLOR=#0000ff][B]AddToComposite[/B][/COLOR]( count, compositename, [COLOR=#800080]"1"[/COLOR], atcmode );
}
[COLOR=#0000ff][B]SetForeign[/B][/COLOR]( compositename );
[COLOR=#008000]// calculate percentage above MA
[/COLOR]percent_above = [COLOR=#800080]100[/COLOR] * [B]C[/B] / [B]Aux1[/B];
[COLOR=#0000ff][B]RestorePriceArrays[/B][/COLOR]();
callcomposite = percent_above;
[COLOR=#0000ff][B]Plot[/B][/COLOR]( callcomposite, compositename, [B]colorRed[/B], [B]styleHistogram[/B], [B]Null[/B], [B]Null[/B], [COLOR=#800080]0[/COLOR], [COLOR=#800080]0[/COLOR], -[COLOR=#800080]60[/COLOR] );</code>