Issue comparing indicator with "> value" and "< value"
Author: kbellare
Creation Date: 5/18/2013 11:13 AM
profile picture

kbellare

#1
I'm executing Buy/Short signals based on an indicator above 1.04 or below 0.96 (code below). The code is not able to evaluate the following expressions correctly

amaoversma[bar] < (1-slider3.ValueInt/100) // where slider3 is 4
amaoversma[bar] > (1+slider3.ValueInt/100) // slider3 is 4

As shown in the debug log, it prints amaoversma values that are between 0.96 and 1.04. It should only print when amaoversma is <0.96 or >1.04

What am i doing wrong? Pl specify the right code to fix this

------------Debug Log----------------------------------
QUOTE:
Bear, date= 7/17/2012, amaoversma=0.992228216089536, slider3=4
Bull, date= 7/30/2012, amaoversma=1.03764814678449, slider3=4
Bear, date= 10/5/2012, amaoversma=0.976891929373198, slider3=4
Bull, date= 10/19/2012, amaoversma=1.00204790653971, slider3=4
Bear, date= 10/29/2012, amaoversma=0.945458991505152, slider3=4

CODE:
Please log in to see this code.
profile picture

Eugene

#2
And now, try sending "(1-slider3.ValueInt/100)" and "(1+slider3.ValueInt/100)" to the PrintDebug log, where applicable. You'll be surprised.

We've all been there, making this common mistake of performing integer division when we actually meant to do floating point division. Here's the FAQ that answers your question:

I'm trying to divide two numbers and the result is zero.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).