Toggling Signal Line Color

utsbigdiggy

New member
Tried searching for this but maybe I don't know how to word it. Is there a way to change the color of the signal line of an indicator to the last signal? For example.. lets say I have an RSI with an overbought (OB) and oversold(OS) level.. There are the arrows for the buy and sell as we cross into OB or OS territory.. I can even change the color of the RSI line WHILE it remains in OB and OS territory BUT.. how do I get it to remain the LAST color until a condition is met to flip it? If I want to to go red when it crosses above OB and remain red until it crosses below OS.. how would I do that? I feel like maybe somehow I have it look for a new signal color and if there isn't one keep the color from one bar ago? I cannot think of the syntax but am I on the right track? Thanks in advance!
 
Solution
Tried searching for this but maybe I don't know how to word it. Is there a way to change the color of the signal line of an indicator to the last signal? For example.. lets say I have an RSI with an overbought (OB) and oversold(OS) level.. There are the arrows for the buy and sell as we cross into OB or OS territory.. I can even change the color of the RSI line WHILE it remains in OB and OS territory BUT.. how do I get it to remain the LAST color until a condition is met to flip it? If I want to to go red when it crosses above OB and remain red until it crosses below OS.. how would I do that? I feel like maybe somehow I have it look for a new signal color and if there isn't one keep the color from one bar ago? I cannot think of the...
Tried searching for this but maybe I don't know how to word it. Is there a way to change the color of the signal line of an indicator to the last signal? For example.. lets say I have an RSI with an overbought (OB) and oversold(OS) level.. There are the arrows for the buy and sell as we cross into OB or OS territory.. I can even change the color of the RSI line WHILE it remains in OB and OS territory BUT.. how do I get it to remain the LAST color until a condition is met to flip it? If I want to to go red when it crosses above OB and remain red until it crosses below OS.. how would I do that? I feel like maybe somehow I have it look for a new signal color and if there isn't one keep the color from one bar ago? I cannot think of the syntax but am I on the right track? Thanks in advance!

If you want something to change on the current bar, based on something happening in the future, you need a way to read future bars. you need a way to save the last value of rsi, to all bars of a variable, so it is available to be read at bar #1 and every other bar.
You could do that with highestall or negative offsets.
Then use this future rsi value to determine the color and the current rsi value to determine the line location.

Code:
declare lower;
def rsi = rsi();
def last_bar = highestall( if !isnan(close) then barnumber() else 0);
def last_rsi = highestall( if last_bar == barnumber() then rsi else 0);
plot z = rsi;
z.assignvaluecolor( if last_rsi > 70 then color.red else if last_rsi < 30 then color.green else color.yellow);

or modify one of these studies, that use a large negative offset, to read a future value.
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
 
Last edited:
Solution

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

If you want something to change on the current bar, based on something happening in the future, you need a way to read future bars. you need a way to save the last value of rsi, to all bars of a variable, so it is available to be read at bar #1 and every other bar.
You could do that with highestall or negative offsets.
Then use this future rsi value to determine the color and the current rsi value to determine the line location.

Code:
declare lower;
def rsi = rsi();
def last_bar = highestall( if !isnan(close) then barnumber() else 0);
def last_rsi = highestall( if last_bar == barnumber() then rsi else 0);
plot z = rsi;
z.assignvaluecolor( if last_rsi > 70 then color.red else if last_rsi < 30 then color.green else color.yellow);

or modify one of these studies, that use a large negative offset, to read a future value.
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
I'll play with that and see if it gives me what I want but I don't "think" it will.. I want the present and the past.. In other words.. check if there is a new signal (cross above >70 or cross below <30) if there is a new signal change the color of the RSI to the new signal color (red or green) otherwise use the color from one bar prior.
 
I'll play with that and see if it gives me what I want but I don't "think" it will.. I want the present and the past.. In other words.. check if there is a new signal (cross above >70 or cross below <30) if there is a new signal change the color of the RSI to the new signal color (red or green) otherwise use the color from one bar prior.

Maybe I don't fully understand the rules you are trying to follow.
Maybe this will give you some ideas. it uses different ranges of rsi numbers to assign colors
https://usethinkscript.com/threads/rsi-with-vertical-colors-for-thinkorswim.10347/#post-92582
 
Maybe I don't fully understand the rules you are trying to follow.
Maybe this will give you some ideas. it uses different ranges of rsi numbers to assign colors
https://usethinkscript.com/threads/rsi-with-vertical-colors-for-thinkorswim.10347/#post-92582
Thank you for trying to help me. Basically I don't want the RSI line to change between three colors like it seems most do (Overbought, Oversold, Normal) I want the color to reflect the last entry or exit signal until a new signal occurs.. So if the RSI in Dec crossed above 70 I have a red down arrow and the RSI line turns red.. MOST then will go grey or yellow when it crosses back below 70.. I don't want that.. I want the RSI line to remain red until it crosses below 30.. then there is an up arrow plotted and the RSI line turns green.. then it stays green as it travels above 30 and it remains green until crossing back above the red... The purpose of this is that I have some slow moving indicators that only flip on rare occasions.. and I dont want to have to scroll back in time to find the last signal. I want to eyeball the current indicator line and know what the last signal was.
 
Ok... getting closer... I have the script record the date of each signal and toggle the color of the line based on which date is more recent BUT the date is null unless the timeframe of my chart is longer than the last signals .. SO.. new question.. how can I have the study look back further than my chart is set to?
 
Ok... getting closer... I have the script record the date of each signal and toggle the color of the line based on which date is more recent BUT the date is null unless the timeframe of my chart is longer than the last signals .. SO.. new question.. how can I have the study look back further than my chart is set to?
The ToS platform does not provide for a study to look back further than a chart is set to.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
236 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