<code>[COLOR=#0000ff][B]<code>[COLOR=#008000]// example to create composites via Static Variables or AddToComposite
[/COLOR]</code>[/B]<code></code>[/COLOR]</code><code>[COLOR=#008000]// by ST.M@elitetrader.com
[/COLOR]
[COLOR=#0000ff][B]SetBarsRequired[/B][/COLOR]( [COLOR=#800080]1000[/COLOR], [COLOR=#800080]0[/COLOR] );
WL = [COLOR=#0000ff][B]Param[/B][/COLOR]( [COLOR=#800080]"Category Number"[/COLOR], [COLOR=#800080]0[/COLOR], [COLOR=#800080]0[/COLOR], [COLOR=#800080]64[/COLOR], [COLOR=#800080]1[/COLOR] );
Periods = [COLOR=#0000ff][B]Param[/B][/COLOR]( [COLOR=#800080]"MA Periods"[/COLOR], [COLOR=#800080]50[/COLOR], [COLOR=#800080]10[/COLOR], [COLOR=#800080]200[/COLOR], [COLOR=#800080]10[/COLOR] );
[COLOR=#008000]// optional setting in regards to first method below (using static variables)
// SetOption( "StaticVarAutoSave", intervale = 60 ); // second interval storage of persistent variables, 0 - disabled
[/COLOR]
[COLOR=#008000]// set category of symbols
[/COLOR]category = [B]categoryWatchlist[/B];
categoryname = [COLOR=#0000ff][B]CategoryGetName[/B][/COLOR]( category, WL );
compositename = [COLOR=#800080]"Percent_Above_Composite_"[/COLOR] + categoryname;
[COLOR=#0000ff][B]RequestTimedRefresh[/B][/COLOR]( sec = [COLOR=#800080]5[/COLOR], onlyvisible = [B]False[/B] );[COLOR=#008000]// refresh chart every x seconds, 0 - disabled
// trigger(s) example
[/COLOR]trigger = [COLOR=#008000]/*refers to RequestTimedRefresh*/[/COLOR][COLOR=#0000ff][B]Status[/B][/COLOR]( [COLOR=#800080]"redrawaction"[/COLOR] ) [COLOR=#800040][B]OR[/B][/COLOR]
[COLOR=#008000]/*button click in paramters dialog*/[/COLOR][COLOR=#0000ff][B]ParamTrigger[/B][/COLOR]( [COLOR=#800080]"Calculate Composite"[/COLOR], [COLOR=#800080]"CLICK HERE"[/COLOR] );
[COLOR=#800040][B]if[/B][/COLOR] ( trigger )
{
</code><code><code> list = [COLOR=#0000ff][B]CategoryGetSymbols[/B][/COLOR]( category, WL );
count = [COLOR=#0000ff][B]StrCount[/B][/COLOR]( list, [COLOR=#800080]","[/COLOR] ) + [COLOR=#800080]1[/COLOR]; [COLOR=#008000]// count symbols of category
[/COLOR]
[COLOR=#008000]// iterate through set filled watchlist
[/COLOR] [COLOR=#008000]// to retrieve comma-separated list of symbols in watch list
[/COLOR] above = [COLOR=#800080]0[/COLOR]; </code>
[COLOR=#800040][B]for[/B][/COLOR] ( i = [COLOR=#800080]0[/COLOR]; ( sym = [COLOR=#0000ff][B]StrExtract[/B][/COLOR]( list, i ) ) != [COLOR=#800080]""[/COLOR]; i++ )
{
[COLOR=#0000ff][B]SetForeign[/B][/COLOR]( sym, [B]True[/B], [B]True[/B] );
above += [B]Close[/B] > [COLOR=#0000ff][B]MA[/B][/COLOR]( [B]Close[/B], Periods );[COLOR=#008000]// sum up true conditions of Price above MA
[/COLOR] [COLOR=#0000ff][B]RestorePriceArrays[/B][/COLOR]();
}
percent_above = [COLOR=#800080]100[/COLOR] * above / count;[COLOR=#008000]// calculate percentage above MA
[/COLOR]
[COLOR=#008000]// two methods to create composite ##################
[/COLOR] [COLOR=#008000]// first one
[/COLOR] [COLOR=#0000ff][B]StaticVarSet[/B][/COLOR]( compositename, percent_above, PersistentStorage = [B]True[/B] ); [COLOR=#008000]// store composite
[/COLOR]
[COLOR=#008000]// second one
[/COLOR] [COLOR=#008000]//AddToComposite( percent_above, "~" + compositename, "C", atcFlagDefaults | atcFlagEnableInIndicator );// store composite
[/COLOR]}
[COLOR=#008000]// call composite via two methods #################
// first method
[/COLOR]callcomposite = [COLOR=#0000ff][B]StaticVarGet[/B][/COLOR]( compositename );
[COLOR=#008000]// second method
//callcomposite = Foreign( "~" + compositename, "C" );
[/COLOR]
[COLOR=#0000ff][B]Plot[/B][/COLOR]( callcomposite, compositename, [B]colorRed[/B], [B]styleLine[/B], [B]Null[/B], [B]Null[/B], [COLOR=#800080]0[/COLOR], [COLOR=#800080]0[/COLOR], -[COLOR=#800080]50[/COLOR] ); </code> <code>
</code>