Incorrect rendering of arrows and objects for indicator

 
Hello folks,

I've ventured into MQL4 coding to build an MT4 custom indicator to aid my manual trading strategy along with an EA to calculate order levels and place a trade. 

The indicator populates the index buffers to display different styles of arrows under or above a candle to represent varying confidence levels in a trade setup.  I am also populating and colour coding 3 labels with the criteria used to determine the style of arrows. For some of these arrows that meet a high confidence threshold, I populate the 0 buffer with a signal for either a long or short trade. This buffer is in turn called by iCustom in the EA to determine direction of the trade, entry and stop loss levels and generate horizontal lines. The EA has a single Trade button that I use to send the order after various checks.

On its own, the indicator works fine and renders the arrows and labels without a hitch on every new bar. The EA too works fine and gets the right values through iCustom. I have added the indicator to the chart along with the EA to see the signals and colour coded labels prior to pressing the trade button. So far so good.

The issue I have is that initially when I open a chart, the Indicator and EA seem to render the arrows, labels and order levels fine. However, over time, I notice that the arrows and colour coding of the labels deviate from the correct values (compared to another chart where the Indicator is running without the EA). Often, I see the EA rendering order levels on an arrow style that shouldn't generate a trade signal, but when I reload the chart template it shows the correct arrow and labels as visible on the comparison chart with only the indicator. 

I have tried to address this issue by using ChartRedraw() in OnCalculate() after every signal. While this addresses the error in the label rendering, it doesn't rectify the errors in rendering of the arrows. The only solution that seems to address the 2 issues is to reload the template which would be cumbersome every time a trade signal sets up. 

This may be related, as I have noticed that on the chart with only the custom indicator, when I change the timeframe or symbol on the chart, the arrows don't appear correct (e.g. they may be placed too far away from the candles) until I reload the template upon which they render correctly. I've lived with this so far, because I don't need signals on multiple timeframes for my trading and as long as I have the same timeframe and symbol on a chart, it renders the arrows and labels correctly (when the EA is not present).

A third manifestation of the issue is when I recompile the indicator, sometimes, I get multiple arrows for a single candle which get rectified upon reloading the chart template again.

The cases seem to suggest that the buffers aren't being initialised or refreshed properly. Can you please offer guidance to resolve this?

Please let me know if you need additional information or code snippets etc. to help resolve.

PS: For some weird reason, my attempt to work around the problem by programatically forcing a refresh of the template using ChartApplyTemplate (0, "\\templates\\<template>.tpl")) also doesn't seem to work.

Thanks in advance,

Narayan