Trading Articles
Article Categories
Article Tools
Divide By zero error
Updated September 15, 2021
trending_up
2,886 views
thumb_up
4 thanks given
group
2 followers
forum
1 posts
attach_file
0 attachments
Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
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 and simple.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
(login for full post details)
#1 (permalink )
TORONTO
Experience: Advanced
Platform: multi charts
Trading: crude cl
Posts: 19 since Sep 2016
Thanks: 10 given,
6
received
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);
The following 2 users say Thank You to simon14 for this post:
Can you help answer these questions from other members on futures io?
Best Threads (Most Thanked) in the last 7 days on futures io
(login for full post details)
#2 (permalink )
CO/USA
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 116 since Jun 2020
Thanks: 69 given,
156
received
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);
The following 2 users say Thank You to ShadowFox for this post:
Last Updated on September 15, 2021
Ongoing