Divide By Zero Error even though I am checking first - futures io
futures io



Divide By Zero Error even though I am checking first


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,100 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 1 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 even though I am checking first

(login for full post details)
  #1 (permalink)
gurji
Miami, Florida
 
 
Posts: 29 since Apr 2022
Thanks: 1 given, 8 received

Hi all,

I'm still new to easylanguage, but I can't figure this out.

I keep getting a divide by zero error even though the very first thing I am doing is to test if any of the denominators is 0.

 
Code
if (absvalue(open[1] - close[1]) > 0) Then
	if (curDirection = -1) Then
		olp = ((high - close[1]) / (open[1] - close[1]));
		if (curDirection = 1) Then
			if (low > close[1]) Then
				olp = (((low - close[1])*-1) / (close[1] - open[1])) Else
				olp = (absvalue(low - close[1]) / (close[1] - open[1])) Else
				olp = 0;
Any help is much appreciated!

Reply With Quote

Can you help answer these questions
from other members on futures io?
Market on Close data within IB
Platforms and Indicators
How do I create Strategy with the Second Entry indicator
NinjaTrader
help with take profit several targets
TradeStation
in depth understanding of last, bid, and ask volume in c …
NinjaTrader
How to pay for market data with Dorman LLC
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Is anyone actually making money?
88 thanks
An embarrassing, honest confession
25 thanks
Sierra vs. Ninja : why I chose .....
8 thanks
ApexTraderFunding.com experience and review
8 thanks
Want your NinjaTrader indicator created, free?
7 thanks
 
(login for full post details)
  #2 (permalink)
 Silver Dragon 
Cincinnati Ohio
 
Experience: Intermediate
Platform: TastyWorks / NT
Broker: TastyWorks /NT
Trading: FX, Stocks, Options
 
Silver Dragon's Avatar
 
Posts: 2,085 since Feb 2011
Thanks: 6,189 given, 5,154 received


gurji View Post
Hi all,

I'm still new to easylanguage, but I can't figure this out.

I keep getting a divide by zero error even though the very first thing I am doing is to test if any of the denominators is 0.

 
Code
if (absvalue(open[1] - close[1]) > 0) Then
	if (curDirection = -1) Then
		olp = ((high - close[1]) / (open[1] - close[1]));
		if (curDirection = 1) Then
			if (low > close[1]) Then
				olp = (((low - close[1])*-1) / (close[1] - open[1])) Else
				olp = (absvalue(low - close[1]) / (close[1] - open[1])) Else
				olp = 0;
Any help is much appreciated!

Hi @gurji,

I dont have access to easylanguage, however I put your formulas into Excel. The only scenario I came up where div by zero error came up is when Close1 is zero. Perhaps try putting a check around the Open1 and Close1 to make sure they are both > than zero or absvalue(open[1] - close[1]) > 0 does not equal open[1] .

example:
if (absvalue(open[1] - close[1]) > 0 and absvalue(open[1] - close[1]) <> open[1])

Robert


nosce te ipsum

You make your own opportunities in life.
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #3 (permalink)
gurji
Miami, Florida
 
 
Posts: 29 since Apr 2022
Thanks: 1 given, 8 received


Hi, thanks for the reply, but thats not it.

I just confirmed a that when a number divided by a number with a decimal WHEN USING a VARIABLE, causes the error.

So for example, right now, I have this:


 
Code
qqq = 0.53234;
yyy = absvalue(open[1] - close[1]);  // (yyy equals 0.08 exactly.  No rounding)
zzz = 4545/0.08;

This works.
But this fails:


qqq = 0.53234;
yyy = absvalue(open[1] - close[1]);  
zzz = 4545/yyy;


Plot1 (zzz);

Reply With Quote
The following user says Thank You to gurji for this post:
 
(login for full post details)
  #4 (permalink)
gurji
Miami, Florida
 
 
Posts: 29 since Apr 2022
Thanks: 1 given, 8 received

Ok, I solved the issue. Hopefully this might help someone else.
Basically, I wrote the IF statements to test for zero in a different way using <> 0 instead of > 0, and also I put the test around each direction, instead of the whole thing.
Not sure why all that matters, but it worked.

 
Code
if ((curDirection = -1) and ((open[1] - close[1]) <> 0)) Then
	olp = ((high - close[1]) / (open[1] - close[1]));
	if ((curDirection = 1) and ((close[1] - open[1]) <> 0)) Then
		if (low > close[1]) Then
			olp = (((low - close[1])*-1) / (close[1] - open[1])) Else
			olp = (absvalue(low - close[1]) / (close[1] - open[1])) Else
			olp = 0;

Reply With Quote
The following user says Thank You to gurji for this post:
 
(login for full post details)
  #5 (permalink)
erdocdpb
phoenix arizona
 
 
Posts: 6 since Apr 2015
Thanks: 0 given, 0 received

Tradestation wants you to code this, this way:

nameofyourchoosing = open[1] -close[1]
if ((curDirection = -1) and ((open[1] - close[1]) <> 0)) Then
olp = iff(nameofyourchoosing <> 0, ((high - close[1]) / (nameofyourchoosing)), olp[1]);
if ((curDirection = 1) and ((nameofyourchoosing) <> 0)) Then
if (low > close[1]) Then
olp = iff(nameofyourchoosing <> 0, (((low - close[1])*-1) / (nameofourchoosing))olp[1]), Else
olp = iff(nameofyourchoosing <> 0,(absvalue(low - close[1]) / (nameofyourchoosing)), olp[1]), Else
olp = 0;


...in order to avoid the divide by zero error.

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Divide By Zero Error even though I am checking first


Last Updated on September 18, 2022


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