Hi everyone,
I'm trying to add two labels on a MACD lower study for the plots Value and Avg.
I cant figure out how to get the labels to work with the plots for the value line(Cyan) and avg line(Yellow):
They work on some tickers, on some time frames, but not all. Seemingly from what I've tested it only appears to happen with some negative plots.
This one isn't even close (2Y 1D)
This one seems to work (3Y M):
This one just shows -0 (180D 15M):
I've searched up and down the site, and I'm just stumped!
Preferably, I'm looking for a solution that incorporates 100 thousandths on the label, right now it'll produce a label sometimes up to 10 thousandths.
The full code I'm using is:
I've tried using different lines of code to get some consistency, but have been unsuccessful:
I'm trying to add two labels on a MACD lower study for the plots Value and Avg.
I cant figure out how to get the labels to work with the plots for the value line(Cyan) and avg line(Yellow):
They work on some tickers, on some time frames, but not all. Seemingly from what I've tested it only appears to happen with some negative plots.
This one isn't even close (2Y 1D)
This one seems to work (3Y M):
This one just shows -0 (180D 15M):
I've searched up and down the site, and I'm just stumped!
Preferably, I'm looking for a solution that incorporates 100 thousandths on the label, right now it'll produce a label sometimes up to 10 thousandths.
The full code I'm using is:
Code:
declare lower;
input price = close;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};
input MACDLevel = 0.0;
def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
plot Value;
plot Avg;
switch (AverageType) {
case SMA:
Value = Average(price, fastLength) - Average(price, slowLength);
Avg = Average(Value, MACDLength);
case EMA:
Value = fastEMA - slowEMA;
Avg = ExpAverage(Value, MACDLength);
}
plot Diff = Value - Avg;
plot Level = MACDLevel;
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0
then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down")
else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Level.SetDefaultColor(GetColor(3));
addLabel(yes, " Value = " + Value + " ", if Value > Avg then Color.GREEN else Color.RED);
addLabel(yes, " Avg = " + avg + " ", if Avg > Value then Color.RED else Color.GREEN);
I've tried using different lines of code to get some consistency, but have been unsuccessful:
Code:
addLabel(yes, " Value = " + absValue(Value) + " ", if Value > Avg then Color.GREEN else Color.RED);
addLabel(yes, " Avg = " + avg + " ", if Avg > Value then Color.RED else Color.GREEN);
Last edited by a moderator: