Storing price in a label?

melfice_187

New member
Hoping someone can help me out with this. I'm trying to store the price(close) when the RSI crosses a certain value and store it as a label.
E.g., If RSI crosses the overbough line(70) get price and store it as a label.

Code:
AddLabel(yes, if RSI crosses below OverBought then AsDollars(close) else ????, Color.RED);
 

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

Is there any way to just store it once? This seems to keep updating as the price plays out. I would like to store it as soon as it crosses the overbought and hold that price level.
 
Is there any way to just store it once? This seems to keep updating as the price plays out. I would like to store it as soon as it crosses the overbought and hold that price level.

No, all variables must be updated for every bar/candle... The method is called using a "state" variable...
 
@magus one of the ways that I have seen for storing data and carrying it forward is with the barNumber() function.
Here is one example:
uGAlzfK.png

https://usethinkscript.com/threads/psar-transition-indicator-for-thinkorswim.1130/
Is this somewhat of what you are trying to do?
 
Thank you @rad14733 and @MerryDay for the follow up responses. I'm coming from C# and javascript so sometimes my way of thinking doesn't translate to thinkscript.

in C# and Javascript there are things you can do to the system to trigger on events or run something on tick(update) only once.

Essentially what I'm trying to achieve is
  • start checking price once RSI reaches above 70
  • evaluate the last (x)bars since RSI went above 70
  • check which RSI level was the highest and store it
  • get a float price at highest RSI level
  • evaluate current bar, if RSI is now lower than the highest point, stop checking and set the float price at highest RSI level
 
Thank you @rad14733 and @MerryDay for the follow up responses. I'm coming from C# and javascript so sometimes my way of thinking doesn't translate to thinkscript.

in C# and Javascript there are things you can do to the system to trigger on events or run something on tick(update) only once.

Essentially what I'm trying to achieve is
  • start checking price once RSI reaches above 70
  • evaluate the last (x)bars since RSI went above 70
  • check which RSI level was the highest and store it
  • get a float price at highest RSI level
  • evaluate current bar, if RSI is now lower than the highest point, stop checking and set the float price at highest RSI level

See if this helps.
Code:
#20210531 Sleepyz - Usethinkscript request @Magus
#Criteria
    #start checking price once RSI reaches above 70
    #evaluate the last (x)bars since RSI went above 70
    #check which RSI level was the highest and store it
    #get a float price at highest RSI level
    #evaluate current bar, if RSI is now lower than the highest point, stop checking and set the float     
    #price at highest RSI level

input xbars    = 3;#Hint xbars: number of bars after RSI crosses above 70
def signal     = RSI().RSI crosses above 70;
def test       = HighestAll(if signal then BarNumber() else Double.NaN);
def hrsi       = CompoundValue(1, if GetDay() == GetLastDay() and
                                 GetTime() > RegularTradingStart(GetYYYYMMDD()) and signal == 1
                                 then RSI() else if RSI() >= 70 and RSI() > hrsi[1] and
                                 Between(BarNumber(), test, HighestAll(test + xbars))
                                 then RSI()
                                 else hrsi[1], 0);
def hrsiclose  = HighestAll(if RSI() == hrsi then close else Double.NaN);
def floatclose = if rsi()<hrsi then hrsiclose else close;
AddLabel(1, hrsi + " " + floatclose );
Capture.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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