Help with painting/re-painting bars

kktrades

New member
Hello @MerryDay @halcyonguy @BenTen @SleepyZ or any others, wondering if any of you can help me with a script with the following rules:

Assuming bull bar is green and bear bar is red (only for RTH).

For bull bars:
1. The highest bull bar should be blue. Starting at 9:30am est, first bull bar will be blue. When a new higher high bull bar forms, that must be blue and the previous blue bull bar with a lower high must be put back to green.
2. Top most bull bar will be blue, any bull bar to the left of the top most bull bar will be green. Any bull bars to the right of the top most bull bar with a lower high must also be blue, provided there is no higher high bull bar to its right.


Similarly with bear bars:
1. First bear bar of the day (RTH) starts with purple. Lowest bear bar is to remain purple, with previous bear bars turning back to red where the current bear bar has made a lower low.
2. Higher low bear bars to the left will remain red while the higher low bear bars to the right will remain purple.
3. When a higher high bear bar forms, all purple bear bars to the right with a lower low of it must turn back to red.

The idea is that the blue bars act as resistance and the purple bars act as support.

I hope the logic as I have explained is not contradicting or flawed!

Thank you again very much for what you do here in this forum! Its a great inspiration!!

-kktrades

PS: Apologies, I feel like that I could have explained this in simple terms. Put simply:
Current bull bar always ends blue. If its a higher high compared to the previous blue bar, the previous blue bar becomes green, else remains blue.

Current bear bar always ends purple and if its a lower high compared to the previous purple bar, that previous purple bar becomes red, else remains purple.
 
Last edited:
Solution
Hello @MerryDay @halcyonguy @BenTen @SleepyZ or any others, wondering if any of you can help me with a script with the following rules:

Assuming bull bar is green and bear bar is red (only for RTH).

For bull bars:
1. The highest bull bar should be blue. Starting at 9:30am est, first bull bar will be blue. When a new higher high bull bar forms, that must be blue and the previous blue bull bar with a lower high must be put back to green.
2. Top most bull bar will be blue, any bull bar to the left of the top most bull bar will be green. Any bull bars to the right of the top most bull bar with a lower high must also be blue, provided there is no higher high bull bar to its right.


Similarly with bear bars:
1...
Hello @MerryDay @halcyonguy @BenTen @SleepyZ or any others, wondering if any of you can help me with a script with the following rules:

Assuming bull bar is green and bear bar is red (only for RTH).

For bull bars:
1. The highest bull bar should be blue. Starting at 9:30am est, first bull bar will be blue. When a new higher high bull bar forms, that must be blue and the previous blue bull bar with a lower high must be put back to green.
2. Top most bull bar will be blue, any bull bar to the left of the top most bull bar will be green. Any bull bars to the right of the top most bull bar with a lower high must also be blue, provided there is no higher high bull bar to its right.


Similarly with bear bars:
1. First bear bar of the day (RTH) starts with purple. Lowest bear bar is to remain purple, with previous bear bars turning back to red where the current bear bar has made a lower low.
2. Higher low bear bars to the left will remain red while the higher low bear bars to the right will remain purple.
3. When a higher high bear bar forms, all purple bear bars to the right with a lower low of it must turn back to red.

The idea is that the blue bars act as resistance and the purple bars act as support.

I hope the logic as I have explained is not contradicting or flawed!

Thank you again very much for what you do here in this forum! Its a great inspiration!!

-kktrades

PS: Apologies, I feel like that I could have explained this in simple terms. Put simply:
Current bull bar always ends blue. If its a higher high compared to the previous blue bar, the previous blue bar becomes green, else remains blue.

Current bear bar always ends purple and if its a lower high compared to the previous purple bar, that previous purple bar becomes red, else remains purple.


this will color the price bars.
i added,
..if a bar has a higher high and a lower low, then it is white.
..if a bar doesn't not have either, then it is gray.


Code:
#highs_lows_colored

#https://usethinkscript.com/threads/help-with-painting-re-painting-bars.16193/

def na = Double.NaN;
def bn = BarNumber();
def big = 99999;

# highs
#  highest , blue
#  highs before highest , green
#  highs after highest , blue

# lows
#  lowest , purple
#  lows before lowest , red
#  lows after lowest , purple

DefineGlobalColor("highest" , Color.BLUE);
DefineGlobalColor("highs_before" , Color.green);
DefineGlobalColor("highs_after", Color.blue);

DefineGlobalColor("lowest", Color.MAGENTA);
DefineGlobalColor("lows_before", Color.red);
DefineGlobalColor("lows_after", Color.magenta);

DefineGlobalColor("hilo", Color.white);
DefineGlobalColor("none", Color.gray);


def hihi = HighestAll(high);
def lolo = LowestAll(low);

def hibn = HighestAll(if hihi == high then bn else 0);
def lobn = LowestAll(if lolo == low then bn else big);

def hi = high > high[1];
def lo = low < low[1];

# color bars
AssignPriceColor(
     if bn == hibn then GlobalColor("highest")
else if bn == lobn then GlobalColor("lowest")
else if hi and lo then GlobalColor("hilo")

else if hi and bn < hibn then GlobalColor("highs_before")
else if hi and bn > hibn then GlobalColor("highs_after")

else if lo and bn < lobn then GlobalColor("lows_before")
else if lo and bn > lobn then GlobalColor("lows_after")
else GlobalColor("none") );
#else Color.CURRENT);
#

QEBXvhI.jpg
 
Solution
@halcyonguy Thank you very much for code! Really appreciate it!!

Is it possible for the past bars to switch color / repaint after many bars? I would prefer the down bars (bar # 3 & 5 in your screen shot) to remain red. Also seeing some up bars as red, which I would prefer to remain green. Also, the 2nd blue bar from the left, seems to be a down bar (?), in which case it should be red.

Ultimately this is what I am looking for:
Every bull bar finishes blue, but needs to switch back to green if there is a higher high bull bar to the right.
Similarly, every bear bar finishes magenta, but needs to switch back to red, if there is a lower low bear bar to the right.

Any idea why my screen looks like this? This is NQ 1 minute chart.

THANK YOU AGAIN !!

PS: Please ignore the dashed lines. Another study that I crated.
 

Attachments

  • Screenshot 2023-07-28 at 11.34.30 AM.png
    Screenshot 2023-07-28 at 11.34.30 AM.png
    94.7 KB · Views: 150
@halcyonguy I've attached the screen shot of the first day in my chart. Looks like HishestAll() and LowestAll() considers chart duration. I'd like this to reset/work for RTH, if that's possible.

Thank you !!!
 

Attachments

  • Screenshot 2023-07-28 at 12.46.22 PM.png
    Screenshot 2023-07-28 at 12.46.22 PM.png
    198.9 KB · Views: 158

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