Error after reconnection with Server

 
My Indicator somtimes stopped after recconection with server.
To investigate it, I made simple indicator, and test it.

This is output log.

2010.07.06 14:31:03 Test (AUDNZD,M1) Rates_total=100002  prev_calc=100002 07:31  07:30  07:29
2010.07.06 14:31:04 Test (AUDNZD,M1) Rates_total=100002  prev_calc=100002 07:31  07:30  07:29
2010.07.06 14:31:05 Test (AUDNZD,M1) Rates_total=100002  prev_calc=100002 07:31  07:30  07:29

------  disconnect with Server around 6minutes by Netowork cut off ---------

2010.07.06 14:37:50 Test (AUDNZD,M1) Rates_total=100003  prev_calc=100002 07:37  07:31  07:30
2010.07.06 14:37:50 Test (AUDNZD,M1) Rates_total=100003  prev_calc=100003 07:37  07:31  07:30
2010.07.06 14:37:50 Test (AUDNZD,M1) Array out of range in 'Test.mq5' (50,169)


After reconnection to server, some bars are missing. (07:32-07:36)
But it's OK for me, it is same as MT4. I know this phenomenon, and my indicator can recover it.

But, after some tick, Indicator stopped by the Error "Array out of range".
"(50,169)" means  "time[i-3]".  "i" had same value of "rates_total".
I don't know why "time[rates_total-3]" cause a error.
This problem was happened around 5%.

I cannot know how to make a code  to recover from this phenomenon.
Please, advice me.

Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
MQL5 programs / Runtime Errors - Documentation on MQL5
Files:
test.mq5  3 kb
 
rates_total can be zero