Plot highest and lowest from previous 5 sessions


Category:
0
0

I typically trade on a 15 minute chart.
I would like to have two horizontal lines on my intraday chart each day:

  • One for the highest daily high of the previous 5 days (not including current day)
  • One for the lowest daily low of the previous 5 days (not including current day)

I thought I was on the right track, and I know I can pull from higher aggregations.

But something seems off and I feel so silly for not being able to figure out the answer. Any help would be GREATLY appreciated.

 

plot FiveDayHigh = highest(high(“period” = AggregationPeriod.DAY)[5]);

plot FiveDayLow = lowest(low(“period” = AggregationPeriod.DAY)[5]);

Marked as spam
Posted by (Questions: 4, Answers: 6)
Asked on January 28, 2024 5:54 pm
80 views
0
Private answer

The code you provided ends up computing the highest high from 5 sessions ago and the lowest low from 5 sessions ago.

A bit more detail to help you understand where you missed the mark:

You correctly used the higher time frame but you failed to include the second parameter in your use of the Highest() and Lowest() methods. Those two methods require the data point as the first parameter and the number of bars ago as the second parameter. Then you placed the index value of 5 at the end of those methods. Which merely shifts those methods to read data from 5 periods ago.

Here is what it looks like after correcting those issues:

input higherTimeFrame = AggregationPeriod.DAY;
input numberOfSessions = 5;
def periodHighest = Highest(high(period = higherTimeFrame)[1], numberOfSessions);
def periodLowest = Lowest(low(period = higherTimeFrame)[1], numberOfSessions);
plot targetHigh = periodHighest;
targetHigh.SetDefaultColor(Color.DARK_GREEN);
plot targetLow = periodLowest;
targetLow.SetDefaultColor(Color.DARK_RED);

I have included user inputs to adjust the higher time frame and number of previous session. Screenshot below shows how this looks on the chart.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 28, 2024 5:59 pm