Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Divide By zero error
Updated September 15, 2021
trending_up
3,106 views
thumb_up
4 thanks given
group
2 followers
forum
1 posts
attach_file
0 attachments
Divide By zero error
September 15th, 2021, 08:15 AM
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);
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
September 15th, 2021, 04:33 PM
CO/USA
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 129 since Jun 2020
Thanks Given: 70
Thanks Received: 157
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);
Last Updated on September 15, 2021