Simple Accumulation Distribution Oscillator

Dear All,

I am new to the Amibroker/AFL and trying a very simple AD Oscillator. However, I am not getting any results. Please advise?

AD_DAYS = Param("AD DAYS",20,1,50,1);
AD_PER = Sum((Close-Open)/(High-Low)*Volume,AD_DAYS)/Sum(Volume,AD_DAYS);
mycolorAD =IIf  (AD_PER<0,ColorRGB(252,255,200) , IIf( AD_PER>0,ColorRGB(252,255,0),ColorRGB(125,84,11)));
Plot(AD_PER,"AD%",mycolorAD ,styleHistogram);
GfxTextOut("AD[ "+AD_DAYS+" ]"+" = "+NumToStr(AD_PER,1.2),07, 14); 
Title = " ";

Best
Bobby

Check your data fields in quote editor

15

If you have Volume being zero
14

Then result will be Empty (Null).
15

Thanks, @fxshrat, for your prompt response and suggestion. I have checked the data field and it does have values. Please find the screenshot. Also, I tried changing the time-window from Daily to Weekly. The chart does work with weekly but not daily. Please advise?
2020-11-a 2020-11-b

if High and Low become equal then it may result in division by zero.

AD_DAYS = Param("AD DAYS",20,1,50,1);
AD_PER = Sum((Close-Open)/(High-Low+1e-9)*Volume,AD_DAYS)/Sum(Volume,AD_DAYS);

or use new function SafeDivide of AmiBroker 6.35

AD_DAYS = Param("AD DAYS",20,1,50,1);
AD_PER = Sum(Safedivide(C-O,H-L)*V,AD_DAYS)/Sum(V,AD_DAYS);
2 Likes

Thanks, @fxshrat for your help. You are a STAR.
Both of your suggestions worked. I learn a lot more from your style of suggesting elegant code to solve the problem.

Cheers
Bobby

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.