For the rest of our viewers, the author of this post included the code in the comment section immediately below their question. In the future, it is always best to provide the code along with the question. If the code is less than a couple dozen lines, it should be included in the body of the question. If the code exceeds the character limit of the question field than it should be included as an attached plain text file.
Here is the code provided by the author of the post:
AddLabel(yes, ” 1h ”, if close(period=AggregationPeriod.Hour) > Open(period=AggregationPeriod.Hour) then color.green else color.red);
AddLabel(yes, ” 30m ”, if close(period=AggregationPeriod.Thirty_Min) > Open(period=AggregationPeriod.Thirty_Min) then color.green else color.red);
AddLabel(yes, ” 15m ”, if close(period=AggregationPeriod.Fifteen_Min) > Open(period=AggregationPeriod.Fifteen_Min) then color.green else color.red);
I tested this and analysized it carefully. I cannot find any reason why it is producing this error. Each of the three labels work when applied separately but not when two or more are included together.
My own style of writing code is very different. I find is much simpler to split complicated statements into very basic individual pieces. I also like to include user inputs so everyone else that comes across my solutions will be able to adjust them to their liking without having to change the code.
So I wrote this solution in my own way from scratch. And it works.
input timeFrameOne = AggregationPeriod.FIFTEEN_MIN;
input timeFrameTwo = AggregationPeriod.THIRTY_MIN;
input timeFrameThree = AggregationPeriod.HOUR;
def priceCloseOne = close(period = timeFrameOne);
def priceOpenOne = open(period = timeFrameOne);
def priceCloseTwo = close(period = timeFrameTwo);
def priceOpenTwo = open(period = timeFrameTwo);
def priceCloseThree = close(period = timeFrameThree);
def priceOpenThree = open(period = timeFrameThree);
AddLabel(yes, "TF One", if priceCloseOne > priceOpenOne then Color.GREEN else Color.RED);
AddLabel(yes, "TF Two", if priceCloseTwo > priceOpenTwo then Color.GREEN else Color.RED);
AddLabel(yes, "TF Three", if priceCloseThree > priceOpenThree then Color.GREEN else Color.RED);
Believe it or not, this style of writing code is much easier to maintain and easier to read. You can replicate elements in this style of writing code using simple copy/paste and find/replace. Troubleshooting the code is also very simple because each key metric has been listed separately. Sometimes, having more lines of code is easier and simpler. Save the complexity for where it absolutely necessary.