| push5280 201 posts
 msg #156826
 - Ignore push5280
 | 5/18/2021 10:44:24 AM 
 I want to add a column that shows which index a stock trades on (Nasdaq, S&P 500, Dow)  I tried
 add column index and searched the forums but no luck. Any suggestions?
 
 
 | 
| Cheese 1,374 posts
 msg #156827
 - Ignore Cheese
 | 5/18/2021 12:53:39 PM 
 /* https://www.stockfetcher.com/forums/General-Discussion/add-a-column-to-show-index/156826 */
 push5280 	5/18/2021 10:44:24 AM
 I want to add a column that shows which index a stock trades on (Nasdaq, S&P 500, Dow) I tried
 add column index and searched the forums but no luck. Any suggestions?
 =============================================================================
 
 Good luck, push
 
 
 
 
 
 | 
| push5280 201 posts
 msg #156830
 - Ignore push5280
 | 5/19/2021 9:44:28 AM 
 Thanks Cheese!
 
 
 | 
| redversa721 157 posts
 msg #156831
 - Ignore redversa721
 | 5/19/2021 9:52:33 AM 
 Hi Cheese, How does the logic work. I am confused how it is picking up the correct index.
 
 
 | 
| Cheese 1,374 posts
 msg #156833
 - Ignore Cheese
 | 5/19/2021 2:14:25 PM 
 My post above was addressed to push5280, and the filter was in response to a specific request.
 
 Not enough time for scope creep.
 
 
 
 | 
| redversa721 157 posts
 msg #156835
 - Ignore redversa721
 | 5/19/2021 4:43:07 PM 
 Cheese
 yes I get that. It is so elegant that I do not know how it works. :). I am not asking for any modifications, just trying to understand how you got the correct values. I have been looking at the code and I am shaking my head still on how you got the index name.
 
 and then the logic with adding the count, that completely threw me off. So I am just trying to learn how you were able to get it working right
 
 
 
 
 SET{SP500_,COUNT(MARKET IS SP500,1)}
 SET{NASDAQ100_,COUNT(MARKET IS NASDAQ 100,1)}
 SET{DJIA_,COUNT(MARKET IS DJIA,1)}
 
 // so SP500_ gets a count of number of stocks in SP500 in the last one day and same with the nasdaq100_ and DJIA_
 
 
 
 ADD COLUMN SP500_
 ADD COLUMN NASDAQ100_
 ADD COLUMN DJIA_
 
 
 SET{ADD1,SP500_ + NASDAQ100_}
 SET{ADD2,ADD1 + DJIA_}
 
 // This is where I am stumped. Hahha. How does adding the count of stocks in SP500 and DJ get the name of the index. I am probably going to like "duhhh" when and if you could please explain the logic.
 
 
 ADD2 > 0
 do not draw ADD2
 ]
 
 
 
 
 | 
| push5280 201 posts
 msg #156836
 - Ignore push5280
 | 5/19/2021 5:33:51 PM 
 Redversa721...I'll walk you through it
 
 SET{SP500_,COUNT(MARKET IS SP500,1)}
 SET{NASDAQ100_,COUNT(MARKET IS NASDAQ 100,1)}
 SET{DJIA_,COUNT(MARKET IS DJIA,1)}
 
 // so SP500_ gets a count of number of stocks in SP500 in the last one day and same with the nasdaq100_ and DJIA_
 ******This code assigns a one to the market if the stock is in the s&p500, or Nasdaq or DIJA******
 ********************************************************************
 ADD COLUMN SP500_
 ADD COLUMN NASDAQ100_
 ADD COLUMN DJIA_
 
 
 SET{ADD1,SP500_ + NASDAQ100_}
 SET{ADD2,ADD1 + DJIA_}
 
 // This is where I am stumped. Hahha. How does adding the count of stocks in SP500 and DJ get the name of the index. I am probably going to like "duhhh" when and if you could please explain the logic.
 ********I’m assuming Cheese added this code to eliminate Amex and pink sheets. If the total does not equal 1, then the stock is not listed on the Naz, Dow or part of S&P 500******
 
 ADD2 > 0
 do not draw ADD2
 
 
 
 | 
| redversa721 157 posts
 msg #156837
 - Ignore redversa721
 | 5/20/2021 12:05:44 AM 
 hey Push. Thanks a lot. hahah. it kinda makes sense
 
 So taking AMD which is in SP500 and NASDAQ, that means in first section
 SP500 and NASDAQ will be equal to 1.
 
 Now taking a stock lets say is only in SP500 & NASDAQ [not sure if possible, but just assuming]
 So in this case we will have
 SP500 = 1
 NASDAQ = 1
 DJ = 0
 
 Add1 = 2. (1+1)
 Add 2 = 2 (2+0)
 
 So in this case, the entry is shown, since add2 > 2 is excluded
 
 Now taking a example where the stock is SP500, DJ and NASDAQ
 Here add 1 = 2
 and add 2 = 3
 
 So this entry should be excluded right. But if you look at
 CSCO, it is available in all 3 markets and yet shows up on list
 LOL.. so that's why I am confused.. But thanks so mich for explaining the Add logic , that helps
 
 
 My first mistake was that, I was cumulatively counting all the values in Sp500
 
 So instead of 'thinking' by each stock per row, I was incorrectly thinking , it is summing up all stocks in Sp500 which is way way greater than 1 and that threw my whole understanding of the logic.
 Thank you so much again!!!
 
 
 
 
 
 
 | 
| push5280 201 posts
 msg #156838
 - Ignore push5280
 | 5/20/2021 7:28:53 AM 
 You're Welcome!
 
 
 | 
| SFMc01 358 posts
 msg #156839
 - Ignore SFMc01
 | 5/20/2021 10:59:57 AM 
 Respectfully, I usually just code
 
 Add Column EXCHANGE
 
 
 |