temporary Array out of range

 

hi friends,

I found a problem regarding the array size in my Custom indicator . When I change my timeframe -for example change to M30- sometimes my indicator does not work properly it takes the error of "array out of range", but when I manually change the timeframe from M30 to another timeframe and then back to my preferred timeframe -M30- the error would be resolved and the indicator works properly !

I'd appreciate if anyone could help me on the issue.

 
parham.trader:

hi friends,

I found a problem regarding the array size in my Custom indicator . When I change my timeframe -for example change to M30- sometimes my indicator does not work properly it takes the error of "array out of range", but when I manually change the timeframe from M30 to another timeframe and then back to my preferred timeframe -M30- the error would be resolved and the indicator works properly !

I'd appreciate if anyone could help me on the issue.


We would need to see the code to answer properly.

 
honest_knave:


We would need to see the code to answer properly.


here is the section of my code that is related to my question,

as you can see the condition of the if (major_arr_size>=10) and if it is true the function "major_confirmation_check_func" would be called and the main problem is with "major_price_arr[major_arr_size-1]" that the error comes from!!

if(major_arr_size>=10)
         completed_major_confirmation=major_confirmation_check_func(major_range_length,major_MACD_value,major_price);

bool major_confirmation_check_func(int completed_major_MACD_length,double completed_major_largest_MACD_value,double completed_major_price)
  {

//--- function variables:
   bool MACD_length_confirmation,MACD_value_confirmation,completed_move_height_confirmation,major_confirmation;
   int number_of_MACD_ranges_to_check,counter,counter_limit;
   double sum_MACD_largest_bars,Avg_MACD_largest_bars,min_accepted_MACD_value;
   double last_saved_major_price,completed_move_height,prev_move_height,completed_move_to_prev_move_RATIO;
   double sum_confirmation_criteria;

   last_saved_major_price=major_price_arr[major_arr_size-1];

}



 
parham.trader: here is the section of my code that is related to my question,
  1. You must post all relevant code. How should we know what major_price_arr is, or how big? How should we know what the value of major_arr_size is?
  2. Print out your variables, and find out why.
 
whroeder1:
  1. You must post all relevant code. How should we know what major_price_arr is, or how big? How should we know what the value of major_arr_size is?
  2. Print out your variables, and find out why.


you're correct!

unfortunately my code is too long to copy here, and I think it is useless to copy all my code here.

anyway, thank you friends for your kindness.

 
last_saved_major_price=major_price_arr[major_arr_size-1];
If
major_arr_size

Happens to be zero for whatever reason, your out.

Where is the code for sizing the array?

If

major_arr_size

Happens to go beyond the size of the array, your out.

 
Marco vd Heijden:
If

Happens to be zero for whatever reason, your out.

Where is the code for sizing the array?

If

Happens to go beyond the size of the array, your out.


I knew it but your response was informative, thank you.

My main question is that what is the reason when I reset the chart timeframe it is solved and it works properly ! it actually makes me confused !

 

Thank you friends,

I just found the problem!

Have a great time

 
parham.trader: unfortunately my code is too long to copy here, and I think it is useless to copy all my code here.
I didn't ask you to.
Reason: