Trend Coloring Price Bars

Haidason7

New member
VIP
I am looking for a script to assign color based on trend control. I've attached an image with colored arrows for example.

1. Uptrend = assume up-bars are making new highs, the next bar is a down-bar, but doesn't close lower than the previous green bar open. I need that bar to stay "green". Same for subsequent down-bars that don't close lower than the last up-bar. A down-bar that closes lower than the last up-bar open, should continue to color as down.

2. Downtrend = just the opposite. Down-bars painting red, then an up-bar, but doesn't close higher than the open of the down-bar; it needs to paint as as a down-bar. Up-bar only paints green, if it closes higher than close of the last down-bar.
 
Last edited:
Solution
Another option, don't know if it is any better or not.
Probably could still use some tweaking.
Ruby:
def UpBar = close>open;
def DnBar = close<open;
def Doji = open==close;
def UpTrendBottom = if UpBar then open else UpTrendBottom[1];
def DnTrendTop = if DnBar then open else DnTrendTop[1];

def GreenBar = (UpBar and close>DnTrendTop) or (DnBar and GreenBar[1] and close>=UpTrendBottom);
def RedBar = (DnBar and close<UpTrendBottom) or (UpBar and RedBar[1] and close<=DnTrendTop);
def GreenDoji = Doji and GreenBar[1];
def RedDoji = Doji and RedBar[1];

AssignPriceColor(if GreenDoji or GreenBar or(GreenBar[1] and close>=close[1]) then Color.UpTick else Color.Current);
AssignPriceColor(if RedDoji or RedBar or (RedBar[1] and close<=close[1])...
Thank you for the response but HA wont work. I would like to maintain the standard candle price action.
Fine. This should do then.

Ruby:
def c = close;
def h = high;
def o = open;

AssignPriceColor(if h > h[1] and c > o[1] then Color.Green else Color.CURRENT);

PS: This based on your condition definition, nothing done to the downside trend in the above code, but your get the idea your can add an else if statement for the downside trend.
 
Last edited:
Another option, don't know if it is any better or not.
Probably could still use some tweaking.
Ruby:
def UpBar = close>open;
def DnBar = close<open;
def Doji = open==close;
def UpTrendBottom = if UpBar then open else UpTrendBottom[1];
def DnTrendTop = if DnBar then open else DnTrendTop[1];

def GreenBar = (UpBar and close>DnTrendTop) or (DnBar and GreenBar[1] and close>=UpTrendBottom);
def RedBar = (DnBar and close<UpTrendBottom) or (UpBar and RedBar[1] and close<=DnTrendTop);
def GreenDoji = Doji and GreenBar[1];
def RedDoji = Doji and RedBar[1];

AssignPriceColor(if GreenDoji or GreenBar or(GreenBar[1] and close>=close[1]) then Color.UpTick else Color.Current);
AssignPriceColor(if RedDoji or RedBar or (RedBar[1] and close<=close[1]) then Color.DownTick else Color.Current);

jYrDoa6.png
 
Solution
Svanoy, i found this green candle today on the MES. I've seen the scenario a few other times, but this has been the best example. I thought I would ask if this can be improved. This was on an 8m chart.

y3Ccaq8.png
 
Svanoy, i found this green candle today on the MES. I've seen the scenario a few other times, but this has been the best example. I thought I would ask if this can be improved. This was on an 8m chart.

y3Ccaq8.png
Try the simple 4 liner code, it works and is designed to what you need. you may want to through the reverse condition too with color Red, but it works.
 
@Haidason7
Ruby:
def UpBar = close>open;
def DnBar = close<open;
def InBar = high<=high[1] and low>=low[1];
def Doji = open==close;
def UpTrendBottom = if UpBar then open else UpTrendBottom[1];
def DnTrendTop = if DnBar then open else DnTrendTop[1];

def GreenBar = (UpBar and close>=DnTrendTop) 
                or (DnBar and GreenBar[1] and close>=UpTrendBottom) 
                or (UpBar and close<=UpTrendBottom[1]) or (InBar and GreenBar[1]) 
                or (Doji and GreenBar[1]);
def RedBar = (DnBar and close<=UpTrendBottom) 
                or (UpBar and RedBar[1] and close<=DnTrendTop) 
                or (DnBar and close<=DnTrendTop[1]) or (InBar and RedBar[1]) 
                or (Doji and RedBar[1]);

AssignPriceColor(if GreenBar then Color.UpTick else Color.Current);
AssignPriceColor(if RedBar then Color.DownTick else Color.Current);

CcZsEcL.png
 

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
628 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