• Get $40 off VIP by signing up for a free account! Sign Up

Previous "five" days close price

rezameri

New member
Hello! I want to plot the previous day close price for the last "five" days only on my daily chart. I have written the following, but it plots the close price for every single day on my daily chart. Is there a way to only show the price line on the last five (or any arbitrary) days? Thank you!

Code:
input timeFrame = {default DAY, WEEK, MONTH};


plot Close = close(period = timeFrame)[1];


Close.SetDefaultColor(Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);
 
Solution
Hello! I want to plot the previous day close price for the last "five" days only on my daily chart. I have written the following, but it plots the close price for every single day on my daily chart. Is there a way to only show the price line on the last five (or any arbitrary) days? Thank you!

Code:
input timeFrame = {default DAY, WEEK, MONTH};


plot Close = close(period = timeFrame)[1];


Close.SetDefaultColor(Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);

This code will plot the last 5 days close, all on the current day only or extended from each day to the right edge, based upon your choice at the input screen.

Capture.jpg
Ruby:
declare upper;

script x {
    def ymd      = GetYYYYMMDD();
    def...
Hello! I want to plot the previous day close price for the last "five" days only on my daily chart. I have written the following, but it plots the close price for every single day on my daily chart. Is there a way to only show the price line on the last five (or any arbitrary) days? Thank you!

Code:
input timeFrame = {default DAY, WEEK, MONTH};


plot Close = close(period = timeFrame)[1];


Close.SetDefaultColor(Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);

This code will plot the last 5 days close, all on the current day only or extended from each day to the right edge, based upon your choice at the input screen.

Capture.jpg
Ruby:
declare upper;

script x {
    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;


    input count  = 5;
    input extend = 5;
    def c        = if thisDay == count and SecondsFromTime(1600) < 0 then Double.NaN else if thisDay == count and SecondsFromTime(1600) == 0 then close else c[1];
    def CDPext   = if thisDay == count then c else CDPext[1];
    input show_all_on_today = yes;
    plot CDP     = if show_all_on_today == yes and thisDay == 0
                   and Between(thisDay, count - extend, count) and CDPext
                   then CDPext
                   else if show_all_on_today == no and thisDay >= 0
                   and Between(thisDay, count - extend, count) and CDPext
                   then CDPext
                   else Double.NaN ;
}
input show_all_on_today = yes;
input extend            = 5;
plot cdp1 = x(count = 1, extend = extend, "show all on today" = show_all_on_today);
plot cdp2 = x(count = 2, extend = extend, "show all on today" = show_all_on_today);
plot cdp3 = x(count = 3, extend = extend, "show all on today" = show_all_on_today);
plot cdp4 = x(count = 4, extend = extend, "show all on today" = show_all_on_today);
plot cdp5 = x(count = 5, extend = extend, "show all on today" = show_all_on_today);


cdp1.SetDefaultColor(Color.YELLOW);
cdp1.SetLineWeight(2);
cdp1.SetPaintingStrategy(PaintingStrategy.DASHES);
cdp2.SetDefaultColor(Color.YELLOW);
cdp2.SetLineWeight(2);
cdp2.SetPaintingStrategy(PaintingStrategy.DASHES);
cdp3.SetDefaultColor(Color.YELLOW);
cdp3.SetLineWeight(2);
cdp3.SetPaintingStrategy(PaintingStrategy.DASHES);
cdp4.SetDefaultColor(Color.YELLOW);
cdp4.SetLineWeight(2);
cdp4.SetPaintingStrategy(PaintingStrategy.DASHES);
cdp5.SetDefaultColor(Color.YELLOW);
cdp5.SetLineWeight(2);
cdp5.SetPaintingStrategy(PaintingStrategy.DASHES);

input showbubbles = yes;
input bubblemover = 5;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), cdp1[b], "C1", Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), cdp2[b], "C2", Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), cdp3[b], "C3", Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), cdp4[b], "C4", Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), cdp5[b], "C5", Color.WHITE);
 
Last edited:
Solution

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