Red to Green Previous Day Price Close

Cowabunga

New member
Hey all,

I'm trying to design an indicator to plot a line for the previous day closing price and the line to display the different color lines depending on the market conditions. I am interested in using this to play Red to Green or Green to Red trades. I searched and didn't find anything so I gave it a try and see if I could come up with something myself. Here's the code that I have so far:

input Close_Color = {default single};

plot Data = close;
plot priceLine = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);


def RedDay = Data < priceLine;
def GreenDay = Data > priceLine;

plot DailyClose = close(period = ”DAY”)[1];
DailyClose.SetDefaultColor(Color.BLACK);
DailyClose.DefineColor("Above Close", Color.DARK_GREEN);
DailyClose.DefineColor("Below Close", Color.DARK_RED);
DailyClose.HideBubble();
DailyClose.HideTitle();


DailyClose.AssignValueColor(if Close_Color == Color_Color.fluid and RedDay then DailyClose.Color("Above Close")
else if Close_Color == Color_Color.fluid and GreenDay then DailyClose.Color("Below Close")
else Color.BLACK);

However, I keep getting and error message ("NO such constant: Color_color.fluid at 19.52). I tried a different iterations of this code and it displayed the previous day close but the colors were off. Any help would be great and much appreciate.
 
the input was missing a choice called fluid

# add fluid as a choice
input Close_Color = {default single , fluid};


variable name was spelled wrong. didn't match the name used in input
# change variable name from Color_Color. to close_Color.

DailyClose.AssignValueColor(if Close_Color == close_Color.fluid and RedDay then DailyClose.Color("Above Close")
else if Close_Color == close_Color.fluid and GreenDay then DailyClose.Color("Below Close")
else Color.BLACK);

i didn't test to see if the desired colored lines are plotted

Ruby:
# prevdayclosew_01

#input Close_Color = {default  single };
#  add  fluid as a choice
input Close_Color = {default  single , fluid};


plot Data = close;
plot priceLine = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);


def RedDay = Data < priceLine;
def GreenDay = Data > priceLine;

plot DailyClose = close(period = ”DAY”)[1];
DailyClose.SetDefaultColor(Color.BLACK);
DailyClose.DefineColor("Above Close", Color.DARK_GREEN);
DailyClose.DefineColor("Below Close", Color.DARK_RED);
DailyClose.HideBubble();
DailyClose.HideTitle();

#
#DailyClose.AssignValueColor(if Close_Color == Color_Color.fluid and RedDay then DailyClose.Color("Above Close")
#else if Close_Color == Color_Color.fluid and GreenDay then DailyClose.Color("Below Close")
#else Color.BLACK);

#  change var name from Color_Color.   to close_Color.
DailyClose.AssignValueColor(if Close_Color == close_Color.fluid and RedDay then DailyClose.Color("Above Close")
  else if Close_Color == close_Color.fluid and GreenDay then DailyClose.Color("Below Close")
  else Color.BLACK);

#
 
Last edited:

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

Hey halcyonguy,

Thanks for the reply and correcting the little errors that I have in my script. The code works but the colors display is slightly off. Price is over previous day close but the line displayed is majority red with green spots throughout.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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