horizontal line at the PREVIOUS WEEKLY candle

CTT

New member
Hi! I'm new to ThinkScript. I'm hoping someone can help me to write a simple script to automate the task of drawing a simple white horizontal line at the center of the PREVIOUS WEEKLY candle (between the high and low for the week), that extends the entire length of the chart. I would also like to label this line "Weekly Line In The Sand" with the price bubble on the right axis.

If someone can help me with this I would really appreciate it. I have spent all day looking for a simple indicator or script to do this in Think or Swim without success.
 
Solution
Hi! I'm new to ThinkScript. I'm hoping someone can help me to write a simple script to automate the task of drawing a simple white horizontal line at the center of the PREVIOUS WEEKLY candle (between the high and low for the week), that extends the entire length of the chart. I would also like to label this line "Weekly Line In The Sand" with the price bubble on the right axis.

If someone can help me with this I would really appreciate it. I have spent all day looking for a simple indicator or script to do this in Think or Swim without success.


See if this helps

Capture.jpg
Ruby:
def weekly_HL2       = if isnan(close(period=aggregationPeriod.WEEK))
                       then weekly_HL2[1]
                       else...
Hi! I'm new to ThinkScript. I'm hoping someone can help me to write a simple script to automate the task of drawing a simple white horizontal line at the center of the PREVIOUS WEEKLY candle (between the high and low for the week), that extends the entire length of the chart. I would also like to label this line "Weekly Line In The Sand" with the price bubble on the right axis.

If someone can help me with this I would really appreciate it. I have spent all day looking for a simple indicator or script to do this in Think or Swim without success.


See if this helps

Capture.jpg
Ruby:
def weekly_HL2       = if isnan(close(period=aggregationPeriod.WEEK))
                       then weekly_HL2[1]
                       else HL2(period=aggregationPeriod.WEEK);

plot prev_weekly_HL2 = weekly_HL2[1];
prev_weekly_HL2.setpaintingStrategy(paintingStrategy.HORIZONTAL);

input showbubble  = yes;
input bubblemover = 7;
def bm  = bubblemover;
def bm1 = bm + 1;
addchartBubble(showbubble and isnan(close[bm]) and !isnan(close[bm1]),
               prev_weekly_HL2[bm], "Weekly Line in the Sand",
               prev_weekly_HL2.takevalueColor());
 
Solution

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

Code:
input higherTimeFrame = AggregationPeriod.WEEK;

plot PREvLOW =  low(period = higherTimeFrame )[1];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvHIGH =  high(period = higherTimeFrame )[1];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Code:
input higherTimeFrame = AggregationPeriod.WEEK;

plot PREvLOW =  low(period = higherTimeFrame )[1];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvHIGH =  high(period = higherTimeFrame )[1];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot mid = (prevHIGH + prevLOW)/2;
mid.SetLineWeight(3);
mid.SetDefaultColor(Color.white);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DEF bubblemover = 7;
def bm  = bubblemover;
def bm1 = bm + 1;

addchartBubble(YES and isnan(close[bm]) and !isnan(close[bm1]),
               mid[bm], "Weekly Line in the Sand",
              Color.WHITE, yes);

addchartBubble(YES and isnan(close[bm]) and !isnan(close[bm1]),
               PREvLOW[bm], "PREVious LOW $",
              Color.UPTICK, NO);

addchartBubble(YES and isnan(close[bm]) and !isnan(close[bm1]),
               PREvHIGH[bm], "PREVious HIGH $",
              Color.DOWNTICK, yes);
 
Code:
input higherTimeFrame = AggregationPeriod.WEEK;

plot PREvLOW =  low(period = higherTimeFrame )[1];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvHIGH =  high(period = higherTimeFrame )[1];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Thank you so much!
See if this helps
SleepyZ, that is exactly what I have been looking for! Thank you! I am also looking to draw another Line In The Sand at the previous day's close and label that one "DAILY Line In The Sand". Can this script be easily modified to do this? Example, by replacing the word WEEK with DAY? Please advise.
 
As an alternative I found this script in the forum that prints out the horizontal line.......but it lacks the bubble label "DAILY Line In The Sand":



input daysback = 1;
plot close_priordays = HighestAll(if IsNaN(close[-1]) and !IsNaN(close)
then close(period = AggregationPeriod.DAY)[daysback]
else Double.NaN);

Please advise. Your assistance is much appreciated!
 
Thank you so much!

SleepyZ, that is exactly what I have been looking for! Thank you! I am also looking to draw another Line In The Sand at the previous day's close and label that one "DAILY Line In The Sand". Can this script be easily modified to do this? Example, by replacing the word WEEK with DAY? Please advise.
Yes
Code:
#https://youtu.be/qSn1cyJZztE
input higherTimeFrame = AggregationPeriod.WEEK;
input Lookback = 1;
plot PREvLOW =  low(period = higherTimeFrame )[Lookback ];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvHIGH =  high(period = higherTimeFrame )[Lookback ];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvCLOSE =  CLOSE(period = higherTimeFrame )[Lookback ];
PREvCLOSE.SetLineWeight(3);
PREvCLOSE.SetDefaultColor(Color.PLUM);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot mid = (prevHIGH + prevLOW)/2;
mid.SetLineWeight(3);
mid.SetDefaultColor(Color.white);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(mid), "MID Line in the Sand: " + Round(mid), Color.WHITE);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvHIGH), "PREVious HIGH $: " + Round(PREvHIGH), Color.RED);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvLOW), "PREVious LOW $: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvCLOSE), "CLOSE Line In The Sand $: " + Round(PREvCLOSE), Color.PLUM);
 
Last edited:
Yes
Code:
input higherTimeFrame = AggregationPeriod.WEEK;

plot PREvLOW =  low(period = higherTimeFrame )[1];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvHIGH =  high(period = higherTimeFrame )[1];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot PREvCLOSE =  CLOSE(period = higherTimeFrame )[1];
PREvCLOSE.SetLineWeight(3);
PREvCLOSE.SetDefaultColor(Color.PLUM);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot mid = (prevHIGH + prevLOW)/2;
mid.SetLineWeight(3);
mid.SetDefaultColor(Color.white);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(mid), "MID Line in the Sand: " + Round(mid), Color.WHITE);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvHIGH), "PREVious HIGH $: " + Round(PREvHIGH), Color.RED);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvLOW), "PREVious LOW $: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvCLOSE), "CLOSE Line In The Sand $: " + Round(PREvCLOSE), Color.PLUM);

Yes, as follows:

Code:
input higherTimeFrame = AggregationPeriod.DAY;
 
can you make it show the label on the chart? if i dont want the line on the chart? Thank you

This has options to show or not, lines, bubbles and/or labels. The default is just to show labels.

Code:
input higherTimeFrame = AggregationPeriod.WEEK;

input lines = no;
plot PREvLOW =  low(period = higherTimeFrame )[1];
PREvLOW.SetLineWeight(3);
PREvLOW.SetDefaultColor(Color.UPTICK);
PREvLOW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PREvLOW.sethiding(!lines);
plot PREvHIGH =  high(period = higherTimeFrame )[1];
PREvHIGH.SetLineWeight(3);
PREvHIGH.SetDefaultColor(Color.DOWNTICK);
PREvHIGH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PREvHIGH.sethiding(!lines);
plot PREvCLOSE =  CLOSE(period = higherTimeFrame )[1];
PREvCLOSE.SetLineWeight(3);
PREvCLOSE.SetDefaultColor(Color.PLUM);
PREvCLOSE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PREvCLOSE.sethiding(!lines);
plot mid = (prevHIGH + prevLOW)/2;
mid.SetLineWeight(3);
mid.SetDefaultColor(Color.white);
mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
mid.sethiding(!lines);

input bubbles = no;
AddChartBubble(bubbles and BarNumber() == HighestAll(BarNumber())  and YES, Round(mid), "MID Line in the Sand: " + Round(mid), Color.WHITE);

AddChartBubble(bubbles and BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvHIGH), "PREVious HIGH $: " + Round(PREvHIGH), Color.RED);

AddChartBubble(bubbles and BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvLOW), "PREVious LOW $: " + Round(PREvLOW), Color.GREEN);

AddChartBubble(bubbles and BarNumber() == HighestAll(BarNumber())  and YES, Round(PREvCLOSE), "CLOSE Line In The Sand $: " + Round(PREvCLOSE), Color.PLUM);

input labels = yes;
Addlabel(labels,  "MID Line in the Sand: " + Round(mid), Color.WHITE);

Addlabel(labels, "PREVious HIGH $: " + Round(PREvHIGH), Color.RED);

Addlabel(labels, "PREVious LOW $: " + Round(PREvLOW), Color.GREEN);

Addlabel(labels, "CLOSE Line In The Sand $: " + Round(PREvCLOSE), Color.PLUM);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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