You should not even be able to apply that code to a watchlist. Secondary aggregation periods are not permitted in custom watchlist columns. There are a lot of problems with that code. None of it should work.
If you are here to learn something I will take the time to give you the analysis of your code so you can see where you went wrong.
input builtInPeriod = aggregationPeriod.DAY;
- Secondary aggregation periods are not supported
Def high = close(period = aggregationPeriod.MONTH)[periodsBack];
- You created a variable name that is already used as a reserved word. You should not ever use the word "high" as a variable name.
def CrossAboveMoHigh = close crosses above high(period = builtInPeriod)[periodsBack]within 1 bar;
- Here you are checking if the close of the current time frame is crossing above the previous high of the Daily time frame "builtInPeriod". Nothing in this code even attempts to find the monthly high, because....
- .... secondary aggregation periods are not supported
Now, how do we actually do this. Well we cannot use secondary aggregation periods. So we need a statement that checks for a new month and begins tracking the highest high of each month. This requires recursion, which is an advanced coding technique. At the beginning of each new month, we need to grab the previous bar's value of that highest high from the previous month and carry it through until the next month begins. Confused? Wait until you try to read the code for this solution.
def newMonth = GetMonth() <> GetMonth()[1];
rec trackMonthlyHigh = if newMonth then high else if high > trackMonthlyHigh[1] then high else trackMonthlyHigh[1];
rec previousMonthlyHigh = if newMonth then trackMonthlyHigh[1] else previousMonthlyHigh[1];
plot data = close > previousMonthlyHigh;
This code gets applied to a custom watchlist column that is set to the daily time frame.