Proud of my first array, but need help to modify and or make better code

 

Hello Folks,


I know to you all it must not sound like much, but for me it is another step on the programming ladder.
Current status: This array is giving me the lows of a 24hr period.

What I want to archieve:

1st: Use an external variable in the brackets [], instead of the 24, so that I can set the desired period for the calculation (like 12 hours as an example). But changing out the 24 with a variable does not work as I was hoping.

2nd: I wonder if this code could be written smarter. It seems to be very much code for a simple task. Let's just say I want to get the lows for 50 hours.


double MyArray_Prev24Low[24];
         MyArray_Prev24Low[0]=iLow(Symbol(),PERIOD_H1,1); MyArray_Prev24Low[1]=iLow(Symbol(),PERIOD_H1,2); MyArray_Prev24Low[2]=iLow(Symbol(),PERIOD_H1,3);
         MyArray_Prev24Low[3]=iLow(Symbol(),PERIOD_H1,4); MyArray_Prev24Low[4]=iLow(Symbol(),PERIOD_H1,5); MyArray_Prev24Low[5]=iLow(Symbol(),PERIOD_H1,6);
         MyArray_Prev24Low[6]=iLow(Symbol(),PERIOD_H1,7); MyArray_Prev24Low[7]=iLow(Symbol(),PERIOD_H1,8); MyArray_Prev24Low[8]=iLow(Symbol(),PERIOD_H1,9);
         MyArray_Prev24Low[9]=iLow(Symbol(),PERIOD_H1,10); MyArray_Prev24Low[10]=iLow(Symbol(),PERIOD_H1,11); MyArray_Prev24Low[11]=iLow(Symbol(),PERIOD_H1,12);
         MyArray_Prev24Low[12]=iLow(Symbol(),PERIOD_H1,13); MyArray_Prev24Low[13]=iLow(Symbol(),PERIOD_H1,14); MyArray_Prev24Low[14]=iLow(Symbol(),PERIOD_H1,15);
         MyArray_Prev24Low[15]=iLow(Symbol(),PERIOD_H1,16); MyArray_Prev24Low[16]=iLow(Symbol(),PERIOD_H1,17); MyArray_Prev24Low[17]=iLow(Symbol(),PERIOD_H1,18);
         MyArray_Prev24Low[18]=iLow(Symbol(),PERIOD_H1,19); MyArray_Prev24Low[19]=iLow(Symbol(),PERIOD_H1,20); MyArray_Prev24Low[20]=iLow(Symbol(),PERIOD_H1,21);
         MyArray_Prev24Low[21]=iLow(Symbol(),PERIOD_H1,22); MyArray_Prev24Low[22]=iLow(Symbol(),PERIOD_H1,23); MyArray_Prev24Low[23]=iLow(Symbol(),PERIOD_H1,24);


Thanks for looking into this.

WorstCases

 
WorstCases:

Hello Folks,

[....]

2nd: I wonder if this code could be written smarter. It seems to be very much code for a simple task. Let's just say I want to get the lows for 50 hours.


1) use a for loop for(;;)

2) i think u should start with iLow(Symbol(),PERIOD_H1,0); (or maybe u don't want the current hour low)

 
WorstCases:

1st: Use an external variable in the brackets [], instead of the 24, so that I can set the desired period for the calculation (like 12 hours as an example). But changing out the 24 with a variable does not work as I was hoping.

2nd: I wonder if this code could be written smarter. It seems to be very much code for a simple task. Let's just say I want to get the lows for 50 hours.

int start = 1;              // input
int end   = 24;             // parameters
double MyArray_Prev24Low[]; // Output

int length = end - start + 1; 
ArrayResize(MyArray_Prev24Low, length);
for(int index = 0; start <= end; start++, index++)
   MyArray_Prev24Low[index]=iLow(Symbol(), PERIOD_H1, start);