Plot only the high from the last 65 most recent days

Pensar

Well-known member
VIP
Lifetime
@Ecantor Maybe this instead
Ruby:
plot line = highestall(if !isnan(close) and isnan(close[-1]) then highest(high,65) else double.nan);
The fold function isn't my strong point, so I can't help on where the code you posted needs changing. Never could understand how it worked.
 

halcyonguy

Well-known member
VIP
Lifetime
Can you please provide the codes for the lower line?

can you please provide the code for plotting he low from the last 65 most recent days?


i added some code to the end of my study,
. to draw a line at the lowest low,
. that exists within the most recent x bars ( not days)

if you want days, set chart to days.


Code:
# test_highestbn_05e

# https://usethinkscript.com/threads/plot-only-the-high-from-the-last-65-most-recent-days.7483/
# find the highest high, in the most rect x bars

def na = Double.NaN;
def bn = BarNumber();
def lastbar = HighestAll(if !IsNaN(close) then bn else na);

input look_back_bars = 65;
# is the current bar within the lookback quantity of bars? true/false
def rng = (lastbar - bn <= look_back_bars);

def hi = fold i = 0 to look_back_bars 
with p
do if !rng then 0 else if GetValue(high, (bn - (lastbar - i))) > p then GetValue(high, (bn - (lastbar - i))) else p;

plot hix = HighestAll(hi);
hix.SetDefaultColor(Color.yellow);
hix.SetStyle(Curve.MEDIUM_DASH);

# test code -------------------------
# identify the first bar in the lookback group
def firstbar = (!IsNaN(close[-look_back_bars]) and IsNaN(close[-(look_back_bars + 1)]));
plot f = firstbar;
f.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
f.SetDefaultColor(Color.yellow);
f.setlineweight(4);

AddVerticalLine(firstbar, "xx" , Color.CYAN );

input show_barnumber_bubbles = no;
addchartbubble(show_barnumber_bubbles, low * 0.995, bn + "\n" + "x", color.cyan, no);

#addchartbubble(1, high * 1.01, hi, color.cyan, yes);
#

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

# lowest from prev x bars

def lolo = lowestall(if rng then low else na);
plot lox = lolo;
lox.SetDefaultColor(Color.magenta);
lox.SetStyle(Curve.MEDIUM_DASH);
#
 

majidg

Member
i added some code to the end of my study,
. to draw a line at the lowest low,
. that exists within the most recent x bars ( not days)

if you want days, set chart to days.


Code:
# test_highestbn_05e

# https://usethinkscript.com/threads/plot-only-the-high-from-the-last-65-most-recent-days.7483/
# find the highest high, in the most rect x bars

def na = Double.NaN;
def bn = BarNumber();
def lastbar = HighestAll(if !IsNaN(close) then bn else na);

input look_back_bars = 65;
# is the current bar within the lookback quantity of bars? true/false
def rng = (lastbar - bn <= look_back_bars);

def hi = fold i = 0 to look_back_bars
with p
do if !rng then 0 else if GetValue(high, (bn - (lastbar - i))) > p then GetValue(high, (bn - (lastbar - i))) else p;

plot hix = HighestAll(hi);
hix.SetDefaultColor(Color.yellow);
hix.SetStyle(Curve.MEDIUM_DASH);

# test code -------------------------
# identify the first bar in the lookback group
def firstbar = (!IsNaN(close[-look_back_bars]) and IsNaN(close[-(look_back_bars + 1)]));
plot f = firstbar;
f.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
f.SetDefaultColor(Color.yellow);
f.setlineweight(4);

AddVerticalLine(firstbar, "xx" , Color.CYAN );

input show_barnumber_bubbles = no;
addchartbubble(show_barnumber_bubbles, low * 0.995, bn + "\n" + "x", color.cyan, no);

#addchartbubble(1, high * 1.01, hi, color.cyan, yes);
#

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

# lowest from prev x bars

def lolo = lowestall(if rng then low else na);
plot lox = lolo;
lox.SetDefaultColor(Color.magenta);
lox.SetStyle(Curve.MEDIUM_DASH);
#
Hi halcyonguy, can you kindly show how to set this to day on the char. do I choose 3M,Day?
 

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.
Top