how would I go about creating an indicator that places a horizontal line at the highest (and lowest) closing prices within a specified date range and chart aggregation? Currently trying to mark the highest monthly closing price within the pre-covid time frame (11/01/2019 - 02/01/2020) as well as at the post-covid crash time frame (03/01/2020 - 05/01/2020).
I've been trying to take chunks from the code presented in another thread called "Calculate Price % from pre-Covid crash" which pulls the price from a specified day. with me being completely new to this, I haven't gotten far haha.
thanks in advance for any guidance
here is a basic version, to draw high low lines between 2 dates
can pick the price type
Ruby:
# date_rng_hi_lo_01
def na = double.nan;
input start_date = 20220101;
input stop_date = 20220301;
input high_price = close;
input low_price = close;
# read the date on each bar
def dat = GetYYYYMMDD();
# are bars within the date range ?
def inrng = if dat >= start_date and dat <= stop_date then 1 else 0;
def big = 999999;
def rnghi = highestall(if inrng then high_price else 0);
def rnglo = lowestall(if inrng then low_price else big);
plot hiz = if inrng and rnghi > 0 then rnghi else na;
plot loz = if inrng and rnglo > 0 then rnglo else na;
hiz.setdefaultcolor(color.light_gray);
loz.setdefaultcolor(color.light_gray);
#