Horizontal Line At Low "N" Days Ago

chris88888

New member
Hello,

I would sincerely appreciate some help with what I think is a simple, yet frustrating, request.

I would like a horizontal line drawn only across the right side of the chart scripted using the low value of price from 15 days prior to today. In other words, the low of 15 days ago, not the lowest low during the past 15 bars.

I would ideally like to modify the timeframe to allow for 15 days, 60 days and 756 days. I would assume that any code could be modified to script a line using the high from 15 days prior to today also having the ability to modify the timeframe.

Essentially, I would like to have the script show a line like in the following but only to the right, not extended across the left of the chart.

6_16_2021_7_04_23_AM.png


Appreciate any help and feedback.

Chris
 
Last edited:
Solution
Hello,

I would sincerely appreciate some help with what I think is a simple, yet frustrating, request.

I would like a horizontal line drawn only across the right side of the chart scripted using the low value of price from 15 days prior to today. In other words, the low of 15 days ago, not the lowest low during the past 15 bars.

I would ideally like to modify the timeframe to allow for 15 days, 60 days and 756 days. I would assume that any code could be modified to script a line using the high from 15 days prior to today also having the ability to modify the timeframe.

Essentially, I would like to have the script show a line like in the following but only to the right, not extended across the left of the chart.

try this...
Hello,

I would sincerely appreciate some help with what I think is a simple, yet frustrating, request.

I would like a horizontal line drawn only across the right side of the chart scripted using the low value of price from 15 days prior to today. In other words, the low of 15 days ago, not the lowest low during the past 15 bars.

I would ideally like to modify the timeframe to allow for 15 days, 60 days and 756 days. I would assume that any code could be modified to script a line using the high from 15 days prior to today also having the ability to modify the timeframe.

Essentially, I would like to have the script show a line like in the following but only to the right, not extended across the left of the chart.

try this out

Code:
# last_x_days_00

# https://usethinkscript.com/threads/horizontal-line-at-low-n-days-ago.13344/
# Horizontal Line At Low "N" Days Ago

def bn = BarNumber();
def na = double.nan;

#def istoday = if GetLastDay() == GetDay() then 1 else 0;
def newday = if GetDay() != GetDay()[1] then 1 else 0;
def daycnt = if bn == 1 then 1 else if (!IsNaN(close) and newday) then daycnt[1] + 1 else daycnt[1];
def maxdays = HighestAll(daycnt);
def revdaycnt = maxdays - daycnt + 1;

input days_back = 15;
def daystoomany = if days_back < 1 or days_back > maxdays then 1 else 0;
AddLabel(daystoomany, " ONLY " + maxdays + " DAYS ON CHART. enter a different number for days back", Color.CYAN);
def x = days_back == revdaycnt;

def agg1 = AggregationPeriod.day;
#def agg1lowx = low(period = agg);

def agg1low = if bn == 1 then na
  else if x then low(period = agg1)
  else agg1low[1];

plot z = agg1low;
z.SetDefaultColor(Color.cyan);
z.setlineweight(1);
z.hidebubble();

#----------------------------------

AddChartBubble(0, low,
newday + " new\n" +
daycnt + " cnt\n" +
revdaycnt + " rev\n" +
maxdays + " max\n"
, Color.YELLOW, no);
#

days back, set to, 15
TagrP9W.jpg
 
Last edited:
Solution
Hello,

I would sincerely appreciate some help with what I think is a simple, yet frustrating, request.

I would like a horizontal line drawn only across the right side of the chart scripted using the low value of price from 15 days prior to today. In other words, the low of 15 days ago, not the lowest low during the past 15 bars.

I would ideally like to modify the timeframe to allow for 15 days, 60 days and 756 days. I would assume that any code could be modified to script a line using the high from 15 days prior to today also having the ability to modify the timeframe.

Essentially, I would like to have the script show a line like in the following but only to the right, not extended across the left of the chart.

6_16_2021_7_04_23_AM.png


Appreciate any help and feedback.

Chris
This will display the high/low on the lastday of the chart for the n days input.

Screenshot-2022-11-12-221224.png
Ruby:
input n = 60;
plot h = if GetDay() < GetLastDay()
         then Double.NaN
         else high(period = AggregationPeriod.DAY)[n];
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot l = if GetDay() < GetLastDay()
         then Double.NaN
         else low(period = AggregationPeriod.DAY)[n];
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input showbubbles = yes;
AddChartBubble(showbubbles and BarNumber() == HighestAll(BarNumber() - 1), h, "H" + n, h.TakeValueColor());
AddChartBubble(showbubbles and BarNumber() == HighestAll(BarNumber() - 1), l, "L" + n, l.TakeValueColor());
 
try this out

Code:
# last_x_days_00

# https://usethinkscript.com/threads/horizontal-line-at-low-n-days-ago.13344/
# Horizontal Line At Low "N" Days Ago

def bn = BarNumber();
def na = double.nan;

#def istoday = if GetLastDay() == GetDay() then 1 else 0;
def newday = if GetDay() != GetDay()[1] then 1 else 0;
def daycnt = if bn == 1 then 1 else if (!IsNaN(close) and newday) then daycnt[1] + 1 else daycnt[1];
def maxdays = HighestAll(daycnt);
def revdaycnt = maxdays - daycnt + 1;

input days_back = 15;
def daystoomany = if days_back < 1 or days_back > maxdays then 1 else 0;
AddLabel(daystoomany, " ONLY " + maxdays + " DAYS ON CHART. enter a different number for days back", Color.CYAN);
def x = days_back == revdaycnt;

def agg1 = AggregationPeriod.day;
#def agg1lowx = low(period = agg);

def agg1low = if bn == 1 then na
  else if x then low(period = agg1)
  else agg1low[1];

plot z = agg1low;
z.SetDefaultColor(Color.cyan);
z.setlineweight(1);
z.hidebubble();

#----------------------------------

AddChartBubble(0, low,
newday + " new\n" +
daycnt + " cnt\n" +
revdaycnt + " rev\n" +
maxdays + " max\n"
, Color.YELLOW, no);
#
Thank you so much! I can't tell you how long I fumbled with code and searching for this outcome!

This works exactly as I need.
Many thanks, Sleepy! Appreciate it.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
543 Online
Create Post

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