As well as this I have a user parameter that allows the user specify the number of previous arrows to show on the chart at all times. So if the user chooses '8'. Once the chart loads the previous 8 times this pattern occurred will display an arrow.
In the code I achieve this by simply Changing the Arrow Drawing Tag each time a pattern occurs by Appending a Number which increases +1 each time the pattern occurs and then I remove old drawings like this::
RemoveDrawObject("MyIndicator Arrow" + (NumberCounter - MaxArrowsToShow));
As real time data continues the chart will only ever show the last 8 arrows, every time a new arrow/pattern occurs the oldest arrow will be deleted.
Now this works perfect. BUT the problem is the script still runs through ALL the bars on the chart when the indicator is initialized. This could be a lot depending on the user chart settings. As such the indicator takes a good few seconds to load and while loading the chart freezes.
I realize I can prevent the indicator running on Historical bars altogether. But is it possible in my scenario to limit the amount of historical bars my indicator checks over?
For example, based on my data I know this pattern occurs at least once every 25 bars. So if the user has a setting of 8 arrows to show, I'd want the indicator to only run on the previous 200 bars (8 x 25). But it seems like in order to do this I'd have to know the total number of bars on the chart before the chart has loaded?
If the chart has 6000 bars, I want to end up this:
if (CurrentBars[0] < 5800)
return;
But is this possible?

Comment