Why aren't you using the args passed into the OnCalculate function? Don't use iTimeSeries funcs unless you need MTF.
I have never used OnCalculate before, so how should I change my code? and is this the reason why it doesn't do the calculation? or whatever error it has?
Hi All
I am coding the following, the code returns no error but doesn't seem to do the calculation.
I tried to debug it by adding the following alert, it doesn't run. However, if I change the WVAD[] = Top or Bottom, it runs.
The code just doesn't do the division. Why?
Please post full code or attach source file.
Warning: seems your double Top returns negative values.
It also seems you want to recreate Williams Variable Accumulation Distribution (WVAD), developed by Larry Williams. If so, WVAD = (( Close – Open ) / ( High – Low )) * Volume.
You should read the following:
https://www.mql5.com/en/articles/10

- www.mql5.com
I have never used OnCalculate before, so how should I change my code? and is this the reason why it doesn't do the calculation? or whatever error it has?
MT4 and MT5 come with many example indicators. Look in Indicators\Examples\.
I recommend you study these examples and read the "OnCalculate" section of this page :
#property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //--- input parameters input int inpPeriod = 15; // Period //--- indicator buffers double iVWAD[]; // William's Variable Accumulation Distribution //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { SetIndexBuffer(0,iWVAD,INDICATOR_DATA); } int OnCalculate( const int rates_total, // size of input time series const int prev_calculated, // number of handled bars at the previous call const datetime& time[], // Time array const double& open[], // Open array const double& high[], // High array const double& low[], // Low array const double& close[], // Close array const long& tick_volume[], // Tick Volume array const long& volume[], // Real Volume array const long& spread[]) // Spread array { if (Bars(_Symbol,_Period)<rates_total) return(0); for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total && !_StopFlag; i++) { iVWAD[i] = ((close[i] – open[i]) / (high[i] – low[i])) * volume[i]; } return(rates_total); }I did not test it.
Please post full code or attach source file.
Warning: seems your double Top returns negative values.
It also seems you want to recreate Williams Variable Accumulation Distribution (WVAD), developed by Larry Williams. If so, WVAD = (( Close – Open ) / ( High – Low )) * Volume.
You should read the following:
https://www.mql5.com/en/articles/10
Yes, I am trying to code this one. I have also uploaded my source code.
I tried to follow the tutorial, as well as compiling the example that you share (thanks for this), but I couldnt get it running, it returns me error: oncalculate function not found in custom indicator
Yes, I am trying to code this one. I have also uploaded my source code.
I tried to follow the tutorial, as well as compiling the example that you share (thanks for this), but I couldnt get it running, it returns me error: oncalculate function not found in custom indicator
I believe I have fixed it. Please try to compile again.
I believe I have fixed it. Please try to compile again.
Same error: oncalculate function not found in custom indicator
Fixed. There was typos and wrong characters.
I was using notepad and copied OnCalculate() from Documentation, and other code samples too. Thanks again @Alain Verleyen.

- www.mql5.com

- 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 All
I am coding the following, the code returns no error but doesn't seem to do the calculation.
I tried to debug it by adding the following alert, it doesn't run. However, if I change the WVAD[] = Top or Bottom, it runs.
The code just doesn't do the division. Why?