identify bar #12,#18,#23

freedom Traders

New member
Need help with coding please. Using the 5M chart i need to identify bar #12,#18,#23 to be painted yellow. With option to just set it to today or many days to back test what i'm seeing. Thanks for any help.
 
Solution
Need help with coding please. Using the 5M chart i need to identify bar #12,#18,#23 to be painted yellow. With option to just set it to today or many days to back test what i'm seeing. Thanks for any help.

bar numbers start counting at 1, on the left side of the chart.
this will color the 12th and 18th and 23rd bars on the chart, yellow.

Code:
input bar1 = 12;
input bar2 = 18;
input bar3 = 23;
AssignPriceColor(if (bar1 == barnumber() or bar2 == barnumber() or bar3 == barnumber() ) then color.yellow else color.current);
#
Need help with coding please. Using the 5M chart i need to identify bar #12,#18,#23 to be painted yellow. With option to just set it to today or many days to back test what i'm seeing. Thanks for any help.

bar numbers start counting at 1, on the left side of the chart.
this will color the 12th and 18th and 23rd bars on the chart, yellow.

Code:
input bar1 = 12;
input bar2 = 18;
input bar3 = 23;
AssignPriceColor(if (bar1 == barnumber() or bar2 == barnumber() or bar3 == barnumber() ) then color.yellow else color.current);
#
 
Solution

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

Need help with coding please. Using the 5M chart i need to identify bar #12,#18,#23 to be painted yellow. With option to just set it to today or many days to back test what i'm seeing. Thanks for any help.

i made my first study, in post#2, to be exactly as you worded your question.

but, i'm guessing that isn't what you wanted. i usually don't guess at what someone wants, but i had some ideas in my head so i made the following.
maybe it's closer to what you wanted or maybe someone else can use it.


based on you wanting to set something to many days, i had a feeling you wanted to have the bar count start over each day, and look for bar numbers 12,18,23 on every day ? for x number of 'days back' , from the current day.

--------------------------

find up to 6 bars, per each day. the bar count resets to 1, on the first bar of each day.
..defaults, 12,18,23. set number to 0 to disable it.
can pick how many days back from the current day, to look for bars.

a light blue warning label will pop up if,
..a bar number is more than the quantity of bars in a day (normal trading hours).
....the quantity of bars per day is displayed in the label.

..the days back number is more than the days on chart.
....the quantity of days on the chart is displayed in the label.


yes/no options:
..display some stats in labels
..change bar color to yellow
..draw arrows
..draw a hollow box around the bar
....make it a solid box
..display the number above the bar
..draw vertical lines, between each day


Ruby:
# colorxbars_0b

# https://usethinkscript.com/threads/identify-bar-12-18-23.10744/
# identify bar #12,#18,#23

def na = double.nan;
def bn = barnumber();

# ---------------------------------
input bar1 = 12;
input bar2 = 18;
input bar3 = 23;
input bar4 = 0;
input bar5 = 0;
input bar6 = 0;

# ---------------------------------
input chart_stat_labels = yes;
def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;
AddLabel(chart_stat_labels, "chartmin " + chartmin, Color.MAGENTA);
# 390min in a day
def daybarqty = roundup(390 / chartmin, 0);
AddLabel(chart_stat_labels, "bars per day " + daybarqty, Color.MAGENTA);
#---------------------------------

def maxbar = max(bar1, max(bar2, max(bar3, max(bar4, max(bar5, bar6)))));
def bartoobig = if (maxbar > daybarqty) then 1 else 0;
addlabel(bartoobig, "ONE OF THE BAR NUMBERS IS TOO BIG. should be <= " + daybarqty, color.cyan);

addlabel(chart_stat_labels, "Day bar numbers", color.yellow);

addlabel(chart_stat_labels and bar1 > 0, "Bar1 " + bar1, color.yellow);
addlabel(chart_stat_labels and bar2 > 0, "Bar2 " + bar2, color.yellow);
addlabel(chart_stat_labels and bar3 > 0, "Bar3 " + bar3, color.yellow);
addlabel(chart_stat_labels and bar4 > 0, "Bar4 " + bar4, color.yellow);
addlabel(chart_stat_labels and bar5 > 0, "Bar5 " + bar5, color.yellow);
addlabel(chart_stat_labels and bar6 > 0, "Bar6 " + bar6, color.yellow);

input change_bar_color = yes;

# -----------------------------------
# day count
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def newday = if getday() != getday()[1] then 1 else 0;
def daycnt = if bn == 1 then 1 else if (!isnan(close) and newday) then daycnt[1] + 1 else daycnt[1];
def maxdays = highestall(daycnt);
def revdaycnt = maxdays - daycnt + 1;

def daybarcnt = if bn == 1 or newday then 1 else daybarcnt[1] +1;

input days_back_from_lastbar = 1;
def daystoomany = if days_back_from_lastbar < 1 or days_back_from_lastbar > maxdays then 1 else 0;
addlabel(chart_stat_labels and daystoomany, " ONLY " + MAXDAYS + " DAYS ON CHART. enter a different number for days back", color.cyan);

addlabel(chart_stat_labels, "Days back " + days_back_from_lastbar, color.magenta);

def lastcls = if bn == 1 then na
  else if (!isnan(close) and isnan(close[-1])) then close
  else lastcls[1];

#------------------------------------------

def barz = if
(revdaycnt <= days_back_from_lastbar) and (
(bar1 == daybarcnt) or
(bar2 == daybarcnt) or
(bar3 == daybarcnt) or
(bar4 == daybarcnt) or
(bar5 == daybarcnt) or
(bar6 == daybarcnt)
 ) then 1 else 0;

AssignPriceColor(if change_bar_color and barz then color.yellow else color.current);

#--------------------------------------

input draw_arrows = yes;
def arrow_offset = 0.999;
plot z1 = if (!draw_arrows or !barz) then na
  else if !isnan(close) then low*arrow_offset
  else if istoday then lastcls
  else na;
 
# if (draw_arrows and barz) then low*arrow_offset else na;

z1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z1.SetDefaultColor(Color.cyan);
#  shape size , 1 to 5
z1.setlineweight(1);
z1.hidebubble();

#--------------------------------------

input draw_hollow_box_around_bar = no;
input solid_box = no;

def vertfac = 0.003;
def h = if (barz and draw_hollow_box_around_bar) then (high * (1+vertfac)) else na;
def l = if (barz and draw_hollow_box_around_bar) then (low * (1-vertfac)) else na;
def o = if (barz and solid_box) then h else if (barz and !solid_box) then l else na;
def c = if (barz and solid_box) then l else if (barz and !solid_box) then h else na;
AddChart(high = h, low = l, open = o, close = c, type = ChartType.CANDLE, growcolor = color.yellow);

#--------------------------------------

# show the barnumber above the bar
input display_bar_number = no;
plot z2 = if (display_bar_number and barz) then daybarcnt else na;
z2.SetPaintingStrategy(PaintingStrategy.values_above);
z2.SetDefaultColor(Color.white);
#z2.setlineweight(1);
z2.hidebubble();

#--------------------------------------

input draw_vertical_line_between_days = yes;
def vert = !isnan(close) and (revdaycnt <= days_back_from_lastbar) and draw_vertical_line_between_days and newday;
addverticalline( vert, "Day", color.cyan, Curve.MEDIUM_DASH);
#


look back 3 days from the last bar
pRGw8UQ.jpg



close up of 1 day
this shows 4 options,
vertical line between days,
yellow box outline,
arrows,
bar number above the bar
2dyHmWq.jpg



notice the blue arrow on the far right.
on the current day, the arrows will show up under all the desired bars,
even if the bar hasn't been drawn yet.
bgkXCtb.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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