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

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:
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;
 
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.
 
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
 
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.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
300 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top