NexusFi: Find Your Edge


Home Menu

 





Divide By zero error


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #1 (permalink)
 
simon14's Avatar
 simon14 
TORONTO
 
Experience: Advanced
Platform: multi charts
Trading: crude cl
Posts: 19 since Sep 2016
Thanks Given: 10
Thanks Received: 6

I know this is a common problem, and i know the issue.
I just cant seem to solve it!

These are my equations


COTindexC = (CommNet - lowest(CommNet,per))/(highest(CommNet,per)-lowest(CommNet,per))*100;
COTindexS = (noncommNet - lowest(nonCommNet,per))/(highest(nonCommNet,per)-lowest(nonCommNet,per))*100;
COTindexL = (specNet - lowest(specNet,per))/(highest(specNet,per)-lowest(specNet,per))*100;

clearly one of the values is coming up at zero, but how do i create an alternative variable if its zero so that its some obsolete number that will bypass the error.

Ive attached the the full script below...


Thanks in advance for whoever takes the time to help.


Best,
Simon




input: FuturesOnly_Or_FuturesAndOptions_1_or_2( 1 ),per(10) ;

variables:

Initialized( false ),
FieldNamePrefix( "" ),
CommLongFieldNme( "" ),
CommShortFieldNme( "" ),
NonCommLongFieldNme( "" ),
NonCommShortFieldNme( "" ),
SpecLongFieldNme( "" ),
SpecShortFieldNme( "" ),
CommLong( 0 ),
oCommLongErr( 0 ),
CommShort( 0 ),
oCommShortErr( 0 ),
NonCommLong( 0 ),
oNonCommLongErr( 0 ),
NonCommShort( 0 ),
oNonCommShortErr( 0 ),
SpecLong( 0 ),
oSpecLongErr( 0 ),
SpecShort( 0 ),
oSpecShortErr( 0 ),
CommNet( 0 ),
NonCommNet( 0 ),
SpecNet( 0 ) ;

var: COTIndexC(0), COTIndexS(0), COTIndexL(0);


if Initialized = false then
begin
if Category > 0 then
RaiseRuntimeError( "Commitments of Traders studies can be applied only to" +
" futures symbols." ) ;
Initialized = true ;
FieldNamePrefix = IffString( FuturesOnly_Or_FuturesAndOptions_1_or_2 = 1,
"COTF-", "COTC-" ) ;
CommLongFieldNme = FieldNamePrefix + "12" ;
CommShortFieldNme = FieldNamePrefix + "13" ;
NonCommLongFieldNme = FieldNamePrefix + "9" ;
NonCommShortFieldNme = FieldNamePrefix + "10" ;
SpecLongFieldNme = FieldNamePrefix + "16" ;
SpecShortFieldNme = FieldNamePrefix + "17" ;
end ;

CommLong = FundValue( CommLongFieldNme, 0, oCommLongErr ) ;
CommShort = FundValue( CommShortFieldNme, 0, oCommShortErr) ;
NonCommLong = FundValue( NonCommLongFieldNme, 0, oNonCommLongErr ) ;
NonCommShort = FundValue( NonCommShortFieldNme, 0, oNonCommShortErr );
SpecLong = FundValue( SpecLongFieldNme, 0, oSpecLongErr ) ;
SpecShort = FundValue( SpecShortFieldNme, 0, oSpecShortErr ) ;

if oCommLongErr = fdrOk and oCommShortErr = fdrOk then
begin
CommNet = CommLong - CommShort ; //commercials
end ;

if oNonCommLongErr = fdrOk and oNonCommShortErr = fdrOk then
begin
NonCommNet = NonCommLong - NonCommShort ;//large traders
end ;

if oSpecLongErr = fdrOk and oSpecShortErr = fdrOk then
begin
SpecNet = SpecLong - SpecShort ; //small speculators
end ;



Plot1( cotindexC, "Comm" ) ;
//SetPlotColor(1,darkcyan );
Plot2( cotindexL, "Large" ) ;
//SetPlotColor(2, green);
Plot3( cotindexS, "Small" ) ;
//SetPlotColor(3, red);


Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Trump Media to sell instant access to market-moving soci …
Traders Hideout
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
CFTC Rewrites the Rulebook -- Kalshi Cracks $1B Non-Spor …
Prediction Markets & Event Contracts
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 
ShadowFox's Avatar
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 129 since Jun 2020
Thanks Given: 70
Thanks Received: 159

Wow thanks for this gem!

In regards to the error, I solved just using an iff statement to check whether the denominator is zero.

COTindexC = iff((highest(CommNet,per)-lowest(CommNet,per)) = 0, 0, (CommNet - lowest(CommNet,per))/(highest(CommNet,per)-lowest(CommNet,per))*100);
COTindexS = iff((highest(nonCommNet,per)-lowest(nonCommNet,per)) = 0, 0, (noncommNet - lowest(nonCommNet,per))/(highest(nonCommNet,per)-lowest(nonCommNet,per))*100);
COTindexL = iff((highest(specNet,per)-lowest(specNet,per)) = 0, 0, (specNet - lowest(specNet,per))/(highest(specNet,per)-lowest(specNet,per))*100);


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on September 15, 2021


© 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