[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EL Divide by zero error



PureBytes Links

Trading Reference Links

I really need help here, am testing the below code

I had several other conditions in the code  but as I was getting errors I
deleted most of them to try and eliminate these and narrow down the problem.
But I am unable to work it out.

It verifies OK but when I run it gives me the runtime error re dividing by
zero. for  the following

If I have the Mult set to 1.2 it works, if I optimize say from .5 to 1.2 I
get the dividing by  zero error

If I change the Buy order from
Open Next Bar + (Average(Range,5)*Mult) stop;
to
at market, it gives the dividing by zero error

If I change (this is only for testing the code) the FirstDayPrft exit from
Open Next Bar + (Average(Range,5)*Mult)* 2 limit
to
Open Next Bar - (Average(Range,5)*Mult)* 2 limit
it gives the dividing by  zero error again

Code:

Inputs: Mult(1.2),LossPcnt(2.5),Low_Cl(2),ContSize(5000);

Vars: RunningCapital(1),Capital(15000),Conts(0),Max_Loss(0);
Vars:   MaxPntRsk(0);

Conts    = Floor((NetProfit+1)/ContSize) + 1;
RunningCapital = Capital + NetProfit;
MaxPntRsk   = ((LossPcnt/100)*RunningCapital)/BigPointValue;
Max_Loss  = Ceiling(MaxPntRsk/Conts);
If Max_Loss > Average(Truerange,34)
  then Max_Loss = Average(Truerange,34);
If Conts < 1  then Conts = 1;
If Conts > 10 then Conts = 10;

Condition10  = Close < Lowest(Close[1],Low_Cl);
Condition20  = Xaverage(C,13) < Xaverage(C,34);

If CurrentBar > 1 and MarketPosition <>1 then begin
 If  Condition10 and Condition20
 then buy(" Contracts") Conts Contracts at
     Open Next Bar + (Average(Range,5)*Mult) stop;
end;

If MarketPosition <>1 then begin
 Exitlong("FirstDayPrft") at
  Open Next Bar + (Average(Range,5)*Mult)* 2 limit;
 Exitlong("1stDayLoss") at
  (Open Next Bar + Average(Range,5)*Mult) - Max_loss stop;
end;

If MarketPosition = 1 then begin
 If open of next bar > entryprice then
  exitlong("BailOut") at market;
 exitlong("Max_Loss")EntryPrice - Max_loss stop;
end;




Mel



Mel