Extend Price Line to the Right

compupix

New member
How do I extend end of day price lines all the way to the right edge of the chart?

Script:
#PreviousClose
#Draws previous Close when aggregation period is less than Day

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1])
{ PrevDayClose = Double.NaN;
}
else
{ PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

PrevDayClose.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);

End of Script
Current Chart:
https://drive.google.com
Thanks!
 
Solution
How do I extend end of day price lines all the way to the right edge of the chart?

Script:
#PreviousClose
#Draws previous Close when aggregation period is less than Day

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1])
{ PrevDayClose = Double.NaN;
}
else
{ PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

PrevDayClose.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);

End of Script
Current Chart...
How do I extend end of day price lines all the way to the right edge of the chart?

Script:
#PreviousClose
#Draws previous Close when aggregation period is less than Day

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1])
{ PrevDayClose = Double.NaN;
}
else
{ PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

PrevDayClose.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);

End of Script
Current Chart:
https://drive.google.com
Thanks!

To extend the plot of each day's close, it requires each day have a seperate plot that is then extended. See the commented notes in the code below to help understand how your request was done using your code as a basis.

You can add more days by adding 'p()' plots using the logic in creating those six in the code.

Capture.jpg

Ruby:
#PreviousClose
#Draws previous Close when aggregation period is less than Day
script p {
#Defines each day on chart for finding 'def prevclose' below. The most current day is defined as thisday == 0 and increments by 1 for each additional previous day     
    input lookback = 0;
    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 aggregationPeriod = AggregationPeriod.DAY;
    input length = 1;
    input displace = -1;
    input showOnlyLastPeriod = no;

#Defines each previous day's close matching thisday to lookback and extends it by storing that close in prevclose[1]
    def prevclose = if thisDay == lookback
                    then Highest(close(period=aggregationPeriod)[-displace], length)
                    else prevclose[1];
    plot PrevDayClose;

    if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) and thisday > lookback
    {
        PrevDayClose = Double.NaN;
    }
    else
    {
        PrevDayClose = prevclose;
    }

    PrevDayClose.SetDefaultColor(GetColor(1));
    PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

    PrevDayClose.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);
}

plot p0 = p();
plot p1 = p(1);
plot p2 = p(2);
plot p3 = p(3);
plot p4 = p(4);
plot p5 = p(5);
plot p6 = p(6);

p0.setpaintingStrategy(paintingStrategy.HORIZONTAL);
p1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
p6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
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
558 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