NexusFi: Find Your Edge


Home Menu

 





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


Discussion in MultiCharts

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




 
Search this Thread

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

  #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?
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
43 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

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 Twitter 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts