Percent Change after first X minutes


Category:
0
0

Hey Pete,

I searched your forums and found this very straightforward code for determining the percent change from the previous day’s close.

plot percentChange = 100 * (open / close[1] – 1);

I am wondering if it can be modified to calculate the close of the first 10-minute (or a preset aggregation) candle vs. previous day’s close?

Thank you!

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 23, 2021 2:41 pm
77 views
0
Private answer

So do I understand correctly that you want to compute the percent change between the previous day's close and first candle for the current trading session?

If that is correct, and you only plan to use this for a chart study, then the solution looks like this:

def previousDayClose = close(period = AggregationPeriod.DAY);
def newDay = GetDay() <> GetDay()[1];
rec firstBarClose = if newDay then close else firstBarClose[1];
plot data = 100 * (firstBarClose / previousDayClose - 1);

Requirements:

  1. Only works for chart studies
  2. Must turn extended hours session OFF on the chart
  3. Must use an intraday time frame
  4. Does not work on Tick or Range bar charts
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on June 23, 2021 5:24 pm
0
This is EXACTLY what I was going for. Added a label and it's perfect. Thank you!!!
( at June 23, 2021 5:54 pm)