# Easy Green Candle Color Watchlist

#### MBF

##### Active member
2019 Donor
Hi all,
i am frustrated with this script. What am I doing wrong here? I've changed GreenBar and Candle1 soo many times I've confused myself. Its so simple, why is it not working?

def GreenBar = (open > close);
def candle1 = If (yes, GreenBar(), Double.NaN);
plot candle1 = if (yes)is true then 1 else 0;

AssignBackgroundColor(if candle1 == 1 then Color.GREEN else Color.GRAY);

Solution
Hi all,
i am frustrated with this script. What am I doing wrong here? I've changed GreenBar and Candle1 soo many times I've confused myself. Its so simple, why is it not working?

def GreenBar = (open > close);
def candle1 = If (yes, GreenBar(), Double.NaN);
plot candle1 = if (yes)is true then 1 else 0;

AssignBackgroundColor(if candle1 == 1 then Color.GREEN else Color.GRAY);

you are trying to define a boolean variable, greenbar, but then trying to define 2 more variables, with the same value, that aren't needed?

1. this is wrong
def GreenBar = (open > close);

should be
def GreenBar = (close > open);
this will be true or false, 1 or 0.

2. def candle1 = If (yes, GreenBar(), Double.NaN)...
Hi all,
i am frustrated with this script. What am I doing wrong here? I've changed GreenBar and Candle1 soo many times I've confused myself. Its so simple, why is it not working?

def GreenBar = (open > close);
def candle1 = If (yes, GreenBar(), Double.NaN);
plot candle1 = if (yes)is true then 1 else 0;

AssignBackgroundColor(if candle1 == 1 then Color.GREEN else Color.GRAY);

you are trying to define a boolean variable, greenbar, but then trying to define 2 more variables, with the same value, that aren't needed?

1. this is wrong
def GreenBar = (open > close);

should be
def GreenBar = (close > open);
this will be true or false, 1 or 0.

2. def candle1 = If (yes, GreenBar(), Double.NaN);
greenbar() doesn't exist, there is no function with that name.
it is pointless to set the condition of a if-then to yes,
might as well write
def candle1 = greenbar;

maybe you meant this
def candle1 = if greenbar then 1 else double.nan;

3. plot candle1 = if (yes)is true then 1 else 0;
duplicate variable name. already used candle1 in previous code line.
it is pointless to set the condition to yes,
why are you plotting a boolean value? just to show something in the column

correct line
plot candle2 = if candle1 then 1 else 0;

4. AssignBackgroundColor(if candle1 == 1 then Color.GREEN else Color.GRAY);
this works. although the == 1 isn't really nessesary

------------------------

candle1 and candle2 are basically the same as greenbar, so might as well remove them and just use greenbar.

i think it is better to stick with 1 and 0 during signal formulas, and wait to use double.nan in plot formulas.
sometimes those double.nan values can cascade through the formulas and cause unwanted results.

this is how i would write it

Code:
``````# column study
plot GreenBar = (close > open);
AssignBackgroundColor(if greenbar then Color.GREEN else Color.GRAY);``````

----------------------------------

if i wanted to look for green and red bars,....

Code:
``````def GreenBar = (close > open);
def redBar = (close < open);
AssignBackgroundColor(if greenbar then Color.GREEN else if redbar then color.red else Color.GRAY);``````

Last edited:
you are trying to define a boolean variable, greenbar, but then trying to define 2 more variables, with the same value, that aren't needed?

1. this is wrong
def GreenBar = (open > close);

should be
def GreenBar = (close > open);
this will be true or false, 1 or 0.

2. def candle1 = If (yes, GreenBar(), Double.NaN);
greenbar() doesn't exist, there is no function with that name.
it is pointless to set the condition of a if-then to yes,
might as well write
def candle1 = greenbar;

maybe you meant this
def candle1 = if greenbar then 1 else double.nan;

3. plot candle1 = if (yes)is true then 1 else 0;
duplicate variable name. already used candle1 in previous code line.
it is pointless to set the condition to yes,
why are you plotting a boolean value? just to show something in the column

correct line
plot candle2 = if candle1 then 1 else 0;

4. AssignBackgroundColor(if candle1 == 1 then Color.GREEN else Color.GRAY);
this works. although the == 1 isn't really nessesary

------------------------

candle1 and candle2 are basically the same as greenbar, so might as well remove them and just use greenbar.

i think it is better to stick with 1 and 0 during signal formulas, and wait to use double.nan in plot formulas.
sometimes those double.nan values can cascade through the formulas and cause unwanted results.

this is how i would write it

Code:
``````# column study
plot GreenBar = (close > open);
AssignBackgroundColor(if greenbar then Color.GREEN else Color.GRAY);``````

----------------------------------

if i wanted to look for green and red bars,....

Code:
``````def GreenBar = (close > open);
def redBar = (close < open);
AssignBackgroundColor(if greenbar then Color.GREEN else if redbar then color.red else Color.GRAY);``````
Interesting. The GreenBar I was using is an easy bar I created in the candlestick wizard, so I thought I could use that one. Ah yes, I see what I did wrong with the open and close.
So the Plot cannot be the same as the definition? Can Plot be anything I want to name it?
I cannot code. I am trying but I basically come here, look for similar codes and try to piece them together to get what I need. Most of the time this works. This was why I iwas so frustrated with this easy one. Thank you so much @halcyonguy! Now I know what happened and can use this correctly in the future.

Interesting. The GreenBar I was using is an easy bar I created in the candlestick wizard, so I thought I could use that one. Ah yes, I see what I did wrong with the open and close.
So the Plot cannot be the same as the definition? Can Plot be anything I want to name it?
I cannot code. I am trying but I basically come here, look for similar codes and try to piece them together to get what I need. Most of the time this works. This was why I iwas so frustrated with this easy one. Thank you so much @halcyonguy! Now I know what happened and can use this correctly in the future.

def and plot assign a number to a variable.
all variables have to be unique.
a variable can be named almost anything, with letters and numbers and underline.
some people use multiple , capitalized words i like to separate words with _ , def gap_change_percent = ...

unfortunetely the wizard can create convoluted code. keep reading through posts to see how others do things.

def and plot assign a number to a variable.
all variables have to be unique.
a variable can be named almost anything, with letters and numbers and underline.
some people use multiple , capitalized words i like to separate words with _ , def gap_change_percent = ...

unfortunetely the wizard can create convoluted code. keep reading through posts to see how others do things.
@halcyonguy why thank you very much for the explanation. I was in the Discord Stat room and I went to the indicator rabbit hole section and I saw a name. Thought it looked familiar. Lo, it was you!

@halcyonguy
So about this easy watchlist Day BO column. I am trying to only show it as green after 8AM in the morning.
Right now it is green from Friday's BO. I am more than confused about this function and have looked in here for a script that may well help but found none. Can anyone help with some (just a little)elaboration on this function?
Here is the code.
def BO = close crosses above high[1];
plot HBO = if close crosses above high[1] then 1 else 0;
AssignBackgroundColor (if HBO then color.green else color.black);

87k+ Posts
218 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?