Thank you so much @mradtke and @fxshrat, you are both Amibroker geniuses! I tried it using both methods and I can get the results I was looking for. First, here is the code I made with Matt's advice:
MaxPositions = 100;
SetPositionSize( 100 / MaxPositions , spsPercentOfEquity );
SetOption( "MaxOpenPositions", MaxPositions );
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
// loop invariant code outside of loop
BuyLimit = 40;
SellLimit = 60;
if( Status( "stocknum" ) == 0 )
{
// Remove Static Variables
StaticVarRemove( "TotalBuySetup*" );
StaticVarRemove( "BuySetup*" );
SymList = CategoryGetSymbols( categoryWatchlist, GetOption( "FilterIncludeWatchlist" ) );
for( i = 0; ( tkSym = StrExtract( SymList, i ) ) != ""; ++i )
{
if( SetForeign( tkSym ) )
{
Indicator = RSI();
BuySetup = Indicator < BuyLimit;
StaticVarAdd( "TotalBuySetup", BuySetup );
RestorePriceArrays();
}
StaticVarSet( "Indicator" + tkSym, Indicator );
StaticVarSet( "BuySetup" + tkSym, BuySetup );
}
}
IndicatorSV = StaticVarGet( "Indicator" + Name() );
BuySetupSV = StaticVarGet( "BuySetup" + Name() );
TotalBuySetupSV = StaticVarGet( "TotalBuySetup" );
Buy = BuySetupSV;
Sell = IndicatorSV > SellLimit;
Short = Cover = 0;
//Exploration
Filter = 1;
AddColumn( RSI(), "RSI", 1.2 );
AddColumn( BuySetupSV, "BuySetupSV", 1.0 );
AddColumn( TotalBuySetupSV, "TotalBuySetupSV", 1.0 );
AddColumn( IIF( Buy, 'B', ' ' ), "Buy", formatChar, colorDefault, IIf( Buy, colorLime, colorDefault ) );
AddColumn( IIF( Sell, 'S', ' ' ), "Sell", formatChar, colorDefault, IIf( Sell, colorRed, colorDefault ) );
SetSortColumns( 2, -4 );
And here is the code that I made with fxshrat's advice:
MaxPositions = 100;
SetPositionSize( 100 / MaxPositions , spsPercentOfEquity );
SetOption( "MaxOpenPositions", MaxPositions );
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
// loop invariant code outside of loop
BuyLimit = 40;
SellLimit = 60;
wl_number = GetOption( "FilterIncludeWatchlist" );
SymList = CategoryGetSymbols( categoryWatchlist, wl_number );
if( Status( "stocknum" ) == 0 )
{
// Remove Static Variables
StaticVarRemove( "TotalBuySetup*" );
StaticVarRemove( "BuySetup*" );
Sum_setup = 0;
for( i = 0; ( tkSym = StrExtract( SymList, i ) ) != ""; ++i )
{
SetForeign( tkSym );
Indicator = RSI();
BuySetup = Indicator < BuyLimit;
RestorePriceArrays();
Sum_setup += Nz( BuySetup );
StaticVarSet( "Indicator" + tkSym, Indicator );
StaticVarSet( "BuySetup" + tkSym, BuySetup );
}
StaticVarSet( "TotalBuySetup", Sum_setup );
}
IndicatorSV = StaticVarGet( "Indicator" + Name() );
BuySetupSV = StaticVarGet( "BuySetup" + Name() );
TotalBuySetupSV = StaticVarGet( "TotalBuySetup" );
Buy = BuySetupSV;
Sell = IndicatorSV > SellLimit;
Short = Cover = 0;
//Exploration
Filter = 1;
AddColumn( RSI(), "RSI", 1.2 );
AddColumn( BuySetupSV, "BuySetupSV", 1.0 );
AddColumn( TotalBuySetupSV, "TotalBuySetupSV", 1.0 );
AddColumn( IIF( Buy, 'B', ' ' ), "Buy", formatChar, colorDefault, IIf( Buy, colorLime, colorDefault ) );
AddColumn( IIF( Sell, 'S', ' ' ), "Sell", formatChar, colorDefault, IIf( Sell, colorRed, colorDefault ) );
SetSortColumns( 2, -4 );
And here is a copy of the exploration that I get using either method. On 1/5/15, I have 3 x 1 buy setups in the buysetup column which gives a 3 in the TotalBuySetup column. Then on 1/6/15, I have 9 x 1 buy setups giving a 9 in the TotalBuySetup column:
