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: 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 ;