Percentage Stock price nyse above the 200 day moving average

You do not carefully read documentation. Please study it carefully. StaticVarAdd is not supposed to be run on first scanned symbol only ( Status( "stocknum" ) == 0).

/// Set symbol list in Analysis Filter - Include
/// And enable pad&align
/// Set Periodicity in analysis General settings
/// Create composite ARRAY via SCAN 
/// @link https://forum.amibroker.com/t/percentage-stock-price-nyse-above-the-200-day-moving-average/19377/5
list_name = CategoryGetName(categoryGroup, 5);
symbol_name = "~AboveMA_"+list_name;
cnt = "~cnt_"+list_name;
if ( Status( "action" ) == actionScan ) {
    /// @link https://www.amibroker.com/guide/afl/staticvaradd.html
    if( Status( "stocknum" ) == 0 ) {
        // remove any earier composite values
        StaticVarRemove(symbol_name);
        StaticVarRemove(cnt);
    }
    StaticVarAdd(symbol_name, C >= MA(C, 200), True, persist = False);
    StaticVarAdd(cnt, 1, True, persist);
    Buy = 0;
}

pcnt_aboveMA = Nz(StaticVarGet(symbol_name) / StaticVarGet(cnt))*100;
Plot(pcnt_aboveMA, "Percentage > 200 day ma", colorBlueGrey, styleThick);

13

4 Likes