Candle Equilibrium coding struggle

perdelta

New member
I am someone that struggles with coding and am hoping there is an easy fix to my coding shortcomings.

I want a script that highlights the two candle that form what I refer to as equilibrium. Equilibrium for this example being when an up candle close and the very next down candle's open are exactly the same or when a down candle's close and the very next candle is a down candle's open are exactly the same.

Here's my current code: (almost exclusively used from halcyonguy's script in the post https://usethinkscript.com/threads/...g-inside-candle-formations.15820/#post-127558 (I hope my use of halcyonguy's script doesn't create offense. I found the thread to be incredibly interesting and helpful.)

#Candle Equilibrium

def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def barup = (c > o);
def bardwn = (c < o);
def equilibrium = open==close[1];

AssignPriceColor(if equilibrium
then color.light_orange
else color.current);

I have attached a chart for a better visual example.

Any assistance with this would be greatly appreciated.

Candle Equilibrium - Current Code Pic.png
 
Last edited:
Solution
I am someone that struggles with coding and am hoping there is an easy fix to my coding shortcomings.

I want a script that highlights the two candle that form what I refer to as equilibrium. Equilibrium for this example being when an up candle close and the very next down candle's open are exactly the same or when a down candle's close and the very next candle is a down candle's open are exactly the same.

Here's my current code: (almost exclusively used from halcyonguy's script in the post https://usethinkscript.com/threads/...g-inside-candle-formations.15820/#post-127558 (I hope my use of halcyonguy's script doesn't create offense. I found the thread to be incredibly interesting and helpful.)...
I am someone that struggles with coding and am hoping there is an easy fix to my coding shortcomings.

I want a script that highlights the two candle that form what I refer to as equilibrium. Equilibrium for this example being when an up candle close and the very next down candle's open are exactly the same or when a down candle's close and the very next candle is a down candle's open are exactly the same.

Here's my current code: (almost exclusively used from halcyonguy's script in the post https://usethinkscript.com/threads/...g-inside-candle-formations.15820/#post-127558 (I hope my use of halcyonguy's script doesn't create offense. I found the thread to be incredibly interesting and helpful.)

#Candle Equilibrium

def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def barup = (c > o);
def bardwn = (c < o);
def equilibrium = open==close[1];

AssignPriceColor(if equilibrium
then color.light_orange
else color.current);

I have attached a chart for a better visual example.

Any assistance with this would be greatly appreciated.

View attachment 19090

This might work how you want:

If 2 bar then both are colored magenta, even if the prior is close[1] == open
If not 2 bar but close[1] == open then colored yellow
There is an option to isolate the above 2 by selecting test = yes to make all other bars colored gray
There is a bubble option to further test the resulting coloring

Screenshot 2023-07-23 162906.jpg
Code:
#Candle Equilibrium

def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def barup  = (c > o);
def bardwn = (c < o);
def equilibrium = barup[1] and bardwn and c[1] == o
                  or
                  bardwn[1] and barup and c[1] == o
                  ;

input pricecoloring = yes;
input test   = yes;
input bubble = yes;

AssignPriceColor(
if !pricecoloring
then Color.CURRENT
     else if equilibrium == 1
     then Color.MAGENTA
     else if equilibrium[-1] == 1
     then Color.MAGENTA
     else if equilibrium == 0 and c[1] == o
     then Color.YELLOW
     else if test and c[1] != o   
     then Color.GRAY
else Color.CURRENT);

AddChartBubble(bubble or test, high * 1.005, "C1: " + c[1] + "\nO:  " + o + "\nC: " + c + "\nE: " + equilibrium, if equilibrium == 0 and c[1] == o then Color.YELLOW else if equilibrium then Color.MAGENTA else Color.GRAY);

#
 
Solution

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