Continue to get 'floating-point division by zero' error

Questions about MultiCharts and user contributed studies.
smhuggins
Posts: 12
Joined: 15 Mar 2015
Has thanked: 1 time

Continue to get 'floating-point division by zero' error

Postby smhuggins » 15 Mar 2015

Hi there

I'm new to Multicharts and to Easylanguage, and can't for the life of me fix my code so that I stop getting the 'Floating-point division by zero' error message in portfolio backtester.

I've added filters to individual signals, eg Bollinger Bands (and others like MovAvg) but continue to get the error message.

Does anyone have any ideas?? My code is below, as well as the two fixes I have tried, but it doesn't work.

Thanks!!

Tried to fix with these two lines of code:

Code: Select all

If value1 = 0 then value1=value1+0.0000000001;
If value1 <> 0 then value2 = value3 / value1;
Code

Code: Select all

inputs:
BollingerPrice( Close ),
TestPriceLBand( Close ),

Length( 20 ),
NumDevsDn( 2 ) ;

If value1 = 0 then value1=value1+0.0000000001;
If value1 <> 0 then value2 = value3 / value1;

input: double DollarsToTrade( 1000 ) ;
input: int SharesToTrade( 0 ) ;
input: bool VolumeFilter( True ) ;
input: double VolPcntTraded( 90 ) ;
input: int VolLastXDays( 10 ) ;
input: bool MarketShareFilter( True ) ;
input: double MarketSharePcnt( 5 ) ;
input: bool MinStockPriceFilter( True ) ;
input: double MinStockPrice( 0.50 ) ;

var: double vTick( ( MinMove / PriceScale ) * iff( Category = 12, 10, 1 ) ) ;
var: double vTickDollar( ( MinMove * PointValue ) * iff( Category = 12, 10, 1 ) ) ;
var: double vDecimals( Log( PriceScale ) / Log( 10 ) ) ;
var: int va( 0 ), int vb( 0 ) ;



/// Trade Amount ///
var: int vShares( 100 ) ;
if SharesToTrade > 0 then vShares = SharesToTrade ;
if DollarsToTrade > 0 then vShares = round( DollarsToTrade / close of data1, 0 ) ;


/// VolumeFilter ///
var: int vVolDays( 0 ) ;
vVolDays = 0 ;
for vb = 1 to VolLastXDays
begin
if ( upticks[vb] + downticks[vb] ) > 0 then vVolDays = vVolDays + 1 ;
end ;



variables:
var0( 0 ) ;

var0 = BollingerBand( BollingerPrice, Length, -NumDevsDn ) ;

condition1 = CurrentBar > 1 and TestPriceLBand crosses over var0 ;
if condition1 then

Buy ( "BBandLE" ) next bar at var0 stop ;
Last edited by smhuggins on 15 Mar 2015, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Continue to get 'floating-point division by zero' error

Postby TJ » 15 Mar 2015

Hi there
I'm new to Multicharts and to Easylanguage, and can't for the life of me fix my code so that I stop getting the 'Floating-point division by zero' error message in portfolio backtester.
I've added filters to individual signals, eg Bollinger Bands (and others like MovAvg) but continue to get the error message.
Does anyone have any ideas?? My code is below, as well as the two fixes I have tried, but it doesn't work.
Thanks!!
Tried to fix with these two lines of code:
If value1 = 0 then value1=value1+0.0000000001;
If value1 <> 0 then value2 = value3 / value1;
Code
inputs:
BollingerPrice( Close ),
TestPriceLBand( Close ),
Length( 20 ),
NumDevsDn( 2 ) ;
If value1 = 0 then value1=value1+0.0000000001;
If value1 <> 0 then value2 = value3 / value1;
input: double DollarsToTrade( 1000 ) ;
input: int SharesToTrade( 0 ) ;
input: bool VolumeFilter( True ) ;
input: double VolPcntTraded( 90 ) ;
input: int VolLastXDays( 10 ) ;
input: bool MarketShareFilter( True ) ;
input: double MarketSharePcnt( 5 ) ;
input: bool MinStockPriceFilter( True ) ;
input: double MinStockPrice( 0.50 ) ;
var: double vTick( ( MinMove / PriceScale ) * iff( Category = 12, 10, 1 ) ) ;
var: double vTickDollar( ( MinMove * PointValue ) * iff( Category = 12, 10, 1 ) ) ;
var: double vDecimals( Log( PriceScale ) / Log( 10 ) ) ;
var: int va( 0 ), int vb( 0 ) ;
/// Trade Amount ///
var: int vShares( 100 ) ;
if SharesToTrade > 0 then vShares = SharesToTrade ;
if DollarsToTrade > 0 then vShares = round( DollarsToTrade / close of data1, 0 ) ;
/// VolumeFilter ///
var: int vVolDays( 0 ) ;
vVolDays = 0 ;
for vb = 1 to VolLastXDays
begin
if ( upticks[vb] + downticks[vb] ) > 0 then vVolDays = vVolDays + 1 ;
end ;
variables:
var0( 0 ) ;
var0 = BollingerBand( BollingerPrice, Length, -NumDevsDn ) ;
condition1 = CurrentBar > 1 and TestPriceLBand crosses over var0 ;
if condition1 then
Buy ( "BBandLE" ) next bar at var0 stop ;
There is only one way to solve this problem... is to go through each and every division to verify the calculations.

You have to understand your variables -- know what they are, and know what they do at each step of the way. The best way to start is to get your calculator out and do a manual calculation.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Continue to get 'floating-point division by zero' error

Postby TJ » 15 Mar 2015

ps.
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Continue to get 'floating-point division by zero' error

Postby TJ » 15 Mar 2015

Hi there

I'm new to Multicharts and to Easylanguage, and can't for the life of me fix my code so that I stop getting the 'Floating-point division by zero' error message in portfolio backtester.

I've added filters to individual signals, eg Bollinger Bands (and others like MovAvg) but continue to get the error message.

Does anyone have any ideas?? My code is below, as well as the two fixes I have tried, but it doesn't work.

Thanks!!

Tried to fix with these two lines of code:

Code: Select all

If value1 = 0 then value1=value1+0.0000000001;
If value1 <> 0 then value2 = value3 / value1;
::
To avoid coding error, and to avoid the need to spend time in debugging,
you must develop good coding habits.

Tip #1
Use meaningful variable names. Avoid generic names at all costs. (ie value1, condition1, etc).

You have to make sure that, 3 months from now, when you look at your code again, you know what you have written, and you do not need to spend needless time trying to figure out the original logic.

Furthermore, no volunteer is going to wade through your lines of codes, back and forth, trying to decipher what is value1, condition1, etc., and to guess your intentions with them.

eg.

Code: Select all

value1 = average( c, 10 );
if c > value1 then BUY...
can be coded as:

Code: Select all


var:
MA10(0);

MA10 = average ( c, 10 );

if c > MA10 then BUY...

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Continue to get 'floating-point division by zero' error

Postby TJ » 15 Mar 2015

Hi there
I'm new to Multicharts and to Easylanguage, and can't for the life of me fix my code so that I stop getting the 'Floating-point division by zero' error message in portfolio backtester.
I've added filters to individual signals, eg Bollinger Bands (and others like MovAvg) but continue to get the error message.
Does anyone have any ideas?? My code is below, as well as the two fixes I have tried, but it doesn't work.
Thanks!!
::
What is your instrument?
What is the chart resolution?


I have compiled the code and applied it to 5 min ESH5 with no division error.

smhuggins
Posts: 12
Joined: 15 Mar 2015
Has thanked: 1 time

Re: Continue to get 'floating-point division by zero' error

Postby smhuggins » 15 Mar 2015

Ok thanks TJ. I have tried so many things, and still feel stuck.

All ASX shares, in portfolio backtester; 1 day bars.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Continue to get 'floating-point division by zero' error

Postby evdl » 16 Mar 2015

This error has to do with a value you try to divide by a value that is 0.

Maybe it is the close of data1 that is not giving a value right from the start of the script.

Can you try:

Code: Select all


if DollarsToTrade > 0
and Close of data1 > 0
then vShares = round( DollarsToTrade / close of data1, 0 ) ;

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Continue to get 'floating-point division by zero' error

Postby tony » 16 Mar 2015

Some where in a calculation you are possibly dividing by zero. I say possibly, because there could be an instance where a variable in the denominator of a division equation could be 0. I see a quick look in your code you have a line that says "If value1 <> 0 then value2 = value3 / value1" that may be the cause right there. Change it to "(value2 * value1) = value3" and at least in that instance you will have removed a chance of dividing by zero, causing the error. But there could be more like that.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Continue to get 'floating-point division by zero' error

Postby tony » 24 Mar 2015

Not sure if you're still working this problem. I happened to come across it the other day when I set up an input variable wrong. It was set to 0 and as a result there was a calculation where I was in essence dividing by 0. Resulting in the same error.

smhuggins
Posts: 12
Joined: 15 Mar 2015
Has thanked: 1 time

Re: Continue to get 'floating-point division by zero' error

Postby smhuggins » 12 May 2015

Hi Tony
Sorry for my tardy reply

Are you still getting the error?

I changed the var set at 0 to 0.00000000001 and it was fixed.

Hope that helps

sim


Return to “MultiCharts”