- Dominik Egert your "zero bar" is at the wrong end of the array.
You must set as-series or non-series to your arrays and buffers, so they match your loop.
-
if(i < 2) // avoid Zero bar, as it keeps changing and affect the Average Value { Buffer_NormVolume[i] = (vVolume); continue;
Bar zero is not changing. You have to avoid it or indicator crashes at
vVolume - Buffer_NormVolume[i-1]);
See How to do your lookbacks correctly #9 — #14 & #19.
-
You must set as-series or non-series to your arrays and buffers, so they match your loop.
-
Bar zero is not changing. You have to avoid it or indicator crashes at
See How to do your lookbacks correctly #9 — #14 & #19.
Hi William
Thanks for your reply. for last couple of hours I have been juggling to implement your suggestions.
First I tried the Count Down method, and had a strange results as output was having sort of Bar Shift effect in display equal to MAPeriod!!! However, there was not much improvement still in the speed of Indicator.
Finally I tried the Count Up method, in the way it was suggested on your other post.
Well with this, at least the indicator is shown correctly however the cause of speed still remains a mystery. I have to run profiler but that also did not helped much.
Below is the REVISED Code (relevant section)
, image of both version of Indicator returning same values and profiler report.
Look forward from masters, to help me out.
regards.
//+----------------------------------------------------------------------------------------------------------+ //| MAIN Iteration function for Custom Normalize Volume Indicator //+----------------------------------------------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { /******* Revision: Suggestion to set false while Count UP ******/ ArraySetAsSeries(Buffer_NormVolume,false); ArraySetAsSeries(Buffer_Colors,false); double vSmoothing = 2.0/(1.0 + Inp_MAPeriod); //+--------------------------------------------------------------------------------------------------------+ //| Loop to FILL Applied Volume values into Buffer_Volume //+--------------------------------------------------------------------------------------------------------+ //for(int i=(int)MathMax(prev_calculated-1,0); i < rates_total; i++) /******* Revision: Suggestion to refraze for..loop ******/ for(int i = MathMax(vMAPeriod,prev_calculated); i < rates_total; i++) { double vVolume; if(Inp_AppliedVolume == VOLUME_TICK) vVolume = (double)tick_volume[i]; else vVolume = (double)volume[i]; if(i < 2) { Buffer_NormVolume[i] = (vVolume); continue; } Buffer_NormVolume[i] = Buffer_NormVolume[i-1] + vSmoothing * (vVolume - Buffer_NormVolume[i-1]); Buffer_Colors[i] = (Buffer_NormVolume[i] < Inp_Threshold ? 1:0); } //--- OnCalculate done, return new prev_calculated. return(rates_total-1); // REVISION: Recalculate current bar next tick. } // END Of Ci_NormVolume indicator calculation //+----------------------------------------------------------------------------------------------------------+
If prev_calculated equals rates_total, you are on the most current bar.
You need to take extra measure to update the most current bars value.
Either subtract one from prev_calculated when it's equal to rates_total or have some other logic to update most current bar. (Ie skip the current bar and wait for it to be the last in history.)
- You are wrong. Indicators never end. What they return is irrevalent.
- If you return rates_total - 1, you do not have to check prev_calculated to adjust starting position. See How to do your lookbacks correctly #9 — #14 & #19.
If prev_calculated equals rates_total, you are on the most current bar.
You need to take extra measure to update the most current bars value.
Either subtract one from prev_calculated when it's equal to rates_total or have some other logic to update most current bar. (Ie skip the current bar and wait for it to be the last in history.)
Thans Dominik.
Well it did not worked me :)
- You are wrong. Indicators never end. What they return is irrevalent.
- If you return rates_total - 1, you do not have to check prev_calculated to adjust starting position. See How to do your lookbacks correctly #9 — #14 & #19.
Thanks William
I tried but could not figure out why it not worked for me.
Hi William
Just trying to understand the logic behind
**********************************************************************************************************
for(int iBar = rates_total-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar){
// Timeseries and Indicators Access uses index=iBar
}
return rates_total-1; // Recalculate current bar next tick.
**********************************************************************************************************
When I tried to put it mathematically in excel sheet, I am not convinced with this. May be you can please through some lights ...
- docs.mql4.com
for(int iBar = rates_total-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar){ ⋮ } return rates_total-1; // Recalculate current bar next tick.
- First run prev_calculated is zero, loop runs from rates_total - 1 - lookback to zero. You can access iBar + (lookback-1) and not exceed rates_total-1.
- If you return rates_total, next run is from rates_total - 1 - rates_total. You said bar zero is done, so loop does nothing. #11
- If you instead return rates_total - 1. Next run is rates_total - 1 - (rates_total - 1) or zero. Loop reprocesses bar zero's new tick.
- If a new bar starts, rates_total increments (prev_calculated does not,) and next run is new_rates_total - 1 - (old_rates_total - 1) or one. Loop reprocesses last change of bar one and new tick of bar zero.
- Your spreadsheet is bogus, you are counting down in the code.
- First run prev_calculated is zero, loop runs from rates_total - 1 - lookback to zero. You can access iBar + (lookback-1) and not exceed rates_total-1.
- If you return rates_total, next run is from rates_total - 1 - rates_total. You said bar zero is done, so loop does nothing. #11
- If you instead return rates_total - 1. Next run is rates_total - 1 - (rates_total - 1) or zero. Loop reprocesses bar zero's new tick.
- If a new bar starts, rates_total increments (prev_calculated does not,) and next run is new_rates_total - 1 - (old_rates_total - 1) or one. Loop reprocesses last change of bar one and new tick of bar zero.
- Your spreadsheet is bogus, you are counting down in the code.
Thanks for explanation William.
need some time to digest it :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
UPDATE NOTE: Finally the issue have been sorted out.
Hi
Wishing Happy Weekend to all.
I am struggling hard to create an optimized "Normalized Volume Indicator".
I have used few other methods too including MAOnBuffer() functions.
Following code is my latest attempt, the same code I am using in Price EMA and is working fine even with 5EMAs calculated in a single indicator file.
I am not sure is the tick_volume[] or the Histogram is causing the below one to be slow. As all other calculations are same as in my EMA Indicator.
Your help will be highly appreciated.