Warning 505 isn't an Error

Hi,

I get an error in second line because it is being divided by zero. I want to calculate if volume increased by 50% from previous day. Which is the best way to go about this ?

Cond1 = Close/Ref(Close,-1) > 1.05;
Cond2 = Volume/Ref(Volume, -1) > 1.50;
Filter = Cond1 AND Cond2;
AddColumn(RSI(),"RSI");

i think you can add a small number, like in this example:

HiC = HHV( Close, Range );
LoC = LLV( Close, Range );
Stoc = ( Close - LoC ) / ( HiC - LoC + 1e-9 );

but I’d say you could also use (although not sure if it works since your code did not give a 505 warning to me)

Cond2 = IIf( Ref( Volume, -1 ) != 0, Volume / Ref( Volume, -1 ) > 1.50, 0 );
1 Like
Cond1 = Close/Ref(Close,-1) > 1.05;
PrevVolume = Ref(Volume, -1);
Cond2 = iif(PrevVolume>0, Volume/PrevVolume > 1.50, false);
Filter = Cond1 AND Cond2;
AddColumn(RSI(),"RSI");
1 Like

Firstly, a warning is not an error. You don’t need to get “rid of it”.

You can do this WITHOUT division at all:

Cond2 = ROC( Volume, 1 ) > 50;

If you want to use division, you can simply use

Nz( Volume/PrevVolume );

it is a lot faster than IIF suggested by others.

2 Likes

Thank you @Tomasz. Didn’t know about the nz function.

I tried using Nz(), but I am still getting the warning.

Cond1 = Close/Ref(Close,-1) > 1.05;
Cond2 = Nz(Volume/Ref(Volume, -1)) > 1.50;
Filter = Cond1 AND Cond2;
//AddColumn(RSI(),"RSI");

@hemanth66 I don’t get a warning running your code. AmiBroker may need more information like your version, your OS, or the data you are using etc.

In the meantime you can try this code which should eliminate your warning (Cond2 as suggested by Tomasz, and Cond1 re-coded based on that idea).

//Cond1 = Close/Ref(Close,-1) > 1.05;
//Cond2 = Nz(Volume/Ref(Volume, -1)) > 1.50;

Cond1 = ROC( Close, 1 ) > 5;
Cond2 = ROC( Volume, 1 ) > 50;

Filter = Cond1 AND Cond2;
AddColumn( RSI(), "RSI" );

The point is not “getting rid of warning”. It is not an error. The warning 505 is informational message that you should watch for Not-a-numbers (infinity) in the results. What IS important is to convert those Not-a-numbers to zero (or whatever number you want). That is what Nz() function does. It takes care of results of division by zero.

1 Like