Vertical Time Lines

TraderMD

New member
VIP
Hello All, I have some knowledge of Thinkscript (enough to be dangerous ), but I am having a mental block on adding vertical lines to a chart from a specific starting point. What I am interested in achieving is from a specific starting point (ie Oct 13, 2022 - SPX low) placing a vertical line every 59 bars into the future. I am working on "Price and Time" moves (ie taking the square root of the low 3491 or 59) and marking every 59 bars in the future.

Code:
AddVerticalLine(SecondsFromTime(0930)==0,"Open",Color.Gray,Curve.SHORT_DASH);

I have tried adding different barcount calculations to the "SecondsFromTime(0930)==0" without success :( I assume there is an easy solution but am blanking. Any help would be greatly appreciated.
 
Hello All, I have some knowledge of Thinkscript (enough to be dangerous ), but I am having a mental block on adding vertical lines to a chart from a specific starting point. What I am interested in achieving is from a specific starting point (ie Oct 13, 2022 - SPX low) placing a vertical line every 59 bars into the future. I am working on "Price and Time" moves (ie taking the square root of the low 3491 or 59) and marking every 59 bars in the future.

Code:
AddVerticalLine(SecondsFromTime(0930)==0,"Open",Color.Gray,Curve.SHORT_DASH);

I have tried adding different barcount calculations to the "SecondsFromTime(0930)==0" without success :( I assume there is an easy solution but am blanking. Any help would be greatly appreciated.
I'm not sure if this is exactly what you are looking for but here is something that will start at a specified time and print a vertical line every 60 bars (ie. 10:30, 11:30, 12:30 and so on for a 1m chart). It stops printing those lines at a specified time as well. Let me know how the square root stuff goes - it is very interesting.

Ruby:
input startTime = 0930;
input endTime = 1600;
input barCount = 60;
def isStart = SecondsFromTime(startTime)==0;
def RTH = SecondsFromTime(startTime)>=0 and SecondsTillTime(endTime) >= 0;
AddVerticalLine(isStart,"Open",Color.Gray,Curve.SHORT_DASH);

def count = if isStart then 0 else count[1] + 1;
def drawLine = count % barCount == 0;
AddVerticalLine(RTH and !isStart and drawLine,"Next Bar",Color.Gray,Curve.SHORT_DASH);
 
I'm not sure if this is exactly what you are looking for but here is something that will start at a specified time and print a vertical line every 60 bars (ie. 10:30, 11:30, 12:30 and so on for a 1m chart). It stops printing those lines at a specified time as well. Let me know how the square root stuff goes - it is very interesting.

Ruby:
input startTime = 0930;
input endTime = 1600;
input barCount = 60;
def isStart = SecondsFromTime(startTime)==0;
def RTH = SecondsFromTime(startTime)>=0 and SecondsTillTime(endTime) >= 0;
AddVerticalLine(isStart,"Open",Color.Gray,Curve.SHORT_DASH);

def count = if isStart then 0 else count[1] + 1;
def drawLine = count % barCount == 0;
AddVerticalLine(RTH and !isStart and drawLine,"Next Bar",Color.Gray,Curve.SHORT_DASH);
Hi FutureTony, thank you very much, above works great, now if we can figure out a way to not only set a time to start but also a date. But the above gives me something to work with, will keep you updated. Below is setting the start time to high at 1312 CST today. Need to figure out how to send a pic :)
 
I believe I am close but can't figure out what thinkscript function will perform the python Mod function. The below thinkscript produces and error in line 7 for the Mod function ?

Code:
input start_date = 20221013;
input bars_forward = 1;
input repeat_interval = 60;

def bars_since_start = if BarNumber() == 1 then 0 else if GetYYYYMMDD() >= start_date then BarNumber() - HighestAll(if GetYYYYMMDD() >= start_date then BarNumber() else 0) else Double.NaN;

def bars_until_repeat = repeat_interval - Mod(bars_since_start, repeat_interval);

plot line = if bars_until_repeat <= bars_forward and !IsNaN(bars_since_start) then high else Double.NaN;
line.SetStyle(curve.Short_DASH);
line.SetDefaultColor(Color.CYAN);
 
I believe I am close but can't figure out what thinkscript function will perform the python Mod function. The below thinkscript produces and error in line 7 for the Mod function ?

Code:
input start_date = 20221013;
input bars_forward = 1;
input repeat_interval = 60;

def bars_since_start = if BarNumber() == 1 then 0 else if GetYYYYMMDD() >= start_date then BarNumber() - HighestAll(if GetYYYYMMDD() >= start_date then BarNumber() else 0) else Double.NaN;

def bars_until_repeat = repeat_interval - Mod(bars_since_start, repeat_interval);

plot line = if bars_until_repeat <= bars_forward and !IsNaN(bars_since_start) then high else Double.NaN;
line.SetStyle(curve.Short_DASH);
line.SetDefaultColor(Color.CYAN);

mod , is % symbol
look at this line in post2,
def drawLine = count % barCount == 0;

when the remainder of count/ barcount = 0 , then true.

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

next time, don't type out a function and hope it exists. try looking it up.
( fyi, i tried, but couldn't remember which section mod was under , so i had to google it...
google.com thinkscript mod % )


math
operators - Arithmetic

mod
%
https://tlc.thinkorswim.com/center/reference/thinkScript/Operators/Arithmetic

https://tlc.thinkorswim.com/center/reference/thinkScript/Operators


math functions
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig
 
Last edited:

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