Hello! Earlier I got help from community member Pensar to add a DailyMid price indicator to the TOS DailyHighLow study. Now I want to employ addLabel to display the current close price distance by % to the DailyMid (usually on a 5 min chart). I cannot (my inexperience) figure out how to resolve the issue the code highlights at 9:33. I thought DailyMid was already defined. Any help I could get to fix this would be appreciated. Here's the code:
# Modified DailyHighLow study that includes DailyMid indicator line and displays close price % distance from DailyMid indicator
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input price = close;
def DistanceBetween = (Sqrt(Sqr(DailyMid / price))) / 100;
plot DailyHigh;
plot DailyLow;
plot DailyMid;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyMid = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
DailyMid = (DailyHigh + DailyLow)/2;
}
DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyMid.SetDefaultColor(GetColor(4));
DailyMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
addLabel(yes, "% to MidPrice = " + asPercent(round(DistanceBetween,2)));
# Modified DailyHighLow study that includes DailyMid indicator line and displays close price % distance from DailyMid indicator
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input price = close;
def DistanceBetween = (Sqrt(Sqr(DailyMid / price))) / 100;
plot DailyHigh;
plot DailyLow;
plot DailyMid;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyMid = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
DailyMid = (DailyHigh + DailyLow)/2;
}
DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyMid.SetDefaultColor(GetColor(4));
DailyMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
addLabel(yes, "% to MidPrice = " + asPercent(round(DistanceBetween,2)));