OPEN-SOURCE SCRIPT

Key Levels (Open, Premarket, & Yesterday)

Updated
OVERVIEW
This indicator automatically identifies and draws recent high-probability support and resistance levels (recent key levels). Specifically, yesterdays highs / lows, premarket highs / lows, as well as yesterdays end of day Volume Weighted Average Price and trader specified Moving Average.

This is most useful on charts with intraday time frames (1 minute, 5 minute etc.) commonly used for day trading. This is not ideal for larger time frames (greater than 1 hour) commonly used for swing trading or identifying larger trends.

INPUTS
You can configure:
  • Line size, style, and colors
  • Label colors
  • Which key levels you want to see
  • Moving Average Parameters
  • Market Hours and Time Zone


DEV NOTES
This script illustrates:
  • A method for iterative management of more complex data objects (not just discrete values) with loops and arrays.
Release Notes
Minor cleanup.
Release Notes
• Refactored logic.
• Added "Near Open" premarket levels.
Release Notes
• Raised the line limit to the maximum allowed.
• Adjusted "Premarket" levels to reset at midnight. This is most useful for things like futures, where new sessions begin the evening prior. This change is unlikely to be noticed unless actively trading overnight.
Release Notes
• Added ability to set a line max length, if you do not want the lines stretching back to their origin. It is turned off by default.
• Improved "Premarket" level logic, where it will now stop updating near the open if "Near Open" levels are turned on, which should keep the premarket and near open levels from overlapping.
Release Notes
• Added ability to limit "Yesterdays Hi / Lo" to only the market hours. This is now on by default. Disabling the option will include Premarket and After Hours levels, if they exceed the levels during the market hours.
• Fixed bug where Yesterdays Hi / Lo would not reset properly if extended hours were not showing.
• Minor code cleanup.
Release Notes
• Added an "Opening Range" (off by default). You can specify the color and how many minutes into the first market hour qualifies as "the open".
• Minor improvements to level logic.
• Fixed a bug that truncated older levels, if the max line length was enabled.
Release Notes
• Fixed bug that broke the indicator when extended trading hours were not displayed on the chart and premarket levels or near open levels were enabled.
Release Notes
• A variety of smaller bug fixes and logic enhancements.
Release Notes
• Updated the default "Max Line Length" to be "15", which is the same default as the "Opening Range". This helps visually communicate when the opening range will stop adjusting. You still have the ability to override both the Max Line Length and Opening Range values.
Release Notes
Added Levels
• After Hours
• Overnight
• Custom

Added Price Proximity Features
• Line Length Override
• Toggle Visibility
• ATR Zones

Other Enhancements
• Refactored arrays for better variable and object management.
• Converted the market hours settings to be TV's session input (their standard time entry field).
• Logic adjustments and max_bar_back adjustments.
• Minor bug fixes.

- - -

All the new levels / features are off by default.

After Hours will capture the high / low after regular trading hours and before the session ends. If "Mkt Hrs Only" is disabled, and the sessions highs / lows occur during this time, "Yesterdays Hi / Lo" and "After Hours" levels will overlap. For this reason, if a After Hours level is identical to Yesterday, the After Hours level will be hidden.

Overnight will capture the high / low before midnight when a session begins after regular trading hours. Sessions beginning after trading hours is not a thing for most securities (thus will not show on most securities), but does occur for things like futures and crypto.

Custom have been added. You are able to set a specific level value in the settings, or drag the level up / down on the chart.

A feature previously introduced was an ability to give lines a maximum length. This truncation aims to help keep charts simple and clean. To this end, a follower suggested having truncated lines extend back to their origin when price was within it's proximity. To accomplish this, two Price Proximity settings are being introduced.

Range of Proximity ( % ) defines how close price needs to be for an enabled proximity settings to take effect. This is a percentage (not monetary) value. For example, how close price should be before a truncated line extends back to its origin.
Line Length Override will extend a line back to its origin, when price is proximal to a given line and "Max Line Length" is enabled.

Given the original intention of truncating lines (decluttering charts), and now having a method to detect price proximity, I extended the concept further.

Toggle Visibility will hide levels by default, and only show a level when price is proximal to a given line. Useful for those who only want to be reminded of an approaching while trading, but otherwise don't want to see it.

This price proximity work also spurred another idea. Price rarely interacts with a key level exactly. In practice they are more like zones, due to order execution variance, better known as volatility. Because the Average True Range (ATR) measures volatility, I decided to pair ATR with price proximity to get a better sense of a given levels area of opportunity.


ATR Zones will show a 5 bar ATR zone around the level, when price is proximal to a given line. Half the ATR is above the line, and half the ATR is below the line.

- - -

General Note
The intention of this indicator is to compliment your trading strategy. It is not intended to be a trading strategy in and of itself, but rather make something you are already doing more convenient. While turning everything on is unlikely to help you, enabling only the things that already have your attention makes chart contextualization so much faster. Happy trading.
Release Notes
Minor setting changes (ie. tooltips, groups, etc.)
Release Notes
• Visual cleanup of settings panel.
Release Notes
Added Levels
• Todays open
• Yesterdays open
• Yesterdays close
• Todays high & low
• This / last weeks high & low
• This / last months high & low
• This / last quarters high & low
• This / last years high & low
• Todays VWAP
• Todays Moving Average

Other Enhancements
• Label tooltips
• Label abbreviation controls
• Code refactor to better manage levels within a single UDT object array

Notes
While I have done my best to address all the edge-cases and bugs I could find, the magnitude of code refactoring required to implement these new levels cannot be overstated. It's possible I missed something, so if you discover any quirks, let me know and I'll get it fixed!
Release Notes
Added Levels
  • Distant level opens & closes (12 new levels)
  • Range averages for all major segments (10 new levels)
  • Second recent moving average (1 new level)


Other Enhancements
  • Added ability to configure the VWAP source
  • Improved accuracy of last market bar calculation
  • Added option to have label colors match the line color
  • Renamed "Mkt Hrs Only" to "RTH" to align with TradingViews terminology
  • Added "Mkt Hrs Only" (now "RTH") option to Todays / Yesterdays, Open / Close (Recent Single Values)
  • Changed "Mkt Hrs Only" (now "RTH") so disabling it aligns a given value with a 1D chart to avoid confusion when toggling between time frames (notably for futures)
  • Added one minute bar data to help make key levels more time frame agnostic
  • Minor changes to the settings panel
  • Added ability to control how many bars into the future a level will extend
  • Added ability to extend custom levels to the left
  • Custom Level 1 used to incorrectly show CL2 when enabled, now correctly shows CL1
  • Opening Range used to incorrectly show the first bars range if the charts time frame was higher than the specified opening range minutes, now correctly shows the opening range of the specified time
  • Constants are now used for script values that do not change, helping reduce computational overhead
  • Premarket levels now measure the highs / lows during the Overnight segment when Overnight levels are disabled
  • Added v.1 logic to merge labels when levels have the same rounded price value


Notes About Label Merging
There is currently no native way to keep labels from overlapping. The best I can do is concatenate text into a single label when they have the same rounded value. Ideally the script would be able to detect when to merge labels automatically based on the charts price scale. Unfortunately there is no way to get this value. This means you will need to set the merge threshold manually (available in the settings panel) to whatever works best for your chart. When TV provides a way to get the price scales increment, I'll update this feature.

Additionally, there is a known issue where labels intermittently fail to re-display when they separate. This is a rendering issue, not a script issue. TV is aware and the issue should go away when TV resolves the bug. As a temporary workaround, you can either do nothing (it might come back after another merge / separation cycle), or toggle the the merge setting off (allowing the script to fully re-render) and back on again.
Release Notes
  • Updated logic to work more consistently in Bar Replay.
  • Minor comment changes.
highlevelsLOWmoving_averagePivot points and levelspremarketresistencesupportSupport and Resistanceyesterday

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer