Examples of isolating/showing time?

melfice_187

New member
I'm new to thinkscript. I have experience mostly in C# and a tiny bit in javascript.

The hard parts of thinkscript have been some of the parts of javascript that plagued me, isolating time. Are there a few examples or links to other posts with good examples of say isloating a specific 30 minutes of premarket or intraday and converting it to proper time with labels? I hope my question makes sense. Thanks all so much for the awesome work, I immediately upgraded my account as soon as I found this place. Love the community here!
 
Solution
If I understand you, @magus, you're looking to plot just the cumulative regular-trading-hours volume?

Code:
def rth = if secondsFromTime(0930) >= 0 and secondsTillTime(1600) >= 0 then 1 else 0;
def cumulative_rth_volume = if rth then cumulative_rth_volume[1] + VOLUME else 0;
plot cum_rth_vol = cumulative_rth_volume;

You can adjust times as you want, 24hour format, east coast time. If I missed the mark on what you're trying to do, just let me know.

-mashume

P.S. This may or may not be quite right... I'm just typing in the text editor, not ToS.
Here is a more specific use case example:
Using the example from the documentation, I can plot volume just in the premarket or I can tweak it to start plotting volume in the premarket and cut off before after market hours. But what if I want to just show intraday? Cut off premarket and aftermarket on the plot.

Code:
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];

def beforeStart = GetTime() < RegularTradingEnd(GetYYYYMMDD());

def vol = if isRollover and beforeStart then volume else if beforeStart then vol[1] + volume else Double.NaN;

plot PreMarketVolume = vol;


28BbLxp.png
 
@magus Without testing I'm pretty sure you could control the visibility through conditional look and feel formatting for the plot itself... For example, conditional PreMarketVolume.SetDefaultColor( . . . . ) based on your time criteria... Or plotting based on that same criteria... Maybe something like plot PreMarketVolume = if isRollover and beforeStart then vol else Double.NaN;... 💡
 
Thanks for the answer! I have a few other use cases for this which is why I’m trying to learn some time patterns.
I would like to see the cumulative volume intraday without having to turn off extended hours in the chart.
 
Yeah, I'm trying to play with everything I can right now. Thank you also for responding and sending me over a few names. I can at least browse through all your collective posts since searching for specific things can be a challenge in the forum.
 
If I understand you, @magus, you're looking to plot just the cumulative regular-trading-hours volume?

Code:
def rth = if secondsFromTime(0930) >= 0 and secondsTillTime(1600) >= 0 then 1 else 0;
def cumulative_rth_volume = if rth then cumulative_rth_volume[1] + VOLUME else 0;
plot cum_rth_vol = cumulative_rth_volume;

You can adjust times as you want, 24hour format, east coast time. If I missed the mark on what you're trying to do, just let me know.

-mashume

P.S. This may or may not be quite right... I'm just typing in the text editor, not ToS.
 
Solution
@mashume Thanks a bunch for this pattern. This is good for me to understand, I had achieved a similar result checking GetTime() against RegularTradingStart/RegularTradingEnd but I thought there might have been an error because the plot line would go straight down to zero instead of masking. Now I know why, because your "0" and my double.nan both equal zero.

The other thing that was giving me an issue is that when I applied this to making a label with volume I would get "0". I now know this is because it's checking live data and in order for me to look at a historical stock, I need to use another time frame function like "AggregrationPeriod" or set demand to the last bar before market close with the example you gave above.

Manipulating time for data is so confusing with thinkscript. I wish I could just loop through days and find exactly what I'm looking for. Thanks again, sorry for the rant, this how I learn :)
 
@mashume Thanks a bunch for this pattern. This is good for me to understand, I had achieved a similar result checking GetTime() against RegularTradingStart/RegularTradingEnd but I thought there might have been an error because the plot line would go straight down to zero instead of masking. Now I know why, because your "0" and my double.nan both equal zero.

The other thing that was giving me an issue is that when I applied this to making a label with volume I would get "0". I now know this is because it's checking live data and in order for me to look at a historical stock, I need to use another time frame function like "AggregrationPeriod" or set demand to the last bar before market close with the example you gave above.

Manipulating time for data is so confusing with thinkscript. I wish I could just loop through days and find exactly what I'm looking for. Thanks again, sorry for the rant, this how I learn :)
Cool. Glad to be able to help. Part of the fun of thinkscript is that, while the language loops over the chart, it is largely a functional programming paradigm. Once you start thinking about it in those terms, it all makes a whole lot more sense.

-mashume
 
how would I scan for
close is greater than LegacyEMA("length" = 8);
only within the first 1 minute of every day? thanks
You can't mix aggregation periods in a scanner. So. If you want to see what's above the 8 day ema, you could use something like OPEN > LegacyEMA("length" = 8). If you really want the first minute, you'll need to figure out your ema on a minute basis to match.

-mashume
 
@mashume This isn't an aggregation issue, it's just watching the time and seeing whether the price, which would be high, closes, goes above the average... So it's a matter of time, not aggregation...
 

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