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)
I have a problem with "foreach loop" in NT. My code is as follows:
The indicator works fine if the collection doesn't contain number 13 (or higher), but with number 13 it doesn't return any number on my plots.
Are there some limitations in NT soft? Or is there something that I'm doing wrong?
And another question about collections. Is there a method to use some interval (something like.. from 1 to 100) instead enumerating each element of collection?
My collection is nt[] values = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,};. But if I want my collection to contain 100 elements, writing these numbers manually is not a very good solution.
Thank you.
Can you help answer these questions from other members on NexusFi?
If you want to use more than 13 numbers, you could define an ArrayList object and introduce a period. For 100 elements, it would look like this:
Your array, which is variable-sized should now contain the numbers from 0 to 99.
Now as you note, the array has not been used so far. You can now store other values in the array and access them accordingly. But I do not understand, what you need it for.
I want to create an indicator which returns different statistical data within a predefined number of bars or events in the past. And I want to use this data in some statistical tests (lile Student Test, Fisher, etc.). You can call it some sort of „scientific trading” if you want. One day I will start a thread about this, but I need some results before.
Now, regarding the code you provided above. Here is still the same problem. If the period is higher than 13, the „for loop” doesn't return any value. If it is 13 or lower, the indicator works fine.
I supose that the ArrayList idea is working just for "foreach" loop. I will test it now.
I want to create an indicator which returns different statistical data within a predefined number of bars or events in the past. And I want to use this data in some statistical tests (lile Student Test, Fisher, etc.). You can call it some sort of „scientific trading” if you want. One day I will start a thread about this, but I need some results before.
Now, regarding the code you provided above. Here is still the same problem. If the period is higher than 13, the „for loop” doesn't return any value. If it is 13 or lower, the indicator works fine.
I supose that the ArrayList idea is working just for "foreach" loop. I will test it now.
Thank you.
If you have 13 values added, the first value should be 0 and the last value 12. Also you cannot access bars with a negative index.
For 13 values you would need at least 13 bars, so you should add:
Yes, I understand this things, but the problem is that it works with any number lower then 13, but not with higher numbers.
For example, the „foreach loop” is working fine with 12, but doesn't calculate anything with number 13. It is the same code, the only thing which differs is the number of candels to look back.
I can't understand why it is working with 12 or lower, but not with 13 or higher.
The same problem with the "for loop". It is working now with number 13 or lower, but not with 14 or higher.
Are there some "build in" limitations in NT?
I want to explain now what I want to obtain.
I want my indicator to return the number of events in some predefined back period. In example above I have a simple condition Close[i] > Open[i] and viceversa. The code you wrote above (for loop) and my code (foreach loop) are working well for any value lower than 14 (for loop) and for any value lower than 13 (foreach loop).
The indicator compiles no matter if I use a higher number than 14. But if I use this values, the indicator - when loaded on chart - returns no value. If I use a lower number, the indicator returns the correct values on plots.
And this is strange, because I left the code intact and the only thing which is changed is the number of bars.