Script that draws line from previous closed 5-minute's high and low?

longbear

New member
Hello everyone! I was hoping if someone could help me with this script. I am looking for a script that draws a horizontal line from the high and low point (one line for each) of the last closed 5-min candle. For context, I will be using this indicator on the 1-min chart.

Here is what I have so far. While it works, there are some some things about it I would like to change but dont know how.
-First thing if that this script also draws lines for the current working 5-minute candle's high and low and I would rather not have that on my chart. This results in diagonal lines that connect the previous candle's lines to the current candle's.
-Second thing I would like to change is this: each of the two lines should (if possible) originate from the candle where the high or low was formed.

Here is my current code:
Code:
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input howManyCandlesBack = 1;
input whichCandle = 1;
input showOnlyLastPeriod = yes;
plot PrevDayHigh;
plot PrevDayLow;

if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1])
{
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
}
else
{
    PrevDayHigh = Highest(high(period = aggregationPeriod)[whichCandle], howManyCandlesBack);
    PrevDayLow = Highest(low(period = aggregationPeriod)[whichCandle], howManyCandlesBack);
}



PrevDayHigh.SetDefaultColor( Color.LIGHT_GREEN);
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevDayLow.SetDefaultColor(Color.LIGHT_RED);
PrevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

And here is the current output: https://postimg.cc/jDDHHHyr

Thank you for any advice!!
 
Solution
Hello everyone! I was hoping if someone could help me with this script. I am looking for a script that draws a horizontal line from the high and low point (one line for each) of the last closed 5-min candle. For context, I will be using this indicator on the 1-min chart.

Here is what I have so far. While it works, there are some some things about it I would like to change but dont know how.
-First thing if that this script also draws lines for the current working 5-minute candle's high and low and I would rather not have that on my chart. This results in diagonal lines that connect the previous candle's lines to the current candle's.
-Second thing I would like to change is this: each of the two lines should (if possible) originate...
Hello everyone! I was hoping if someone could help me with this script. I am looking for a script that draws a horizontal line from the high and low point (one line for each) of the last closed 5-min candle. For context, I will be using this indicator on the 1-min chart.

Here is what I have so far. While it works, there are some some things about it I would like to change but dont know how.
-First thing if that this script also draws lines for the current working 5-minute candle's high and low and I would rather not have that on my chart. This results in diagonal lines that connect the previous candle's lines to the current candle's.
-Second thing I would like to change is this: each of the two lines should (if possible) originate from the candle where the high or low was formed.

Here is my current code:
Code:
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input howManyCandlesBack = 1;
input whichCandle = 1;
input showOnlyLastPeriod = yes;
plot PrevDayHigh;
plot PrevDayLow;

if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1])
{
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
}
else
{
    PrevDayHigh = Highest(high(period = aggregationPeriod)[whichCandle], howManyCandlesBack);
    PrevDayLow = Highest(low(period = aggregationPeriod)[whichCandle], howManyCandlesBack);
}



PrevDayHigh.SetDefaultColor( Color.LIGHT_GREEN);
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevDayLow.SetDefaultColor(Color.LIGHT_RED);
PrevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

And here is the current output: https://postimg.cc/jDDHHHyr

Thank you for any advice!!

This is set at input back =1 to project on a 1min chart using the 5min agg candle to project the prior candle's high/low onto the developing current 5min candle. Vertical lines are used to show the candle breaks.

Screenshot-2022-11-10-070629.png
Ruby:
#Example_xbars_HL_PriorCandle_Projected_on_CurrentCandle

input back   = 1;
input extend = no;
def range    = if close(period=aggregationPeriod.FIVE_MIN) then range[1] + 1 else range[1];


def bn  = BarNumber();
def ymd = range;
def ok  = !IsNaN(close);
def capture  = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

def hh      = CompoundValue(1,
              if thisDay[1] == back + 1 and thisDay == back
              then high
              else if  high > hh[1]
              then high
              else hh[1] , high);
def hhigh   = if thisDay == back and high == hh
              then bn
              else Double.NaN;
def hhnan   = if IsNaN(close)
              then hhnan[1]
              else if thisday==back
              then hh
              else hhnan[1];
plot hhplot = if bn<=highestall(hhigh) then double.nan else hhnan[1];
hhplot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def ll      = CompoundValue(1,
              if thisDay[1] == back + 1 and thisDay == back
              then low
              else if low < ll[1]
              then low
              else ll[1] , low);
def llow    = if thisDay == back and low == ll
              then bn
              else Double.NaN;
def llnan   = if IsNaN(close)
              then llnan[1]
              else if thisday == back
              then ll
              else llnan[1];
plot llplot = if bn<=highestall(llow) then double.nan else llnan[1];
llplot.setpaintingStrategy(paintingStrategy.HORIZONTAL);

##############

# Vertical Lines @Start Time and then Interval of Minutes
input begin   = 0930;
input minutes = 5;
def chartAgg  = GetAggregationPeriod();
def barSeq    = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else barSeq[1] + 1;
def BarsPerHour = 60 / (chartAgg / 1000 / 60);
def bar         = barSeq;
def barCount    = CompoundValue(1, if bar % BarsPerHour == 0
                                    then (bar / BarsPerHour) - 1
                                    else Double.NaN, 1);
input vertical_plot_limiter = 2;
def lastbar = if !isnan(close) and isnan(close[-1]) then barnumber() else double.nan;
AddVerticalLine(thisday<=back and (bar) % (minutes / (GetAggregationPeriod() / 60000)) == 0, color = Color.BLUE, stroke = Curve.FIRM);
#

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