I am coding an algorithm and I am using arrays of custom data and if it looks a bit strange is that I am coding the algorithm for a futures trading platform and so they may have functions that don't look standard C#.
I'm trying to Resize my arrays because I need them resized every time a new value is found to be added and then I use the SetValue sometimes to replace the last value found when a better one is found again within the next 5 values after the last value was set.
Trouble is, when I debug it in Visual Studio, it stops at line after ArrayResize and when I hover over the LastLSwDMIpriceBar[k], it shows the k = 0, just as I expected it to be, as it would be the first element in the array of one, so what Index is then outside the bounds of the array?
The way I understand and hoped the code to work is this: when the conditions met are by setting LSwDMIbool to true, the array is resized from 0 to 1 element and the element with index [0] is then set as LastLSwDMIpriceBar[k]. Am I wrong about this?
Any help would be greatly appreciated.
private int k, l;
private int[] LastLSwDMIpriceBar;
LastLSwDMIpriceBar = new int [1];
.....
if (LSwDMIbool)
{
lastLSwDMIbar = CurrentBar - 2 - LowestBar(LSwDMI, 5);
LastLSwDMI[0] = DMI(Closes[2], Convert.ToInt32(DmiPeriod)).Values[0].GetValueAt(lastLSwDMIbar);
Array.Resize(ref LastLSwDMIpriceBar, l++);
LastLSwDMIpriceBar[k] = CurrentBar - LowestBar(Lows[2], 5);
k++;
LSwDMIprice[0] = Lows[2].GetValueAt(LastLSwDMIpriceBar[k]);
}
......
if(!LSwDMIbool)
{
for (int LastBar = CurrentBar - 1; IsFirstTickOfBar && LastBar <= lastLSwDMIbar + 5; LastBar++)
LastLSwDMIpriceBar.SetValue((CurrentBar - LowestBar(Lows[2], 5)), k);
}