Hi.
I'm receiving a floating point (division by zero error) in the following formula:
(1-value1/value2)*100
How can I remove the error?
Is there another way to write the above formula?
regards
ptcman
One way to remove a division by zero error where you expect this to happen is to introduce an IF statement
If value2 = then 0 else (1-value1/value2)*100 ;
Charlton
In that case decide what you want the result to become - let's call it n and the formula becomesIMO: The cell shouldn't be = 0 if value2 is = 0. That is incorrect.
In that case decide what you want the result to become - let's call it n and the formula becomes
If value2 = then n else (1-value1/value2)*100 ;
It's really a question of what you want the value to be if the calculation fails to work because you are dividing by zero.
What would you suggest the result should be ?
Charlton
PtcmanImagine this:
(1-value1=30/value2=62)*100
Let me add that, value2 is always higher than value1
This formula will produce in some bars, negative results. How is that possible? I assume that it is because of that division by zero error.
{ *Variables*}
vars : cls(0), dRng(0);
vars : inRng(true), upRng(true), dnRng(true), inBulRng(0), pctBul(0);
vars : in1Bul(0), in2Bul(0), up1Bul(0), up2Bul(0), dn1Bul(0), dn2Bul(0),bulRng(0);
{ *Variable declaration* }
cls = close[1];
inRng = high > cls and low < cls;
{ *Daily Range* }
if high < cls then begin
dRng = cls - low;
end
else
if low > cls then begin
dRng = high - cls;
end
else
if high > cls and low < cls then begin
dRng = high - low;
end;
{ *Inside Range 1st version* }
if inRng then begin
in1Bul = high - open;
in2Bul = close - low;
bulRng = (in1Bul + in2Bul) * 0.5;
end;
{ *Inside Range 2nd version
if inRng then begin
in1Bul = high - open;
end
else
in1Bul = 0;
if inRng then begin
in2Bul = close - low;
end
else
in2Bul = 0;
inBulRng = (in1Bul + in2Bul) * 0.5;
if inRng then begin
bulRng = inBulRng;
end;
*}
{ *Percentage Range }
pctBul = (1-bulRng/dRng)*100;
{ *Plot im own Window* }
plot1(pctBul);
PtchmanOK.
Here is a similar formula that produces the same error.
I've made two versions of the "bulRng" variable to see if there was a problem with the first one but the result is the same.
Notice how there are a couple of bars where the result is negative.
Code:{ *Variables*} vars : cls(0), dRng(0); vars : inRng(true), upRng(true), dnRng(true), inBulRng(0), pctBul(0); vars : in1Bul(0), in2Bul(0), up1Bul(0), up2Bul(0), dn1Bul(0), dn2Bul(0),bulRng(0); { *Variable declaration* } cls = close[1]; inRng = high > cls and low < cls; { *Daily Range* } if high < cls then begin dRng = cls - low; end else if low > cls then begin dRng = high - cls; end else if high > cls and low < cls then begin dRng = high - low; end; { *Inside Range 1st version* } if inRng then begin in1Bul = high - open; in2Bul = close - low; bulRng = (in1Bul + in2Bul) * 0.5; end; { *Inside Range 2nd version if inRng then begin in1Bul = high - open; end else in1Bul = 0; if inRng then begin in2Bul = close - low; end else in2Bul = 0; inBulRng = (in1Bul + in2Bul) * 0.5; if inRng then begin bulRng = inBulRng; end; *} { *Percentage Range } pctBul = (1-bulRng/dRng)*100; { *Plot im own Window* } plot1(pctBul);
I tested the Print() as you advised and I didn't find any zero result
I just can't see where is the problem
PS: I forgot to say that I´m using Multicharts and not Tradestation
{ *Variables*}
vars : cls(0), dRng(0);
vars : inRng(true), upRng(true), dnRng(true), inBulRng(0), pctBul(0);
vars : in1Bul(0), in2Bul(0), up1Bul(0), up2Bul(0), dn1Bul(0), dn2Bul(0),bulRng(0);
{ *Variable declaration* }
cls = close[1];
inRng = high > cls and low < cls;
upRng = low >= cls;
dnRng = high <= cls;
{ *Daily Range* }
if dnRng then begin
dRng = cls - low;
end
else
if upRng then begin
dRng = high - cls;
end
else
if inRng then begin
dRng = high - low;
end;
{ *Inside Range 1st version* }
if inRng then begin
in1Bul = high - open;
in2Bul = close - low;
bulRng = (in1Bul + in2Bul) * 0.5;
end;
{ *Percentage Range }
pctBul = (1-bulRng/dRng)*100;
{ *Plot in own Window* }
plot1(pctBul);
{ *Plot in own window upRng, dnRng and inRng conditions*
plot1(high<=cls);
plot2(low>=cls);
plot3(high>cls and low<cls); }
The barstatus has the values 2= closing tick of the bar, 1 = a tick within the bar, 0 = opening tick of bar.Hi Charlton.
I've tested BarStatus() but I'm having difficulty in understanding the concept.
plot1(barstatus);
As far as I could see, when a new bar iniciates (open price) the barstatus() plots 2 and after that plots 1 until the end of the, in this case, 5 min bar althouht this is a bit different of what EL manual says about barstatus()
Can you give me a hint on how to apply it, I'm clueless.
You've mentioned that the open price is static, but isn't the high and low of each bar also static after they've been made? For example, a bar opens and starts to rise. Then starts to come back towards the open, so that high has become static, right?
The only value that will truly become static at the end of the bar is the close, right?
Fernando
Hi.
I'm receiving a floating point (division by zero error) in the following formula:
(1-value1/value2)*100
How can I remove the error?
Is there another way to write the above formula?
regards
ptcman
Hi.
I appreciate all the help that you are giving me but I'm starting to go crazy here.
I simply cannot open the study, plotted in the #11 post of this thread, on a intraday chart because I'm always receiving a floating point error.
The only way for that error dissapear is to use BPV option but that produce completely useless data
You said that you don't receive any error? How is that possible? In this case, the message that MC gives is a floating point error, not a divison by zero error.
My god, how can a simple formula give so much problems?
Hi.
I appreciate all the help that you are giving me but I'm starting to go crazy here.
I simply cannot open the study, plotted in the #11 post of this thread, on a intraday chart because I'm always receiving a floating point error.
The only way for that error dissapear is to use BPV option but that produce completely useless data
You said that you don't receive any error? How is that possible? In this case, the message that MC gives is a floating point error, not a divison by zero error.
My god, how can a simple formula give so much problems?