Page 1 of 1

Indicator Divide by Zero error for Intraday chart

Posted: Mon Feb 26, 2024 3:24 pm
by rlite4
Hi,

I put indicators ADX and DMI on a 4 min MSFT chart. Set database to load data from Jan 1 2024 to Feb 29 2024 to have 3 day blank space on the right.

Got error message "Error: in DMI, Line 35 Attempted to divide by 0. after poking around a bit figured data was not being loaded from Jan 01 through Jan 15.

The DMI indicator was not generating error message. it was plotting DM+ and DM- as zero for the days there was no data. It was the ADX indicator when put on chart which was causing the error message to be generated. Removing Jan 01 through 15th from database cleared the error and the ADX indicator plots ok.

Questions:
(1) how to detect that data for days was not loaded? I believe we have available 3 months of data for equity - is my understanding wrong?

(2) how to figure out cause of error message and correction required in the calculation of the ADX indicator?

TIA
rlite4

Re: Indicator Divide by Zero error for Intraday chart

Posted: Fri Mar 08, 2024 2:34 pm
by sbank
(1) how to detect that data for days was not loaded? I believe we have available 3 months of data for equity - is my understanding wrong?
Sorry can't help you. That is probably an Earik question if no one else knows on this board.
(2) how to figure out cause of error message and correction required in the calculation of the ADX indicator?
You should be able to just look at the QScript for ADX since this is a public indicator. Take a look at the Indicator "ADX", and you will see it uses a function (called "ADX"). If you open the function, you can see the code and all the places it can divide by zero.

Interestingly, it should never do that. :lol:

I only see two divisions, one by the length that is passed in, and the other the current barnumber. Both are tested for the presence of being zero before they are actually used. So in theory they should never trigger the problem. Here is what my ADX function looks like. Maybe you have an older version that what is installed on my machine?

Code: Select all

#returns Wilder's ADX indicator

input: length;

if (length<=0) return 0;  #break on bad input

dmival=dmi(length);
adx,ret=0;

if (barnum == length)
{
  cummdmi = 0;
  for (counter = 0 to barnum - 1 by 1)
  {
     cummdmi = cummdmi + dmival[counter];
  }
  ret = cummdmi / barnum;
}
else ret = (adx[1] * (length - 1) + dmival) / length ;

adx = ret;
           
return adx;  

Re: Indicator Divide by Zero error for Intraday chart

Posted: Fri Mar 08, 2024 3:01 pm
by rlite4
Hi Sbank,

will check that out and update.

cheers,
rlite4

Re: Indicator Divide by Zero error for Intraday chart

Posted: Mon Mar 11, 2024 7:39 pm
by rlite4
Hi Sbank,

checked it out my function ADX is exactly the same as your ADX and the ADX indicator in my wave59 installation is as given below - so am at a bit of a loss as to how to proceed. TIA
rlite4

input:length(14),timingline(20),color(red),timingline_color(blue),
thickness(1);

plot1=adx(length);
color1=color;
plot2=timingline;
color2=timingline_color;
thickness1=thickness;

Re: Indicator Divide by Zero error for Intraday chart

Posted: Tue Mar 12, 2024 1:28 pm
by sbank
One thought is to try to change the QScript for ADX (not the function). You posted above the ADX indicator, perhaps change it (and then re-compile it):

Code: Select all

input:length(14),timingline(20),color(red),timingline_color(blue),
thickness(1);

if (bar_has_data) {
	myadx = adx(length);
} else myadx=0;

plot1=myadx;
color1=color;
plot2=timingline;
color2=timingline_color;
thickness1=thickness;
The code above is a just a very simple tweak to the original. It tests if there is actual data first before it calculates the adx (instead of relying on a check when it calculates the value).

Re: Indicator Divide by Zero error for Intraday chart

Posted: Tue Mar 12, 2024 7:02 pm
by earik
Also double check your reference bars setting in your script. That needs to be how many bars to reserve for history so the script can access past data. If you are running a 20-period average, you'd set it to 20 or larger. Weird stuff can happen if you set it to something smaller than you need. W59 has all sorts of ways to try and save you from that, but every now and then something strange can happen when that isn't right...

Earik

Re: Indicator Divide by Zero error for Intraday chart

Posted: Wed Mar 13, 2024 3:07 am
by rlite4
Hi Sbank,

the mod to check if bar has data worked. Can plot ADX now.

cheers
rlite4

Re: Indicator Divide by Zero error for Intraday chart

Posted: Wed Mar 13, 2024 3:09 am
by rlite4
Thanks Earik,

will set that parameter to cover Max length ADX - or other by indicator - I plan to use.

cheers,
rlite4

Re: Indicator Divide by Zero error for Intraday chart

Posted: Wed Mar 13, 2024 3:11 am
by rlite4
Thanks Earik,

will set that parameter to cover max length ADX - or other by indicator - I plan to use

cheers.
rlite4