Trend change indicator. I need help adjusting the plot.

Haamu

New member
I have built an indicator when a candle changes trend. The plots work fairly well.
I am looking to have the lines extend all the way to the end of the chart and then have the lines stop or go dashed when a candle closes through (not on wicks) preferably a toggle if possible. Thanks in advance!
Screenshot 2025-01-05 223956.png




# Aggregation period for weekly levels
input aggPeriod = AggregationPeriod.WEEK;

# Define high, low, and close for the weekly timeframe
def weekOpen = open(period = aggPeriod);
def weekHigh = high(period = aggPeriod);
def weekLow = low(period = aggPeriod);
def weekClose = close(period = aggPeriod);

# Trend change conditions on the weekly timeframe
def weekDownToUp = weekClose > weekOpen and weekClose[1] < weekOpen[1];
def weekUpToDown = weekClose < weekOpen and weekClose[1] > weekOpen[1];

# Persistent Down-to-Up levels (extend until invalidated on the weekly timeframe)
rec weekDownToUpLevel1 =
if weekDownToUp then weekOpen
else if weekClose[1] <= weekDownToUpLevel1[1] then weekDownToUpLevel1[1]
else weekDownToUpLevel1[1];

rec weekDownToUpLevel2 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel1 then weekOpen
else if weekClose[1] <= weekDownToUpLevel2[1] then weekDownToUpLevel2[1]
else weekDownToUpLevel2[1];

rec weekDownToUpLevel3 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel2 then weekOpen
else if weekClose[1] <= weekDownToUpLevel3[1] then weekDownToUpLevel3[1]
else weekDownToUpLevel3[1];

# Persistent Up-to-Down levels (extend until invalidated on the weekly timeframe)
rec weekUpToDownLevel1 =
if weekUpToDown then weekOpen
else if weekClose[1] >= weekUpToDownLevel1[1] then weekUpToDownLevel1[1]
else weekUpToDownLevel1[1];

rec weekUpToDownLevel2 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel1 then weekOpen
else if weekClose[1] >= weekUpToDownLevel2[1] then weekUpToDownLevel2[1]
else weekUpToDownLevel2[1];

rec weekUpToDownLevel3 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel2 then weekOpen
else if weekClose[1] >= weekUpToDownLevel3[1] then weekUpToDownLevel3[1]
else weekUpToDownLevel3[1];

# Plot Down-to-Up levels
plot weekDownToUpPlot1 = weekDownToUpLevel1;
weekDownToUpPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot1.SetDefaultColor(Color.GREEN);

plot weekDownToUpPlot2 = weekDownToUpLevel2;
weekDownToUpPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot2.SetDefaultColor(Color.LIGHT_GREEN);

plot weekDownToUpPlot3 = weekDownToUpLevel3;
weekDownToUpPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot3.SetDefaultColor(Color.DARK_GREEN);

# Plot Up-to-Down levels
plot weekUpToDownPlot1 = weekUpToDownLevel1;
weekUpToDownPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot1.SetDefaultColor(Color.RED);

plot weekUpToDownPlot2 = weekUpToDownLevel2;
weekUpToDownPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot2.SetDefaultColor(Color.PINK);

plot weekUpToDownPlot3 = weekUpToDownLevel3;
weekUpToDownPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot3.SetDefaultColor(Color.DARK_RED);
 

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