Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hi,
I have modified the PriorDayOHLC code slightly to suit me needs. The problem is the script works sometimes and in most times it throws the following error:
I am at my limited wits end. Anyone know what I need to do to get this thing going?
Cheers,
Kash
Can you help answer these questions from other members on NexusFi?
Hi Kash,
Recently had this happen to me also. I only had 2 days loaded on the chart. As soon as I switched it to 10 days all was well.
Hope it is this simple for your case also!
My guess is that the error is in the following line of code.
If the date is March 1st, Time[0].Day-1 will return a value of 0. You need to use Time[0].Subtract(new TimeSpan(x,x,x,x)).Day. Also, you can use try/catch blocks to verify that this is indeed the issue.
Hi raffu & Moore,
I was stepping through the whole code line by line to make sure all is logical when I fumbled at the same line of code as you Moore have highlighted! So on further 'research' and pushing the boundaries of my c# coding abilities, I realized that "Time[0].Day-1" was the culprit. It works ok when today is Wednesday to Friday but fails when it is Monday or Tuesday, as I suspect it cannot gather values for Sunday or Saturday as my chart session templates are Mon-Fri.
So to cut a long story short, I added the following snippet to the script:
Now the code above will substitute the right number of day/s to subtract depending on the today. If today is Monday, then code will skip Sun & Sat and use Friday values.
Unfortunately it still gives the same error!!! Not sure what more there is to it. Hope someone can help out.
The problem is still with the same line of code. Time[0].Day returns a value between 1 and 31 indicating the day of the month. If the day of the month is the first, Time[0].Day-n will return a 0 or negative value, which is the cause of your error. To get the proper value, you need to use Time[0].Subtract(new TimeSpan(n,0,0,0)).Day. Additionally, you will likely need to make similar changes to the month and year values.