I've coded a Kelly

money management signal for

Multicharts off of the risk capital set and I've been getting the error: [EXCEPTION} Floating-point invalid operation.

I've searched for the solution, and found that others have gotten around the problem by removing the scenario where their equation divides by zero.

I've tried to identify where there is a zero that I'm dividing by, and attempted to add exceptions however the error persists.

I havn't put any code in my signal code to associate to the money management code.

Any advice is appreciated.

//#Number of Units = Account Total * Risk Capital * ( Kelly Ratio % - Win % Change Buffer )

//Kelly Ratio = % of trades that win - (1 - % of trades that win) / ($ Winnings per trade / Expected Loss per trade)

---------------------------------------------------------------------------------------------------

Vars:

GL( 0 ),

GP( 0 ),

NWT( 0 ),

TT( 0 ),

Tradevolume( 0 ),

Equity( 0 ),

ProfitFactor( 0 ),

WTP( 0 ),

KellyCriterion( 0 ),

Kelly( 0 );

//Equity

Equity = Round ((InitialCapital + NetProfit + OpenPositionProfit),0);

//Kelly Criterion Variables

GL = grossloss/numlostrades;

GP = grossprofit/numwintrades;

NWT = Numwintrades;

TT = Totaltrades;

//Kelly Criterion Calculation

kelly[(NWT/TT) - (1-(NWT/TT)/(GP/GL))];

//Entries

If Entryprice > 0

Then pmms_strategy_set_entry_contracts(0,((Equity * Kelly)/Entryprice));

//Exceptions

IF GL=0 then raiseruntimeerror("!!!alarm GL=0");

IF GP=0 then raiseruntimeerror("!!!alarm GP=0");

IF NWT=0 then raiseruntimeerror("!!!alarm NWT=0");

IF TT=0 then raiseruntimeerror("!!!alarm TT=0");

IF Tradevolume=0 then raiseruntimeerror("!!!alarm Tradevolume=0");

IF Equity=0 then raiseruntimeerror("!!!alarm Equity=0");

IF ProfitFactor=0 then raiseruntimeerror("!!!alarm ProfitFactor=0");

IF WTP=0 then raiseruntimeerror("!!!alarm WTP=0");

IF KellyCriterion=0 then raiseruntimeerror("!!!alarm KellyCriterion=0");

IF Kelly=0 then raiseruntimeerror("!!!alarm Kelly=0");

If Entryprice = 0 then raiseruntimeerror("!!!alarm Entryprice=0");