Divide By zero error - futures io
futures io



Divide By zero error


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,886 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. 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)

 
Search this Thread
 

Divide By zero error

(login for full post details)
  #1 (permalink)
 simon14 
TORONTO
 
Experience: Advanced
Platform: multi charts
Trading: crude cl
 
simon14's Avatar
 
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);

Started this thread Reply With Quote
The following 2 users say Thank You to simon14 for this post:

Can you help answer these questions
from other members on futures io?
Market on Close data within IB
Platforms and Indicators
Big Mo Indicator for NT8
NinjaTrader
in depth understanding of last, bid, and ask volume in c …
NinjaTrader
Anyone ever use "Seasonax" website?
Trading Reviews and Vendors
NT8 Order Management Strategy
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Is anyone actually making money?
52 thanks
An embarrassing, honest confession
37 thanks
Sierra vs. Ninja : why I chose .....
8 thanks
Machine Learning Journal
5 thanks
Institutional Grade Massive Data Dump for Quant Research …
5 thanks
 
(login for full post details)
  #2 (permalink)
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
 
ShadowFox's Avatar
 
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);

Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to ShadowFox for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Divide By zero error


Last Updated on September 15, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts