# Help on indicator...price between X and Y conditions always Plots

W

#### Wannaspeed

##### New member
I'm trying to create an indicator that uses yesterday's close price to filter my "def". I have 3 definitions for stocks (over 3, under 0.75, and between 0.75 and 3). They all work, except the one for stocks priced between 0.75 and 3 displays a plot at all times no matter what the stock price is. So on many stocks I end up with 2 plots, the correct one and the between .75-3 plot. Below is the code snippet to the relevant plots.

Code:
``````#plot HHightBetween = if ShowhaltHigh > 0 and Priorclose between 0.75 and 3 then HaltHighBetween else Double.NaN;
plot HHightBetween = if ShowhaltHigh > 0 and Priorclose >=0.75 <=3 then HaltHighBetween else Double.NaN;
plot HLowBEtween = if ShowhaltLow > 0 and Priorclose between .75 and 3 then HaltLowBetween else Double.NaN;
plot HHighUnder = if ShowhaltHigh > 0 and Priorclose <= .75 then HaltHighUnder else Double.NaN;
plot HLowUnder = if ShowhaltLow > 0 and Priorclose <= 0.75 then HaltLowUnder else Double.NaN;
############``````
I've tried many variations to specify the between values for the price. Such as greater than .75 and less than 3, as well as the two top codes for between .75 and 3. I'm not sure why it insists on plotting it. Any help is appreciated

Last edited by a moderator:
T

#### tomsk

##### Well-known member
VIP
I'm trying to create an indicator that uses yesterday's close price to filter my "def". I have 3 definitions for stocks (over 3, under 0.75, and between 0.75 and 3). They all work, except the one for stocks priced between 0.75 and 3 displays a plot at all times no matter what the stock price is. So on many stocks I end up with 2 plots, the correct one and the between .75-3 plot. Below is the code snippet to the relevant plots.
Code:
``````#plot HHightBetween = if ShowhaltHigh > 0 and Priorclose between 0.75 and 3 then HaltHighBetween else Double.NaN;
plot HHightBetween = if ShowhaltHigh > 0 and Priorclose >=0.75 <=3 then HaltHighBetween else Double.NaN;
plot HLowBEtween = if ShowhaltLow > 0 and Priorclose between .75 and 3 then HaltLowBetween else Double.NaN;
plot HHighUnder = if ShowhaltHigh > 0 and Priorclose <= .75 then HaltHighUnder else Double.NaN;
plot HLowUnder = if ShowhaltLow > 0 and Priorclose <= 0.75 then HaltLowUnder else Double.NaN;
############``````
I've tried many variations to specify the between values for the price. Such as greater than .75 and less than 3, as well as the two top codes for between .75 and 3. I'm not sure why it insists on plotting it. Any help is appreciated
Change definition of your plot condition for stocks between 0.75 to 3 as follows:

plot HLowBEtween = if ShowhaltLow > 0 and between(PriorClose, .75, 3) then HaltLowBetween else Double.NaN;

W

#### Wannaspeed

##### New member
Oh thank you so much! I've been working on this for over an hour trying to get it to work correctly. Actually after I posted I found this https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Between.html which got me on the right track for at least some kind of solution. I ended up creating high and low inputs and the following code.
Code:
``````input lowLimit = 0.75;
input highLimit = 3;
plot HHighBetween = if ShowhaltHigh > 0 and priorclose >= lowLimit and priorclose <= highLimit then HaltHighBetween else Double.NaN;``````
This also works, but I prefer your method.

T

#### tomsk

##### Well-known member
VIP
Oh thank you so much! I've been working on this for over an hour trying to get it to work correctly. Actually after I posted I found this https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Between.html which got me on the right track for at least some kind of solution. I ended up creating high and low inputs and the following code.
Code:
``````input lowLimit = 0.75;
input highLimit = 3;
plot HHighBetween = if ShowhaltHigh > 0 and priorclose >= lowLimit and priorclose <= highLimit then HaltHighBetween else Double.NaN;``````
This also works, but I prefer your method.
Just a word of caution when using between(). Make sure the lower value is listed first before the higher value.
In other words between(PriorClose, .75, 3) is fine while between(PriorClose, 3, .75) would not yield you the results you seek
I have seen many programmers miss this point, a small issue but it sure makes a difference !

Good job in researching this @Wannaspeed

• Wannaspeed
W

#### Wannaspeed

##### New member
Just a word of caution when using between(). Make sure the lower value is listed first before the higher value.
In other words between(PriorClose, .75, 3) is fine while between(PriorClose, 3, .75) would not yield you the results you seek
I have seen many programmers miss this point, a small issue but it sure makes a difference !

Good job in researching this @Wannaspeed
Thanks for the tip, I'll keep that in mind for the future.