What am I doing wrong here? Help with background alert color

This is the code I have written. the arrow comes up but the screen is not changing colors. I have a screen with my watchlist and I want the chart to change color when the Arrow comes in so my eyes can catch it.

Code:
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
plot PatternPlot =
    IsDown[1] and
    IsUp[0] and
    low[1] == low[0] and
    high[1] < close[0] and
    low[1] <= open[0] and
    high[1] != high[0];

PatternPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
PatternPlot.SetDefaultColor(CreateColor(0, 0, 153));

alert(patternPlot, “BULLISH”, alert.bar, sound.ring);

assignbackgroundcolor(if patternPlot is true then color.blue
else color.dark_gray);
 
@joshua74133 If your logic is correct, and your Alert is working, all you should need is the following... Notice what's missing... I didn't test your code, I just removed the code that was either redundant or was interfering with the AssignBackgroundColor() logic...

Ruby:
assignbackgroundcolor(if patternPlot then color.blue else color.dark_gray);

If that doesn't work then try this...

Ruby:
plot PatternPlot =
if IsDown[1] and
IsUp[0] and
low[1] == low[0] and
high[1] < close[0] and
low[1] <= open[0] and
high[1] != high[0]
then 1 
else Double.NaN;
 
@joshua74133 I had no problem w/ the original code you posted:
MoxcXyw.png
 
now its not working for this script. the alert works fine just not the screen color change

Code:
# Candlestick Reversal System
# Assembled by BenTen at useThinkScript.com
# Converted from [URL]https://www.tradingview.com/script/H5290fLn-Candlestick-Reversal-System/[/URL]

input extreme_reversal = yes;
input outside_reversal = yes;
input doji_reversal = yes;

def O = open;
def C = close;
def H = high;
def L = low;

input bodysize = 0.525;
input barsback = 50;
input bodymultiplier = 2;

def mybodysize = absValue(C - O);
def AverageBody = simpleMovingAvg(mybodysize, barsback);
def mycandlesize = (H - L);
def AverageCandle = simpleMovingAvg(mycandlesize, barsback);

def Elongsignal = ((O[1] - C[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) >  AverageBody) and (C > O);
def Eshortsignal = ((C[1] - O[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) >  AverageBody) and (O > C);

input BarMultiplier = 1.25;

def AverageCandle1 = simpleMovingAvg(mycandlesize, BarsBack);

def Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * BarMultiplier;
def Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * BarMultiplier;

input percentage = 0.1;

def frangehl = H[1] - L[1];
def frangeco = absValue(C[1] - O[1]);
def sma10 = simpleMovingAvg(close, 10);

def Dshortsignal = (frangeco <= frangehl * percentage and C < L[1] and L[1] > sma10 and C < O)  or (C < L[2] and C[1] >= L[2] and frangeco <= frangeco * percentage and C < O and L[2] > sma10);
def Dlongsignal = (frangeco <= frangehl * percentage and C > H[1] and H[1] < sma10 and C > O)  or (C > H[2] and C[1] <= H[2] and frangeco <= frangeco * percentage and C > O and H[2] < sma10);

plot bullish_extreme = if extreme_reversal then Elongsignal else double.nan;
plot bearish_extreme = if extreme_reversal then Eshortsignal else double.nan;

plot bullish_outside = if outside_reversal then Olongsignal else double.nan;
plot bearish_outside = if outside_reversal then Oshortsignal else double.nan;

plot bullish_doji = if doji_reversal then Dlongsignal else double.nan;
plot bearish_doji = if doji_reversal then Dshortsignal else double.nan;

bullish_extreme.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_extreme.SetDefaultColor(Color.CYAN);
bullish_extreme.SetLineWeight(1);
bearish_extreme.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_extreme.SetDefaultColor(Color.CYAN);
bearish_extreme.SetLineWeight(1);

bullish_outside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_outside.SetDefaultColor(Color.MAGENTA);
bullish_outside.SetLineWeight(1);
bearish_outside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_outside.SetDefaultColor(Color.MAGENTA);
bearish_outside.SetLineWeight(1);

bullish_doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_doji.SetDefaultColor(Color.YELLOW);
bullish_doji.SetLineWeight(1);
bearish_doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_doji.SetDefaultColor(Color.YELLOW);
bearish_doji.SetLineWeight(1);

alert(bullish_doji, “BULLISH DOJI”, alert.bar, sound.RING);
alert(bullish_extreme, “BULLISH EXTREME”, alert.bar, sound.DING);

assignbackgroundcolor(if bullish_doji then color.yellow else color.dark_gray);
assignbackgroundcolor(if BULLISh_Extreme then color.blue else color.dark_gray);
assignbackgroundcolor(if BULLISh_OUTside then color.blue else color.dark_gray);
 
try using 1 assignbackgroundcolor() with a long if then else to handle all the possibilities

Code:
assignbackgroundcolor( if bullish_doji then color.yellow else if BULLISh_Extreme then color.blue else if BULLISh_OUTside then color.blue else color.dark_gray);
 
Yes, it needs to be one statement. Whatever color gets assigned first wins. Subsequent calls to AssignBackgroundColor will be ignored. Only the bullish doji condition would work properly in the code with 3 calls. Once that line sets dark gray nothing else can change it.

This also includes AssignBackgroundColor calls from other scripts. Whoever assigns first wins. If you have any other studies on the chart that also may assign bg color, they might be interfering. Either remove those or move this one above them in the list of studies applied to your chart.

The same thing occurs with AssignPriceColor, too.
 
Yes, it needs to be one statement. Whatever color gets assigned first wins. Subsequent calls to AssignBackgroundColor will be ignored. Only the bullish doji condition would work properly in the code with 3 calls. Once that line sets dark gray nothing else can change it.

This also includes AssignBackgroundColor calls from other scripts. Whoever assigns first wins. If you have any other studies on the chart that also may assign bg color, they might be interfering. Either remove those or move this one above them in the list of studies applied to your chart.

The same thing occurs with AssignPriceColor, too.

To add to what @Slippage stated, one way to know there is a problem of this nature, and any others, is that you will see a circled "!" exclamation mark in the upper left hand corner of your Chart... Clicking on that icon will reveal messages related to any problems with your chart... You should address all problems listed to avoid unexpected performance issues...
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
263 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