The issue you're seeing happens because you're using "TickVolume()" inside the "OnCalculate()" function. This function makes external data requests, which can cause the indicator to show incorrect values when it first loads, or update only after a manual refresh.
You don’t need to use "iTickVolume()" here because MetaTrader already gives you all the tick volume data in the "tick_volume[]" array, which is passed directly into "OnCalculate()".
To fix this, just replace this line:
Vol_diff[i] = iTickVolume(NULL, PERIOD_CURRENT, rates_total - i - 1) - iTickVolume(NULL, PERIOD_CURRENT, rates_total - i);
With this:
Vol_diff[i] = tick_volume[i] - tick_volume[i + 1];
Also, make sure your loop stops at "rates_total - 1", since the last bar doesn't have a "next" one to compare with.
Once you make these changes, the indicator will work as expected and update automatically with every new tick, no need to refresh it manually anymore.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone, it probably is a very dum8 mistake but I'm new to coding,
I've created an indicator that calculates the difference between two consecutive candles tick volume but for some reason, unless i refresh it manually in mt5 , after first loading it it will display wrong values
I'll post my code here
thanks for your time