calculate difference between today and specific previous date

abotoni

New member
would like to ask for help creating a study that calculates the difference between last price and the closing price on a certain previous date like 05/13/2021
 
Not a script, but the trend line drawing tool will do that for you. Make sure in the settings that "snap drawings to" is set to OHLC, then on the chart middle mouse click or choose drawing tools from chart menu, choose the trend line tool -> click on the two points of interest. You will get time, number of bars, move points, move percent, angle of line. Please note these before clicking on the second point, as this data disappears. I use this all the time to get points and percent of moves.
 
Thanks. That helps for one stock at a time but I want to use it as a scanning tool.

See if this helps. The label code is only included for debugging and needs to be removed for scanning.

Code:
input date      = 20210513;
def prior_close = if GetYYYYMMDD() == date
                  then close
                   else prior_close[1];
def close_diff  = close - prior_close;
plot scan       = close_diff > 0;;

input showlabel = yes;
AddLabel(showlabel,  "Today Close: " + AsText(close)
                   + "  " + AsPrice(date) + " Close: " + AsText(prior_close)
                   + "  Diff: " + AsText(close_diff),
                     if close_diff >= 0
                     then Color.LIGHT_GREEN
                     else Color.PINK);
 
See if this helps. The label code is only included for debugging and needs to be removed for scanning.

Code:
input date      = 20210513;
def prior_close = if GetYYYYMMDD() == date
                  then close
                   else prior_close[1];
def close_diff  = close - prior_close;
plot scan       = close_diff > 0;;

input showlabel = yes;
AddLabel(showlabel,  "Today Close: " + AsText(close)
                   + "  " + AsPrice(date) + " Close: " + AsText(prior_close)
                   + "  Diff: " + AsText(close_diff),
                     if close_diff >= 0
                     then Color.LIGHT_GREEN
                     else Color.PINK);
works like magic! thanks
 

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
189 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