# Stock Score and Industry Score

Hey,

I'm running a Scoring and Filtering Process on 100 Stocks categorized in 20 Industries.

I've successfully coded the Scoring Process for Stocks. Now, I wish to assign the cumulative Stock Score of all Stocks in one Industry and assign it as Industry Score.

So, each of the 100 Stocks have two Scores i.e. Stock Score and Industry Score. An example is as follows:

Stock A (Industry X): Stock Score = 85 | Industry Score = 85 + 90 = 175
Stock B (Industry Y): Stock Score = 55 | Industry Score = 55 + 45 + 60 = 160
Stock C (Industry Y): Stock Score = 45 | Industry Score = 55 + 45 + 60 = 160
Stock D (Industry X): Stock Score = 90 | Industry Score = 85 + 90 = 175
Stock E (Industry Y): Stock Score = 60 | Industry Score = 55 + 45 + 60 = 160

I've unsuccessfully tried working to AddToComposite and StaticVarAdd Functions. Kindly see me through or share an sample / reference code.

Regards & Thanks.

Hey Tomasz,

The following Steps are to be achieved.

Step 1: Assign Variables to each Industry to store Industry Score.
Step 2: Calculate Stock Score and add to Industry Score (i.e. Cumulative Stock Score).
Step 3: Run Loop to assign Industry Score (Cumulative Stock Score) to each Stock.
Step 4: Explorer Output.

I could achieve Step 1 and Step 2 with the following code:

IndScoreVar = "IS" + IndustryID(1);
IndScore = Nz (StaticVarGet (IndScoreVar));

if ( Status ("stocknum") == 0 ) {StaticVarRemove ("IS*");}
if ( IndScore [BarCount - 1] == 0 ) {StaticVarSet (IndScoreVar, StockScore );}
if ( IndScore [BarCount - 1] != 0 ) {StaticVarAdd (IndScoreVar, StockScore );}

IndustryScore = StaticVarGet ( IndScoreVar, 1 );

Current Explorer Output:

Stock A (Industry X): Stock Score = 85 | Industry Score = 85
Stock B (Industry Y): Stock Score = 55 | Industry Score = 55
Stock C (Industry Y): Stock Score = 45 | Industry Score = 55 + 45 = 100
Stock D (Industry X): Stock Score = 90 | Industry Score = 85 + 90 = 175
Stock E (Industry Y): Stock Score = 60 | Industry Score = 100 + 60 = 160

Kindly advise on how to assign the Final Industry Score (Cumulative Stock Score) to each Stock before taking Explorer Output through AddColumn Function.

Expected Explorer Output:

Stock A (Industry X): Stock Score = 85 | Industry Score = 85 + 90 = 175
Stock B (Industry Y): Stock Score = 55 | Industry Score = 55 + 45 + 60 = 160
Stock C (Industry Y): Stock Score = 45 | Industry Score = 55 + 45 + 60 = 160
Stock D (Industry X): Stock Score = 90 | Industry Score = 85 + 90 = 175
Stock E (Industry Y): Stock Score = 60 | Industry Score = 55 + 45 + 60 = 160

Probably, some sort of Looping is required for 100 Stocks categorized in 20 Industries.

Regards & Thanks.