Hi All,
As the subject suggests, I'm tricking the daily watchlist column to identify last month's high. When I manually enter in the BeginDate and EndDate, the code works fine but I'm trying to automatically set the BeginDate and EndDate based on the current month. When I use a formula to calculate the dates, the result is 0. The code isn't recognizing the BeginDate and EndDate in the formula output for some reason. Any ideas why this is the case?
As the subject suggests, I'm tricking the daily watchlist column to identify last month's high. When I manually enter in the BeginDate and EndDate, the code works fine but I'm trying to automatically set the BeginDate and EndDate based on the current month. When I use a formula to calculate the dates, the result is 0. The code isn't recognizing the BeginDate and EndDate in the formula output for some reason. Any ideas why this is the case?
Code:
def H = high;
def L = low;
def C = close;
def O = open;
def bn = barnumber();
def na = double.nan;
def month = Getmonth();
def BeginDate = if
month == 1 then 20211201 else if
month == 2 then 20220101 else if
month == 3 then 20220201 else if
month == 4 then 20220301 else if
month == 5 then 20220401 else if
month == 6 then 20220501 else if
month == 7 then 20220601 else if
month == 8 then 20220701 else if
month == 9 then 20220801 else if
month == 10 then 20220901 else if
month == 11 then 20221001 else if
month == 12 then 20221101 else na;
def EndDate = if
month == 1 then 20211231 else if
month == 2 then 20220131 else if
month == 3 then 20220228 else if
month == 4 then 20220331 else if
month == 5 then 20220430 else if
month == 6 then 20220531 else if
month == 7 then 20220630 else if
month == 8 then 20220731 else if
month == 9 then 20220831 else if
month == 10 then 20220930 else if
month == 11 then 20221031 else if
month == 12 then 20221130 else na;
def ispriormonth = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;
def hi = if bn == 0 or !ispriormonth then 0
else if ispriormonth and high > hi[1] then high else hi[1];
def hihi = highestall(hi);
def z = if ispriormonth then hihi else z[1];
plot zz= z;