How to assign hierarchy in painting Candles?

Trigun1127

Member
Hey guys Im trying to get into coding by just looking at other peoples code. I'm trying to paint 4 types of bars but I would like them arranged in a hierarchy. Where if the Top code is first in that hierarchy it will ignore the other paint codes. How would I do this?
 
Solution
I'm looking at the post on page 10 but I don't understand how to use > < when its not something like rsi(14). I don't know anything about coding just taking a shot in the dark here barely know what anything means just guessing. Id assume there would be some kind of function where Gap1up > NormalGapup then Color.XXXX but I don't know how to assign that its in fact greater.

See if this is what you requested

Ruby:
def Gap1Up = open [0] > close[1];
def Gap1Dn = open [0] < close[1];
def NormalGapDown = open < close [3];
def NormalGapUp = open > close [3];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if Gap1Up and close > open
then Color.ORANGE
else if NormalGapUp and close > open
then...

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

I apologize I'm not getting it. I'm trying to get Gap1up to Prioritize over NormalGapUp and Gap1Dn to prioritize over NormalGapDown


def Gap1Up = open [0] > close[1];
def Gap1Dn = open [0] < close[1];
def NormalGapDown = open < close [3];
def NormalGapUp = Open > close [3];
input pricecolor = yes;
AssignPriceColor(if Gap1Up
then color.Orange
else color.current);
AssignPriceColor(if NormalGapUp
then color.White
else color.current);
AssignPriceColor(if Gap1DN
then color.Orange
else color.current);
AssignPriceColor(if NormalGapDown
then color.Blue
else color.current);
Another thing Im trying to code is how do i specifically make something like Gap1dn only pertain to Bear Bars instead of a ... Bull bar open [0] < close [1]. I know I need to define what a bear bar Close < Open but how to I tie that to Gap1DN. Maby I haven no clue what im saying lol.
 
Last edited:
I'm apologize I'm not getting it. I'm trying to get Gap1up to Prioritize over NormalGapUp and Gap1Dn to prioritize over NormalGapDown



Another thing Im trying to code is how do i specifically make something like Gap1dn only pertain to Bear Bars instead of a ... Bull bar open [0] < close [1]. I know I need to define what a bear bar Close < Open but how to I tie that to Gap1DN. Maby I haven no clue what im saying lol.

should use only one instance of
AssignPriceColor( )
combine all your if-then's into one.

go back and read sleepyz post2 and look at the linked code.
 
I'm looking at the post on page 10 but I don't understand how to use > < when its not something like rsi(14). I don't know anything about coding just taking a shot in the dark here barely know what anything means just guessing. Id assume there would be some kind of function where Gap1up > NormalGapup then Color.XXXX but I don't know how to assign that its in fact greater.
 
I'm looking at the post on page 10 but I don't understand how to use > < when its not something like rsi(14). I don't know anything about coding just taking a shot in the dark here barely know what anything means just guessing. Id assume there would be some kind of function where Gap1up > NormalGapup then Color.XXXX but I don't know how to assign that its in fact greater.

See if this is what you requested

Ruby:
def Gap1Up = open [0] > close[1];
def Gap1Dn = open [0] < close[1];
def NormalGapDown = open < close [3];
def NormalGapUp = open > close [3];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if Gap1Up and close > open
then Color.ORANGE
else if NormalGapUp and close > open
then Color.WHITE
else if Gap1Dn and close < open
then Color.ORANGE
else if NormalGapDown and close < open
then Color.BLUE
else Color.CURRENT);
 
Solution
Ok got it and im understanding the hierarchy thing now. I didn't get that it was just about coding what you wanted then "else if" as the next lower block on the hierarchy. Thanks!
 
One more thing! How would I stop the color plotting when there's an exception to the rule for example
For example I have
else if NormalGapDown and close < open or close>open
then Color.BLUE
but i don't want this to plot when [2] close is greater then the current bars open.


So this is what im trying to do
input begin = 930;
plot firstbar = secondsFromTime(begin)==0;
input Reset_Time = 0930;
def NormalGapDown = open < close [2];
def NormalGapUp = open > close [2];
def TailGapUp = low > high[2];
def TailGapDn = high < low[2];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if TailGapUp and close > open or close < open and low > high [2]
then color.yellow
else if NormalGapUp and close > open
then Color.WHITE
else if TailGapDn and close < open or close > open and high < low [2]
then color.dark_RED
else if NormalGapDown and close < open or close>open
then Color.BLUE
else Color.CURRENT);

I want the exception that if that yellow bars close is greater then that blue bars close it should just be painted grey or current color. cant get it work though.
 
Last edited:
One more thing! How would I stop the color plotting when there's an exception to the rule for example
For example I have

but i don't want this to plot when [2] close is greater then the current bars open.


So this is what im trying to do


I want the exception that if that yellow bars close is greater then that blue bars close it should just be painted grey or current color. cant get it work though.

This colors it gray in the upper chart. Your code is in the lower chart. I only tested this one.

Screenshot-2022-09-29-060449.jpg
Ruby:
input begin = 930;
plot firstbar = secondsFromTime(begin)==0;
input Reset_Time = 0930;
def NormalGapDown = open < close [2];
def NormalGapUp = open > close [2];
def TailGapUp = low > high[2];
def TailGapDn = high < low[2];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if TailGapUp and close > open or close < open and low > high [2]
then color.yellow
else if NormalGapUp and close > open
then Color.WHITE
else if TailGapDn and close < open or close > open and high < low [2]
then color.dark_RED
else if NormalGapDown and Tailgapup[2] and Tailgapup[1] and close[2] > close
then color.gray
else if NormalGapDown and close < open or close>open
then Color.BLUE
else Color.CURRENT);
 
Got it. That helped me. I'm appreciating what you guys do ever more so now. Its hard for me to hold what logic is true / false corresponding to my own belief.
So this is what I've gotten so far.
I was able to get more bars grey that I wanted grey but now I'm all confused on how to achieve the rest. You can see captions here for the process.
I would like to be able to have any grey bar either be grey or current (normal green red bars)

 
Got it. That helped me. I'm appreciating what you guys do ever more so now. Its hard for me to hold what logic is true / false corresponding to my own belief.
So this is what I've gotten so far.
I was able to get more bars grey that I wanted grey but now I'm all confused on how to achieve the rest. You can see captions here for the process.
I would like to be able to have any grey bar either be grey or current (normal green red bars)

I do not understand what the logic is that you are using to gray out those bars. I only have seen the 2 yellow followed by a blue that you did not want blue that I provided above. I do not want to guess what it is that you want. Thanks.
 
I've got to say its hard to know what i want too!
Basically NormalGapdown should happen with mixed candles
Bear bar [2] close would be > then current bear bar open
Bear bar [2] close would be > then current bull bar close
Bull bar [2] open would be > then current Bull bar close
Bull bar [2] open would be > then current bear bar open
(i believe thats correct)
Here are picture examples

Grey candles should happen When [2] doesn't meet criteria and there is no gap or tail gap and usually occurs when theres alot of overlap with bars
 
Also not if sure if normalGapdown and normalgapup should be redefined now that I think about it.

The same mixed candles Idea apply for the white NormalGapUp bars except reverse.

************** Edit **************

would like to report ive made some headway on this although there are finicky rules that I'm trying to fix.

Do you have any idea on how I can only start the bar paint for RTH? I dont have extended hours on?
Another Question I have is how can i have every bar that does not fit the rule a certain color like grey?
 
Last edited:
Also not if sure if normalGapdown and normalgapup should be redefined now that I think about it.

The same mixed candles Idea apply for the white NormalGapUp bars except reverse.

************** Edit **************

would like to report ive made some headway on this although there are finicky rules that I'm trying to fix.

Do you have any idea on how I can only start the bar paint for RTH? I dont have extended hours on?
Another Question I have is how can i have every bar that does not fit the rule a certain color like grey?

As I understand your RTH request, since you have a longest lookback of 2 (close[2], high[2], etc). is to make sure that the only bars that are used to test the gaps are the same day's RTH. So the 3rd bar looks back to the opening RTH bar for the close[2] test, for example. Also, the first 2 bars will then be colored gray on each chart's timeframe. The following tries to do that.

The last request was to color all bars not part of your coloring, replacing the final 'else color.current' with color.gray does that.

Ruby:
input longest_lookback = 2;
input begin = 0930;
def firstbar = SecondsFromTime(begin) == 0;
input Reset_Time = 0930;

def bn = BarNumber();
def beginbar = if firstbar then bn else beginbar[1];
def NormalGapDown = open < close [2];
def NormalGapUp = open > close [2];
def TailGapUp = low > high[2];
def TailGapDn = high < low[2];

input pricecolor = yes;

AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if Between(bn, beginbar, beginbar + longest_lookback - 1)
then Color.GRAY
else if bn > beginbar + longest_lookback - 1 and SecondsFromTime(1600) <= 0
then if TailGapUp and close > open or close < open and low > high [2]
then Color.YELLOW
else if NormalGapUp and close > open
then Color.WHITE
else if TailGapDn and close < open or close > open and high < low [2]
then Color.DARK_RED
else if NormalGapDown and TailGapUp[2] and TailGapUp[1] and close[2] > close
then Color.GRAY
else if NormalGapDown and close < open or close > open
then Color.BLUE
else Color.GRAY
else Color.GRAY);
#
 
Last edited:
any clue why this is happening for me


Also ive been playing with this and I dont know how to fix this without screwing up the rest of the code.

Code:
input begin = 930;
plot firstbar = secondsFromTime(begin)==0;
input Reset_Time = 0930;
def TailGapUp = low > high[2];
def TailGapDn = high < low[2];
def NormalGapDown = open < close [2];
def NormalGapDownBearBull = close>open and close<close[2];
def normalgapup = close>open and close[2]>open[2] or open>open[2];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.current

#TailGap Up Hierarchy
else if TailGapUp and close > open or close < open and low > high [2]
then color.yellow

#TailGap Down Hierarchy
else if TailGapDn and close < open or close > open and high < low [2]
then color.dark_RED

#NormalGap Up Section hierarchy
else if normalgapup and close<=close[2]
then color.gRAY
else if normalgapup and open<close[2]
then color.gray
else if normalgapup
then color.white


#gap Down Section Hierarchy
else if normalgapdown and close<open and open>=open[2]
then color.Gray
else if normalgapdown and close<open and close[2]>open[2]
then color.blue
else if NormalGapDown and close[2]>open[2]
then color.gray
else if normalgapdownbearbull and close[2]>open[2]
then color.gray
Else if normalgapdownbearbull
then color.blue
else if NormalGapDown and close < open 
then Color.BLUE
else Color.current);
 
Last edited:
any clue why this is happening for me


Also ive been playing with this and I dont know how to fix this without screwing up the rest of the code.

Here is your playing around incorporated into what I posted

Ruby:
input longest_lookback = 2;
input begin = 930;
plot firstbar = secondsFromTime(begin)==0;
input Reset_Time = 0930;
def bn = BarNumber();
def beginbar = if firstbar then bn else beginbar[1];

def TailGapUp = low > high[2];
def TailGapDn = high < low[2];
def NormalGapDown = open < close [2];
def NormalGapDownBearBull = close>open and close<close[2];
def normalgapup = close>open and close[2]>open[2] or open>open[2];
input pricecolor = yes;
AssignPriceColor(
if !pricecolor
then Color.CURRENT
else if Between(bn, beginbar, beginbar + longest_lookback - 1)
then Color.GRAY
else if bn > beginbar + longest_lookback - 1 and SecondsFromTime(1600) <= 0
then

#TailGap Up Hierarchy
if TailGapUp and close > open or close < open and low > high [2]
then color.yellow

#TailGap Down Hierarchy
else if TailGapDn and close < open or close > open and high < low [2]
then color.dark_RED

#NormalGap Up Section hierarchy
else if normalgapup and close<=close[2]
then color.gRAY
else if normalgapup and open<close[2]
then color.gray
else if normalgapup
then color.white


#gap Down Section Hierarchy
else if normalgapdown and close<open and open>=open[2]
then color.Gray
else if normalgapdown and close<open and close[2]>open[2]
then color.blue
else if NormalGapDown and close[2]>open[2]
then color.gray
else if normalgapdownbearbull and close[2]>open[2]
then color.gray
Else if normalgapdownbearbull
then color.blue
else if NormalGapDown and close < open
then Color.BLUE
else Color.gray
else color.gray);
 
Why wasn't it working for me the "if" problem?

Also in previous post I was talking about this. I don't know why this specific candle isn't working when all others seem to be.

Thanks for Fixing the open time

Without all of the code, I am not sure why the "if" problem. So a guess would be that you did not have an 'else; at the bottom of the code just like the extra one in what I posted above.


The color of that highlighted bar appeaars to be gray because it is a normalgapdown and close[2] > open[2].

Snip.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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