Chart needs refreshing to show custom indicator arrows

 

Hi all

I'm new to the MQL5 world and have been toying around with combining two indicators (iMACD and a custom indicator mab_qqe2) to create a combined indicator (mab_combined). mab_combined should place "Buy" and "Sell" arrows on the chart depending on the source indicators signals. The idea being that eventually mab_combined will drive an EA.

The idea is not new and the different parts of code has come from various examples I have found on the web. The mab_qqe2 indicator appears to be causing an issue, the source of the indicator is in #property. Stand alone, the indicator works fine.

When attaching mab_combined to a chart, no indicator arrows appear(which they should). However, when right_clicking on the chart and refreshing, the arrows appear. If i replace the mab_qqe2 indicator with a pre packaged indicator like iRVI, then the chart does not need to be "Refreshed" in order for the arrows to immediately appear when mab_combined is attached to a chart.

Also, if I attach the mab_qqe2 indicator to the chart before attaching mab_combined then the arrows appear without the need for refreshing the chart

I've attached the source code of "mab_combined" and "mab_qqe2" any ideas / help much appreciated.

Files:
 
ajaxuk:

When attaching mab_combined to a chart, no indicator arrows appear(which they should). However, when right_clicking on the chart and refreshing, the arrows appear. If i replace the mab_qqe2 indicator with a pre packaged indicator like iRVI, then the chart does not need to be "Refreshed" in order for the arrows to immediately appear when mab_combined is attached to a chart.

mab_qqe2 just takes longer to compute, such that upon attaching mab_combined to your chart, and doing the first tick (that is when ALL arrows are first drawn), no data is available hence no arrow can be drawn.

So your problem can be solved by adding this line to the beginning of your OnCalculate:

   if (MathMin(BarsCalculated(indHandle1),BarsCalculated(indHandle2))<iBars(NULL,0))
      return (prev_calculated);
 
Seng Joo Thio:

mab_qqe2 just takes longer to compute, such that upon attaching mab_combined to your chart, and doing the first tick (that is when ALL arrows are first drawn), no data is available hence no arrow can be drawn.

So your problem can be solved by adding this line to the beginning of your OnCalculate:

Thank you for taking the time to give the explanation and also solution, it works now!

Reason: