I have written an indicator that I want to be a triple screen that will change the background color to green when true. The screen is as follows:
1. The close is above the EMA 10 and the EMA 10 is above the EMA 65.
2. The Slow Stochastics is greater than 20.
3. The MACD is displaying a buy signal.
Here is the code:
# TripleScreen
# 1. EMA screen
def EMA10 = ExpAverage(close[-0], 10);
def EMA65 = ExpAverage(close[-0], 65);
def A = if close > EMA10 and EMA10 > EMA65 then 1 else 0;
# **************************************************
# 2. Slow Stochastics screen
def SStoch51 = reference StochasticFull(80, 20, 5, 1, high, low, close, 3, AverageType.SIMPLE).FullK;
def B = if SStoch51 > 20 then 1 else 0;
# **************************************************
# 3. MACD screen
#
# NOTE: (Value cross above Avg) > ZeroLine = BUY SIGNAL
# Value Above ZeroLine Bullish and below Bearish
# Value Cyan
# Avg white
# Diff Histogram
# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MACD
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
#plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
#plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
plot UpSignal = if Value > ZeroLine and Diff > ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Value < ZeroLine and Diff < ZeroLine then ZeroLine else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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"));
ZeroLine.SetDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.WHITE);
UpSignal.SetLineWeight(5);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(5);
#AddLabel(yes, if close > open then if close > Average(close, 20) then "Uptrend Green" else "Downtrend Green" else if close > Average(close, 20) then "Uptrend RED" else "Downtrend RED");
AddLabel(yes, if Value > ZeroLine then "OK BULLISH" else "BEARISH", if Value > ZeroLine then Color.LIGHT_GREEN else Color.PINK);
#AddLabel(yes, if Value > Avg then "" else "CAUTIOUS Raise STOP", if value > Avg then Color.GRAY else Color.YELLOW);
AddLabel(yes, "Watch White Arrows", Color.WHITE);
def C = if UpSignal then 1 else 0;
# **************************************************
# 4. BGColor change if all the above are true
DefineGlobalColor("TRUE",Color.GREEN);
DefineGlobalColor("FALSE",Color.RED);
DefineGlobalColor("default",Color.CURRENT);
#AssignBackgroundColor(if A = 1 && B = 1 && C = 1 then GlobalColor("TRUE") else if A = 0 && B = 0 && C = 0 then GlobalColor("FALSE") else GlobalColor("default");
# **************************************************
# End code------------------------------------------
I am having problems with #4. above Assigning Background Color. As an example here is a chart that should have the Background Color changed to Green. Any help with the code is appreciated.
1. The close is above the EMA 10 and the EMA 10 is above the EMA 65.
2. The Slow Stochastics is greater than 20.
3. The MACD is displaying a buy signal.
Here is the code:
# TripleScreen
# 1. EMA screen
def EMA10 = ExpAverage(close[-0], 10);
def EMA65 = ExpAverage(close[-0], 65);
def A = if close > EMA10 and EMA10 > EMA65 then 1 else 0;
# **************************************************
# 2. Slow Stochastics screen
def SStoch51 = reference StochasticFull(80, 20, 5, 1, high, low, close, 3, AverageType.SIMPLE).FullK;
def B = if SStoch51 > 20 then 1 else 0;
# **************************************************
# 3. MACD screen
#
# NOTE: (Value cross above Avg) > ZeroLine = BUY SIGNAL
# Value Above ZeroLine Bullish and below Bearish
# Value Cyan
# Avg white
# Diff Histogram
# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MACD
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
#plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
#plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
plot UpSignal = if Value > ZeroLine and Diff > ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Value < ZeroLine and Diff < ZeroLine then ZeroLine else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
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"));
ZeroLine.SetDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.WHITE);
UpSignal.SetLineWeight(5);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(5);
#AddLabel(yes, if close > open then if close > Average(close, 20) then "Uptrend Green" else "Downtrend Green" else if close > Average(close, 20) then "Uptrend RED" else "Downtrend RED");
AddLabel(yes, if Value > ZeroLine then "OK BULLISH" else "BEARISH", if Value > ZeroLine then Color.LIGHT_GREEN else Color.PINK);
#AddLabel(yes, if Value > Avg then "" else "CAUTIOUS Raise STOP", if value > Avg then Color.GRAY else Color.YELLOW);
AddLabel(yes, "Watch White Arrows", Color.WHITE);
def C = if UpSignal then 1 else 0;
# **************************************************
# 4. BGColor change if all the above are true
DefineGlobalColor("TRUE",Color.GREEN);
DefineGlobalColor("FALSE",Color.RED);
DefineGlobalColor("default",Color.CURRENT);
#AssignBackgroundColor(if A = 1 && B = 1 && C = 1 then GlobalColor("TRUE") else if A = 0 && B = 0 && C = 0 then GlobalColor("FALSE") else GlobalColor("default");
# **************************************************
# End code------------------------------------------
I am having problems with #4. above Assigning Background Color. As an example here is a chart that should have the Background Color changed to Green. Any help with the code is appreciated.
