I want to export OHLCV data for a range of dates to CSV files. One csv file will hold OHLCV data for a particular day e.g. ALL_SYMS-2019-02-07.csv will hold OHLCV data for every stock only for Feb 7th
I got it working for a single date but it is not working for the range of dates. Can you please look at the code and tell me what I'm doing wrong.
CODE:
Please log in to see this code.
Size:
Color:
Matching dates should be done using the .Date property rather than via string comparison but why complicate things at all? Simply choose a "Date Range" in data loading options e.g. 2019/2/1 to 2019/2/15. Case closed.
Size:
Color:
It's not working. I'm getting the following error:
Error processing symbol AAPL Object reference not set to an instance of an object.
Can you please try this and see what I'm missing ?
Size:
Color:
What should be working? Am I overlooking some updated code here without the
ListOfDates and a
.ToDate-based comparison? Can't find any.
As for the error in general please refer to the Knowledge Base (Wiki) article:
Errors | Strategy >
Object reference not set to an instance of an object.
Size:
Color:
I rewrote the code and it' still giving the "Object reference not set to an instance of an object. ". So something somewhere is not getting initialized and I can't figure it out. I ran the GetDataRange after compiling it with csc.exe and it's returning the list. Can you please tell me what's going on or what's the best way to debug this:
CODE:
Please log in to see this code.
Size:
Color:
Not sure if you've overlooked my reply #2 with the obvious solution. Since I haven't seen an explanation as to why the code has to work the way you're trying it to make then it's up to you to do your troubleshooting:
How can I debug my trading strategies in Wealth-Lab?
Size:
Color:
I overlooked the #2 comment. What you suggested is a much better solution. I changed the code (listed below). However, the code only prints the data for the last date. I set the Date Range in WL to 2019-01-01 to 2019-01-04. However it only prints data for 2019-01-04.
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
However, the code only prints the data for the last date.
No, it prints the data for the last two bars. There are 3 bars in that time span but for some reason you've modified the working code from
Exporting to ASCII comma-separated files (CSV) to exclude the first bar:
CODE:
Please log in to see this code.
If you retract the unnecessary change it will output all the 3 bars. Run this in Multi-Symbol mode:
CODE:
Please log in to see this code.
Size:
Color:
Oops my bad! Thanks for pointing it out.
Only one problem remains. All the data is getting written into the same file i.e. the one with the last date. How do I change the program to write the data to separate files ?
Thanks again for all your comments and help.
Size:
Color:
QUOTE:
All the data is getting written into the same file i.e. the one with the last date.
That's how I gather your intention was. The file name clearly indicates that everything gets dumped into one file:
CODE:
Please log in to see this code.
QUOTE:
How do I change the program to write the data to separate files ?
Just revisit the Wiki article for the code example which already does just that - export to separate files:
Exporting to ASCII comma-separated files (CSV)
Size:
Color:
I'm trying to get EOD data for every symbol on a file named after that date
i.e. 2019-01-05.csv will have the OHLCV data for every stock in the dataset for Jan 5, 2019
The challenge I'm facing is to how to write the output to the correct files i.e. how to match the file name with the date
e.g. let's say there are 2 symbols in the dataset AAPL FB
I want the Jan 03.2019 data for both FB and AAPL to go to 2019-01-03.csv.
AAPL
Jan 04, 2019 144.53 148.55 143.80 148.26 147.63 58,607,100 -> 2019-01-04.csv
Jan 03, 2019 143.98 145.72 142.00 142.19 141.58 91,312,200 -> 2019-01-03.csv
Jan 02, 2019 154.89 158.85 154.23 157.92 157.25 37,039,700 -> 2019-01-02.csv
FB
Jan 04, 2019 134.01 138.00 133.75 137.95 137.95 29,002,100 -> 2019-01-04.csv
Jan 03, 2019 134.69 137.17 131.12 131.74 131.74 22,717,900 -> 2019-01-03.csv
Jan 02, 2019 128.99 137.51 128.56 135.68 135.68 28,146,200 -> 2019-01-02.csv
Size:
Color:
I replaced
CODE:
Please log in to see this code.
to
CODE:
Please log in to see this code.
and it works now.
Thank you so much for your time and help.
Size:
Color:
You're welcome. I'm glad you got it working.
Size:
Color: