Objects in Expert Advisor Fails to appear after EA code is executed a couple of times

 

So, i'm writing an EA that paints rectangles into the chart. Yes, this should be done as an indicator but I want to use these rectangles in my back testing thus I want it drawn in the chart using an EA.

 My EA codes are run 1 time and is re-run every time a candle is closed. It works well on the first few candles but after the code is re-run a couple of times, the rectangles fails to appear. my codes are run and the values of the rectangles are churned out by the EA. the logs tells me the values are churned out but the rectangles are never drawn anymore. 

I am at a loss and have no idea what is going on and how to fix this. For those who wrote an EA before, I'm sure you encountered this problem before. Please please help.

 

Thanks. 

 
Are you really thinking someone can help you without seeing your code ?
 

Its my first time to post so noob mistake. Thanks for reminding me Alain.

 I found the problem. I failed to re-initialize the variables used so the codes don't work after a few iterations. I've fixed it already. Thanks.

Alain Verleyen:
Are you really thinking someone can help you without seeing your code ?