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)
As I answered in post #6, you cannot access negative bars. The first bar of the chart has the index 0. So if you select a period of 13, the index of the current bar should be equal to or greater than 13.
Have modified the indicator, put the variables where they belong and added a property to access the period value.
Thank you. I didn't understand why that condition is needed in one case (for 13), but not for a lower number. For when I used a lower number, the indicator worked fine.
Isn't this because you are creating an array with 13 elements which will be indexed 0-12, so trying to access array[13] is the 14th element of the array that makes no sense.
The ArrayList that Fat Tails mentioned has the advantage of being dynamic as far as element size so you don't have to manually allocate memory at compile time like you do with a regular array.
The limitations for both are how much memory you have.
Print(arraylist.count) is good for debugging, will give you have many elements your arraylist has.
Both indicators you posted compiled but could not be applied to any chart, even not for a period of 12. If you look at the code, you will understand that for the first bar of the chart, which has the index 0, you tried to access negative bars, which do not exist. Logically both your indicators threw exceptions and did not plot anything.