How to make a code that uses 1-hour time frame to start at the bottom of the hour?


  • Questions
  • Watch Lists
  • How to make a code that uses 1-hour time frame to start at the bottom of the hour?
Category:
0
0

I wrote a simple code for my watchlist to let me know if the current hour candle is green(Up), red(Down), or white(Neither), for only market hours (no pre/post market data). I’ve hid the “Extended-Hours Trading Session” on my hourly charts so the candle will start at the bottom of the hour, i.e. 9:30am, instead of 9:00am (which happens when premarket data is shown).

 

Here’s my code:

plot dir = if close > open then 1 else if open == close then 0 else -1;

AddLabel(yes, if dir == 1 then “G” else if dir == 0 then “U” else “R”, if dir == 1 then Color.black else Color.white);

AssignBackgroundColor(if dir == 1 then Color.green else if dir == 0 then Color.white else color.red);

 

I made sure that the “Include Extended-Hours Trading Session” checkbox was unchecked. Whenever I look at my watchlist, the color inconsistently matches the hourly bar. When I allow my hourly charts to show premarket data, the codes matches it perfectly, but that’s not what I want. I need this code to match the candles that are at the bottom f the hour, not the top.

 

Thank you in advance for your assistance.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on December 26, 2018 12:38 pm
1306 views
0
Private answer

Short answer, not possible. All the tools in Thinkorswim (except charts) are fixed to only use candles that begin at the top of the hour. It is impossible to force them (through code modifications) to start at the bottom of the hour (unless you select extended hours).

Edit: To be clear, it is simply not possible at this time. Not even if you select extended hours. The only way this will become possible is if/when Thinkorswim developers add the option to start aggregation at market open for the rest of the platform tools. This setting currently only exists for charts. Thinkorswim developers would have to add this as a setting for Study Alerts, Conditional Orders, Watchlists and Study Filters. Until that time, it is completely impossible.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on December 26, 2018 6:46 pm
0

Thank you for your quick response. I really enjoy your site and I have learned a lot through your videos and reading numerous questions and answers here. You are a godsend for Thinkscript.

( at December 26, 2018 7:12 pm)
0
Hi. Where do you enter this code to get the hourly candle to begin at the bottom of the hour?
( at September 2, 2019 8:42 am)
0
Did you read the answer to this question? The part where it says that this is not possible?
( at September 2, 2019 12:53 pm)
0
Of course I did - I also read the end part that said (unless you select extended hours), which i would select in order to get the result.
( at September 2, 2019 6:54 pm)
0
That is a chart setting. When you check that box to turn on extended hours for the chart, you will notice the option to start aggregation at market open is disabled. Perhaps I need to change the wording of my answer.
( at September 2, 2019 8:33 pm)