stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Array out of Range Divergence Indicator
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5625
Page 1 of 1
Author:  BobbyT [ Sun Feb 24, 2019 11:14 pm ]
Post subject:  Array out of Range Divergence Indicator

Hi Y'all
I'm trying to modify the 9ofX indi from dwain to show divergences. I've been using a CCI divergence indicator as a template. I've included it for clarity

I keep getting array out of range during the divergence routine but for the life of me I cant work out what the hell is going on.
Printing the indexes to the terminal shows that there are enough data points in the array.

The 9ofX indi used was v2.

Cheers
Author:  SteveHopwood [ Mon Feb 25, 2019 1:09 am ]
Post subject:  Array out of Range Divergence Indicator

BobbyT ยป Sun Feb 24, 2019 11:14 pm wrote:Hi Y'all
I'm trying to modify the 9ofX indi from dwain to show divergences. I've been using a CCI divergence indicator as a template. I've included it for clarity

I keep getting array out of range during the divergence routine but for the life of me I cant work out what the hell is going on.
Printing the indexes to the terminal shows that there are enough data points in the array.

The 9ofX indi used was v2.

Cheers
Just so you know, I have read your post several times and still have no idea what you are talking about.

I am a bit on the thick side of thingies. Even so, those on the brighter side of thingies might need you to be a tad on the clearer side of thingies if they are going to be able to help.

:xm: :rocket:
Author:  BobbyT [ Mon Feb 25, 2019 6:37 am ]
Post subject:  Array out of Range Divergence Indicator

Fair point Steve. I'll see if I can't make this a bit easier for everyone.

I'm trying to combine the attached cci indicator with the attached 9ofX indicator. This is the result of some toying I have done with 9ofX/price divergence and scalping on the short time frames.
I thought it would be as easy as just swapping out the calls to CCI in the divergence indicator but as I'm sure you can appreciate, indis be a strange beast wto tame.

If this still doesn't make sense then I can always try again haha

Cheers

Edit: the array out of range error appears linked to Strengthbuffer being accessed when trying to find the most recent trough.....am I helping.....probably not.....
Author:  renexxxx [ Mon Feb 25, 2019 8:58 am ]
Post subject:  Array out of Range Divergence Indicator

Hi BobbyT,

You might want to have a look at this loop:

Code: Select all

            for (int j = i; j < Bars; j++)
              {              
                Print("i: " + i + "; j: " + j + "; Bars: " + Bars + "; Strengthbuffer size: " + ArraySize(Strengthbuffer));  
                if(Strengthbuffer[j] <= Strengthbuffer[j+1] && Strengthbuffer[j] < Strengthbuffer[j+2] &&
                   Strengthbuffer[j] <= Strengthbuffer[j-1] && Strengthbuffer[j] < Strengthbuffer[j-2])
                    return(j);
              }
The j variable will iterate up to (and including) Bars-1. However, you access Strengthbuffer[j+2], which means (when j reaches Bars-1), that you access Strengthbuffer[Bars+1]. Strengthbuffer is an automatic array, created by the indicator and has only Bars elements, indexed from 0 to Bars-1. So, the index Bars+1 for Strengthbuffer is out of range.

Hope this helps.

Rene.
Author:  BobbyT [ Mon Feb 25, 2019 2:44 pm ]
Post subject:  Array out of Range Divergence Indicator

Thanks for dropping in Rene.

So changing

Code: Select all

Bars to Bars-2
(to accommodate for the shift issue you pointed out) hangs the terminal. There is no spike in memory usage from the terminal but I'm guessing it's too much for it to handle.

Changing

Code: Select all

Bars to BarsToDraw
(currently set at 1000) results in a new array out or range error (but at least doesn't hang the terminal). This is generated by

Code: Select all

GetIndicatorLastTrough
(the previous offender) as it fails to find a trough and therefore returns -1. Arrays don't have -1 elements, at least not last time I checked :P

So the question now becomes....what on earth is wrong with this indi? The original CCI divergence indicator that I have been using finds divergences just fine. Why on earth the peak/trough logic no longer works with a different line has me beat :/
All times are UTC Page 1 of 1