Hi Barno,
if you're using Visual Studio, just wanted to mention first you can download the FSB source, then develop your indicator in the FSB folder. It will do all the debugging and error catching for you, and helps with the autocompletes.
Source on github:
https://github.com/PopovMP/Forex-Strategy-Builder
you might have to read through their manual about registering and downloading a fork to your local machine. There might be a zip file of the source somewhere too for easy download and setup.
Then, for debugging your indicator, add it to your FSB project, described here:
http://forexsb.com/forum/post/11374/#p11374
It's just adding one line in one of the source files then running the project.
For your indicator, any of the price series arrays refer to that bar in your entire dataset, not the bar in the lookback period. If curbar goes to 0, then
curbar = 0
Close[curbar]
will get the the closing price from the first bar of your data file.
"Bars" is the total number of bars in your dataset; I usually have 4 months of 5 minute data, so comes to around 25,000. The usual convention on most indicators is to iterate forward through all the bars, then do some calculation over the lookback. Usually the iterator is "iBar", and the start is "iFirstBar", which is set to some value greater than the lookback periods of the parameters to avoid "Index Out of Bounds" error.
2 possibilities:
1)
Do you know if it's Close[curbar], Close[curbar+1], StopLossBuffer[curbar], or StopLossBuffer[curbar+1]?
If it's Close[curbar+1], probably trying to access a bar jsut out of the data set.
If it's StopLossBuffer, be sure StopLossBuffer is created with a sufficient size, usually size of Bars.
If it's StopLossBuffer[curbar+1], same as trying to access a bar just outside of the dataset.
First guess -- limit may be set to Bars or Bars-1, then [curbar+1] would be outside the dataset. If [curbar+1] is greater than [Bars-1], it will throw the index out of range error.
On the other side, limit may somehow decrease to -1.
You might have to change the >= to > to get the number of bars right, or change "curbar=limit" to "curbar=limit-1". If you want 10 bars in your lookback, and limit is set to 10, the for loop as coded above will get 11 bars. I usually have to try a few things to get the number correct.
2)
For your indicator, try something like this:
int limit = (int)IndParam.NumParam[0].Value; // could be [0] to [5]
int iFirstBar = limit + 5; // could be 5 or anything, just advances past the first few bars
for (int iBar = iFirstBar; iBar < Bars; iBar++) {
for (curbar=limit;curbar>=0;curbar--) {
Close[iBar-curbar] = ....
Then iBar advances through all the bars, then curbar in the inner loop gets the values from the lookback period. With this style, you might have to change the >= to > to get the number of bars right, or change "curbar=limit" to "curbar=limit-1". In porting MT4 indicators, I usually have to try a few adjusting tricks like that to get the values to sync up correctly. I usually do it the other way ( (int curbar=0; curbar < limit; curbar++) Close[iBar-curbar] ) but it's not a real reason, that's just the style I learned.
Hope that helps, I'd be happy to hear how it goes.