Is a boolean correct for this?

 

Hello,

I'm having an issue getting the correct signal from my indicator.

Previously the line of code stated ( if x > 1) and it signalled correctly


now i want it to signal if x is between 1 and 2, but the back test seem erratic, I'm using the code below

if (x > 1 && x < 2) 

it seems as though it'll trigger at any level above 1 and not be capped by level 2

is there a better way of coding this, if so could anyone help please?

Many thanks

 
mql4acc:

Hello,

I'm having an issue getting the correct signal from my indicator.

Previously the line of code stated ( if x > 1) and it signalled correctly


now i want it to signal if x is between 1 and 2, but the back test seem erratic, I'm using the code below

if (x > 1 && x < 2) 

it seems as though it'll trigger at any level above 1 and not be capped by level 2

is there a better way of coding this, if so could anyone help please?

Many thanks

what else is in that part of the code ?

 
mql4acc:

Hello,

I'm having an issue getting the correct signal from my indicator.

Previously the line of code stated ( if x > 1) and it signalled correctly


now i want it to signal if x is between 1 and 2, but the back test seem erratic, I'm using the code below

if (x > 1 && x < 2) 

it seems as though it'll trigger at any level above 1 and not be capped by level 2

is there a better way of coding this, if so could anyone help please?

Many thanks

Is x a double ?
 
andrew4789 #:
Is x a double ?

Hi, I realise it's been a while! yes X was/is a double. thanks

 
mql4acc:

Hello,

I'm having an issue getting the correct signal from my indicator.

Previously the line of code stated ( if x > 1) and it signalled correctly


now i want it to signal if x is between 1 and 2, but the back test seem erratic, I'm using the code below

if (x > 1 && x < 2) 

it seems as though it'll trigger at any level above 1 and not be capped by level 2

is there a better way of coding this, if so could anyone help please?

Many thanks

if (x > 1 && x < 2) is correct. Check how x is calculated — maybe it's not updating or has floating-point issues. Use Print(x) for debugging.