Help with AssignBackgroundColor for triple screening indicator

jimw

New member
VIP
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.

UJm5430.jpeg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
476 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top