Calculate how many stocks in a DataSet closed up
Author: kelvinyip
Creation Date: 12/12/2020 12:15 AM
profile picture

kelvinyip

#1
I want to have a sample to calculate across my Dow30 DataSet and if today's close is greater than yesterday, I want to add one to my global variable so eventually I want to see how many Dow stocks closed up. I think index lab has that but I think I may want something non standard but index lab requires complex C++ code that I don't think I know how to develop. Code below is my sample and I am trying to print out my FTC global variable. I thought this will print once at the end of my loop after all 30 stocks have been iterated through for 1 day. However, my debug statement got triggered 30 times. The global variable also increases if I run it over and over again.. 30 symbols for DOW but if I run it twice, my global variable goes to 60 and beyond.

Where should I put my debug so it prints only once each day after all 30 stocks have been iterated through and where /what should I use to reset the global variable each day after all 30 stocks have been iterated through




CODE:
Please log in to see this code.
profile picture

Eugene

#2
QUOTE:
I want to see how many Dow stocks closed up

Don't code (especially in C++ when IndexDefinitions can be coded in a few lines of easy C#) what you can beg, borrow or steal - or simply use the built-in tool. Open the Index-Lab tool, and from the "Index Builder" choose "Advancing Issues" and select your Dow DataSet. Voila. Then refer to the newly created index symbol as you would with GetExternalSymbol. It's that simple.

Further reading: Wealth-Lab User Guide > Index-Lab®

P.S. Topic is renamed.
profile picture

Eugene

#3
P.S. If you're tempted to do it in a script, there's no need in global variables at all. Check this out:

CODE:
Please log in to see this code.
profile picture

kelvinyip

#4
yes, I was using index lab like you said but I wanted some custom stuff down the road... the code you posted works fine. thanks
profile picture

Eugene

#5
You're welcome.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).