ThinkScript for Cycle Brackets

Picard

Member
I'm looking for a way to code an indicator for equal cycles like the built in indicator called "Cycle Brackets" that I can start at a specific date. Even though this is a built-in indicator, I would like to do this with ThinkScript or any other way to indicate equal cycles.

6NuowD2.png
 
Last edited by a moderator:
Unfortunately, TOS does not have any Thinkscript Functions that would allow automated drawing of anything but straight lines... Your only option is the manual Chart Drawing Tools you are currently using...
 

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

Unfortunately, TOS does not have any Thinkscript Functions that would allow automated drawing of anything but straight lines... Your only option is the manual Chart Drawing Tools you are currently using...
is there a way to have TOS provide a counter that indicates the number of bars /days/weeks in the cycles it is drawing?
 
Follow up question this. I can configure the Cycle brackets to show vertical lines at 9 period intervals. However, it does not stay saved. As soon as I pull up a different ticker, the drawing goes away. I tried to save the study and the style with the cycle brackets, but am missing something. I'd like this to become part of my study set so I don't have to configure the darn things again and again. What am I missing?

Clarification: The drawing stays with the ticker, so if I return back to that same ticker, the cycle brackets show fine.

Perhaps, the cycle brackets is not the way to go. So looking for a simple way to draw vertical lines at m y defined interval and be able to choose style and color of line
 
So after researching vertical lines, ToS has this simple default code

Code:
input period = {WEEK, default MONTH};
AddVerticalLine((period == period.WEEK and GetWeek() <> GetWeek()[1]) or (period == period.MONTH and GetMonth() <> GetMonth()[1]), "", Color.ORANGE, curve.SHORT_DASH);

If someone can help me update this to include:
  • Specific period lines in days (example 9 days)
  • ability to change color and line type

UPDATE:
Using the DAYS option was causing all sorts of issues, so I have decided to go with periods. That actually works well for me
Here's the code I'm using.

Code:
input periods = 9;
AddVerticalLine(BarNumber() % periods == 0, "", Color.Violet, curve.SHORT_DASH);

Can someone help me add options so the color and line style is user configurable?
 
Last edited by a moderator:
So after researching vertical lines, ToS has this simple default code

Code:
input period = {WEEK, default MONTH};
AddVerticalLine((period == period.WEEK and GetWeek() <> GetWeek()[1]) or (period == period.MONTH and GetMonth() <> GetMonth()[1]), "", Color.ORANGE, curve.SHORT_DASH);

If someone can help me update this to include:
  • Specific period lines in days (example 9 days)
  • ability to change color and line type

UPDATE:
Using the DAYS option was causing all sorts of issues, so I have decided to go with periods. That actually works well for me
Here's the code I'm using.

Code:
input periods = 9;
AddVerticalLine(BarNumber() % periods == 0, "", Color.Violet, curve.SHORT_DASH);

Can someone help me add options so the color and line style is user configurable?


draw repeating vertical lines, based on some time period
. based on a chosen time: day , week, month
. and a quantity to skip: 1+

example,
day 6 , draws a vertical line at the start of every 6th day

can pick a color, based on getcolor , 10 choices

can pick the line type, although it doesn't work perfectly. can pick a couple types. zooming may affect what is seen.


Code:
# cycles_periods_lines_01

#https://usethinkscript.com/threads/thinkscript-for-cycle-brackets.4891/#post-119704

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

# valid price ?  price enable
def pr_en = !isnan(close);

def d = getday();
def w = getweek();
def m = getmonth();

def daycurrent = d == getlastday();

def daynew = d != d[1];
def weeknew = w != w[1];
def monthnew = m != m[1];

# period counts, used by % formulas
def daycnt = if bn == 1 then 1
 else if daynew then daycnt[1] + 1
 else daycnt[1];

def weekcnt = if bn == 1 then 1
 else if weeknew then weekcnt[1] + 1
 else weekcnt[1];

def monthcnt = if bn == 1 then 1
 else if monthnew then monthcnt[1] + 1
 else monthcnt[1];

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

input period = {default Day, Week,  Month };
input qty = 3;

#def charttime = GetAggregationPeriod();
#def en = if period >= charttime then 1 else 0;

#----------------------------
#  pick color
# https://usethinkscript.com/threads/format-watchlist-text-in-thinkorswim.4045/page-3#post-67014
#  this doesn't assign the color in quotes.
#  the location of the picked color in the series, is changed to a number
#   ex. pink is the 3rd number.  3 is saved in color1_choice
input Color1_choice = {default "magenta", "cyan", "pink", "gray", "orange", "red", "green", "dark_gray", "yellow", "white"};

#AddLabel(yes, "test1 " + Color1_choice , GetColor(Color1_Choice));
#---------------------------

input line_type = {default LINE, dashes, POINTS};


addlabel(1, "  ", color.black);
addlabel(1, qty, color.yellow);
addlabel(1, period, color.yellow);
addlabel(1, "  ", color.black);


# getday is a day # that includes weekends...  so doesn't work for this
#def xd = (d % qty) == 0; 

#def xd = if qty == 1 then 1 else ((daycnt % qty) == 0);
def xd = ((daycnt % qty) == 0);
def xw = ((weekcnt % qty) == 0);
def xm = ((monthcnt % qty) == 0);

def xd2 = if qty == 1 then daynew else (!xd[1] and xd);
def xw2 = if qty == 1 then weeknew else (!xw[1] and xw);
def xm2 = if qty == 1 then monthnew else (!xm[1] and xm);

def x = if period == period.day then xd2
 else if period == period.week then xw2
 else if period == period.month then xm2
 else 0;

def p = pr_en and x;

AddVerticalLine(p, "-", GetColor(Color1_Choice),
(if line_type == line_type.POINTS then PaintingStrategy.POINTS
 else if line_type == line_type.dashes then PaintingStrategy.dashes
 else PaintingStrategy.LINE));



#--------------------------
# test stuff


input test1 = no;
addchartbubble(test1, low,
daycnt + "\n" +
xd + "\n" +
weekcnt + "\n" +
xw + "\n" +
monthcnt + "\n" +
xm + "\n" 
, color.yellow, no);


# change plot type , kind of works
#input line_type = {default LINE, dashes, POINTS};
#input test3 = no;
#addverticalline(test3 and daycurrent, "z", color.white, 
#(if line_type == line_type.POINTS then PaintingStrategy.POINTS
# else if line_type == line_type.dashes then PaintingStrategy.dashes
# else PaintingStrategy.LINE));


# https://usethinkscript.com/threads/create-a-horizontal-drawing-then-remove-it-once-price-hits-it.5257/#post-75706
# comments at end of study, regarding choosing a painting type
#
# paint a line , choose type 
#input lines = {default LINE, POINTS};
#def paint = if lines == lines.POINTS then PaintingStrategy.POINTS else  PaintingStrategy.LINE;
# plot x1 = 
#x1.SetPaintingStrategy(paint);

#

17NzmZC.jpg

hal_period


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


in the comments, at the end of this study, are notes about picking a line type
https://usethinkscript.com/threads/...remove-it-once-price-hits-it.5257/#post-75706


3 links on drawing arcs and lines
one link is about drawing ovals. the oval code could be modified and added to this, to draw half circles
https://usethinkscript.com/threads/drawing-cones-ovals-arcs-in-thinkorswim.12839/#post-109233


https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/PaintingStrategy
it is possible to use a number for a painting strategy, when plotting a line.
it may or may not help in picking a type in this study
x.SetPaintingStrategy(6);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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