Cant allocate array values

 

Please could someone help me understand whats wrong with the logic in the code attached?

It causes an array out of range error at the line:

outLFHighArray[SFH]=lastHigh;

What im hoping to try and achieve is to be able to create a new array for the last Fractal Value. An array where lastFractalHigh[0] would have the value of the last high fractal at candle 0. Currently only candles when the fractal actually formed hold values where all others are EMPTY_VALUE.The end result would be to be able to use code like if lastFractalHigh[15]>lastFractalHigh[20].

I am using arraysize(inFHighArray) to call the function.

I have checked that i am actually getting values in the inFHighArray.

My thinking is that the outLFHArray will be populated with the same amount of iterations as the inFHighArray. Am I wrong there or is it the initial run of the for loop where the code fails?

I appreciate that there may be a much better way of doing this but as a novice its difficult to know relevant topics to search.


void setFractalHigh(double &outLFHighArray[],double &inFHighArray[],int highFractalArraySize)
{
double lastHigh=EMPTY_VALUE;
for(int SFH=0;SFH<highFractalArraySize;SFH++)
  {
   if(inFHighArray[SFH]==EMPTY_VALUE)
     {
      outLFHighArray[SFH]=lastHigh;
     }
   else
     {
      outLFHighArray[SFH]=inFHighArray[SFH];
      lastHigh=outLFHighArray[SFH];
     }
  }
Print("Last Fractal High 0 ",lastFractalHighArray[0]);
Print("Last Fractal High 20 ",lastFractalHighArray[20]);
}
 
toma4186: It causes an array out of range error at the line:

Your output array is smaller than your input array passed size. Show all relevant code,

 
William Roeder #:

Your output array is smaller than your input array passed size. Show all relevant code,

Hi and thanks for the reply. 

I am using arraysize(input array) to provide the counter amount for the for loop. My thinking is that this decides the size of the output array. I'm sorry but I don't understand what other code is relevant. I'm not trying to be difficult, I just don't understand.  Am I missing out using array resize or similar with the output array before passing it into my function? My function is intended to create the output array and size it accordingly. 
 
Hi

I have looked again at this and have used arrayresize (outputarray) at the beginning of the function. I no longer have the out of range error and am getting sensible values. Thanks again for your guidance William.
 
void setFractalHigh(double &outLFHighArray[],double &inFHighArray[],int highFractalArraySize)
{
ArrayResize(outLFHighArray,highFractalArraySize);
double lastHigh=EMPTY_VALUE;
for(int SFH=highFractalArraySize-1;SFH>=0;SFH--)
  {
   if(inFHighArray[SFH]==EMPTY_VALUE)
     {
      outLFHighArray[SFH]=lastHigh;
     }
   else
     {
      outLFHighArray[SFH]=inFHighArray[SFH];
      lastHigh=outLFHighArray[SFH];
     }
  }
Print("Last Fractal High 0 ",lastFractalHighArray[0]);
Print("Last Fractal High 20 ",lastFractalHighArray[20]);
}

For anyone that may need it this is the udpdated working code.