NexusFi: Find Your Edge


Home Menu

 





Kelly Money Management Multicharts [EXCEPTION} Floating-point invalid operation.


Discussion in MultiCharts

Updated
    1. trending_up 2,381 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
BrianMichaelWall
Kitchener Ontario Canada
 
Posts: 1 since Mar 2020
Thanks Given: 0
Thanks Received: 0

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");


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
Thanks Mike. Godspeed.
The Elite Circle
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
1 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

BrianMichaelWall,

it's a good practice to add checks for every division done within your code. The code snippet below contains several divisions without "protective" checks and these might cause the error.

Without any trades any reserved word returning the number of trades (or winning/losing trades) will return zero for example.

Regards,

ABCTG


BrianMichaelWall View Post
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");


Follow me on X Reply With Quote
  #3 (permalink)
Midline
Basking Ridge
 
Posts: 7 since Mar 2020
Thanks Given: 2
Thanks Received: 9


I'm new to Easylanguage but I notice that you're checking for 0 values after you do the divisions therefore the exception gets thrown and execution halts before you check for 0 values.. You might find the offending 0 value if you move the divisions below after checking for 0 values.

Typically you would check for zero in an if statement before conducting the division.


Reply With Quote




Last Updated on March 29, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts