Can't access bars on higher time frame

 
hello guys. So I was trying to build an EA that utilises bars of multiple timeframes to gather information for trading. Now i'm struggling with an issue where if I try to run the code on a lower timeframe chart it can't seem to access the adequate number of bars it needs on the higher timeframe charts. This causes my EA to crash with an array out of range error whenever I run it a LTF chart however it seems to run properly when I run it on the highest timeframe chart. I need the EA to run on the smaller timeframes but it only seemes to be able to allocate a certain number of bars to the history cache for the higher timeframe candles(according to my console/journal). Please how do I fix this.
 
clyde50:
hello guys. So I was trying to build an EA that utilises bars of multiple timeframes to gather information for trading. Now i'm struggling with an issue where if I try to run the code on a lower timeframe chart it can't seem to access the adequate number of bars it needs on the higher timeframe charts. This causes my EA to crash with an array out of range error whenever I run it a LTF chart however it seems to run properly when I run it on the highest timeframe chart. I need the EA to run on the smaller timeframes but it only seemes to be able to allocate a certain number of bars to the history cache for the higher timeframe candles(according to my console/journal). Please how do I fix this.
I suggest you include more error handling into your code.

Documentation states how Copy xxx behaves in an EA, and you need to take this into account in your code.