OPEN-SOURCE SCRIPT

4H Range

Updated
This script visualizes certain key values based on a 4-hour timeframe of the selected market on the chart. These values include the High, Mid, and Low price levels during each 4-hour period.

These levels can be helpful to identify inside range price action, chop, and consolidation. They can sometimes act as pivots and can be a great reference for potential entries and exits if price continues to hold the same range.

Here's a step-by-step overview of what this indicator does:

1. Inputs: At the beginning of the script, users are allowed to customize some inputs:
Choose the color of lines and labels.
Decide whether to show labels on the chart.
Choose the size of labels ("tiny", "small", "normal", or "large").
Choose whether to display price values in labels.
Set the number of bars to offset the labels to the right.
Set a threshold for the number of ticks that triggers a new calculation of high, mid, and low values.
* Tick settings may need to be increased on equity charts as one tick is usually equal to one cent.
For example, if you want to clear the range when there is a close one point/one dollar above or below the range high/low then on ES
that would be 4 ticks but one whole point on AAPL would be 100 ticks. 100 ticks on an equity chart may or may not be ideal due to
different % change of 100 ticks might be too excessive depending on the price per share.
So be aware that user preferred thresholds can vary greatly depending on which chart you're using.

2. Retrieving Price Data: The script retrieves the high, low, and closing price for every 4-hour period for the current market.
The script also calculates the mid-price of each 4-hour period (the average of the high and low prices).

3. Line Drawing: At the start of the script (first run), it draws three lines (high, mid, and low) at the levels corresponding to the high,
mid, and low prices. Users can also change transparency settings on historical lines to view them. Default setting for historical lines
is for them to be hidden.

4. Updating Lines and Labels: For each subsequent 4-hour period, the script checks whether the close price of the period has gone
beyond a certain threshold (set by user input) above the previous high or below the previous low. If it has, the script deletes the
previous lines and labels, draws new lines at the new high, mid, and low levels, and creates new labels (if the user has opted to
show labels).

5. Displaying Values in the Data Window: In addition to the visual representation on the chart, the script also plots the high, mid, and
low prices. These plotted values appear in the Data Window of TradingView, allowing users to see the exact price levels even when
they're not directly labeled on the chart.

6. Updating Lines and Labels Position: At the end of each period, the script moves the lines and labels (if they're shown) to the right,
keeping them aligned with the current period.

Please note: This script operates based on a 4-hour timeframe, regardless of the timeframe selected on the chart. If a shorter timeframe is selected on the chart, the lines and labels will appear to extend across multiple bars because they represent 4-hour price levels. If a longer timeframe is selected, the lines and labels may not accurately represent high, mid, and low levels within that longer timeframe.
Release Notes
Updated script for users to select the preferred range timeframe to display. This will also allow you to add the script to a chart more than once to show multiple ranges together. You can color code different ranges as you please. I find the 4 hour and daily ranges combined to be helpful. Timeframes included are 5min, 15min, 30min, 240min (4 hour), Daily, Weekly, and Monthly.
Release Notes
Updated to allow for any timeframe. Also updated the settings and style options. All settings should be customizable now. Users can now extend the levels and labels further to the right if preferred.
Candlestick analysisfuturesmultitimeframePivot points and levelspriceactionrangeStocks

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?


Also on:

Disclaimer