The question you should ask yourself first.. Do you actually require looping at all? But at least you should place all code not being required within loop outside of it.
YES I do need loop as i am creating custom time framing with different intervals for first and last bar. This program is for live market not for backtesting, that means with every tick program will be rerun. So in order to make program fast and not run loop every time from i=0, I am storing loop results in static variable on first run. and every next time, I do not want loop to start from I=0 but i=barcount-1000 and and update last few values of static variable.
Did you even bother to read the link @fxshrat has given you? FYI: BarCount can be less than 1000 and then your BarCount - 1000 yields NEGATIVE number (negative indexes to array which are obviously wrong).
yes I read it, my reply was just to explain why this is required. I understood that this is not supported in Amibroker. All my loops need to from 0 to 200 (max). There is no way to start loop from Barcount-1000.