How to use StaticVarAdd for longer time ( >10 years)

Hi all,
I tried my code (below) to explore data (EOD) in Analysis window (from 01/01/2009 to 01/01/2011) to count Buy- Sell signals ( via StaticVarAdd/ Stocknum) in my watchlist, but i just had data only from 07/15/ 2010 until now, i cant explore data longer than 07/15/ 2010 . I checked my (EOD) database, it had enough data during that time. I had search many topics in this forum but i cant solve this problem. Anyone can help me to solve this one?
My Amibroker's version is 6.35.1 (64-bit).
Thank you in advance!
Albert

Capture

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );


//watchlist
wlnum1 = "mylist";
wlnum = CategoryFind(wlnum1,categoryWatchlist);
List = CategoryGetSymbols( categoryWatchlist, wlnum );	

if( Status( "stocknum" ) == 0 )
{
 
    
    StaticVarRemove( "~Short*" );
	StaticVarRemove( "~Sell*" );
	StaticVarRemove( "~Buy*" );
	StaticVarRemove( "~Cover*" );
    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {
        SetForeign( symbol );
        
		r1 = Param( "Fast avg", 12, 2, 200, 1 );
		r2 = Param( "Slow avg", 26, 2, 200, 1 );
		r3 = Param( "Signal avg", 9, 2, 200, 1 );
		ml = MACD(r1, r2);
		sl = Signal(r1,r2,r3);
		Hist = ml-sl;

        Short8 = Cross( sl, ml );
        Buy8 = Cross( ml, sl );
		Sell8= Cross( sl, ml );
		Cover8= Cross( ml, sl );

        StaticVarAdd( "~Short", Short8 );
        StaticVarAdd( "~Buy", Buy8 );
		StaticVarAdd( "~Sell", Sell8 );
		StaticVarAdd( "~Cover", Cover8 );
        RestorePriceArrays();
    }
}

Shortcomp = StaticVarGet( "~Short" );
Buycomp = StaticVarGet( "~Buy" );
Sellcomp = StaticVarGet( "~Sell" );
Covercomp = StaticVarGet( "~Cover" );


Filter = Status( "stocknum" ) == 0 ;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );

AddColumn( CoverComp, "Cover", 1.0 );
AddColumn( BuyComp, "Buy", 1.0);
AddColumn( Shortcomp, "Short", 1.0);
AddColumn( SellComp, "Sell");

First and foremost your use of StaticVarAdd is incorrect.
Probably copied from incorrect code too.

Please read this thread (having same issue of incorrect StaticVarAdd code)

You should remove loop completely. StaticVarAdd is supposed to be run without any loop.

Besides Param functions do not belong within any loop and not within if statements.

Also for Staticvaradd enable Pad&align.


I checked my (EOD) database

As for your output... check the data again (and the one of pad &align symbol) if you still get unexpected output after correcting the code/settings.

1 Like

@fxshrat Thank you so much,
You solved my problem, the code runs perfectly fine now.