This code is a **ThinkScript** (used in the ThinkorSwim platform)...
August 26, 2025 at 01:22 PM
This code is a ThinkScript (used in the ThinkorSwim platform) designed to calculate and visually display the Pre-Market Zone (PMZ) on a trading chart for analysis. Here's an explanation of what the different pieces of the code do:
-
Inputs
Premarket
: Allows users to toggle between "PRE" (only pre-market) or "ALL" (regular + pre-market) trading hours for PMZ calculation.futures
: A boolean input to determine whether the PMZ should include futures trading data after hours.Banner
: A flag to enable or disable visual labels on the chart.
-
Core Definitions
topen
andtclose
: Define market open and close times (9:30 AM and 4:00 PM, respectively).- Constants like
fut_close
,nt2
,nt3
,nt4
deal with futures hours and other session time boundaries. - Aggregated data like
price
,h
(high),l
(low),o
(open), andc
(close) are used to assess market behavior during different periods.
-
PMZ Logic
- Computes Pre-Market Zone High (pmh) and Low (pml) based on the highest and lowest prices during pre-market trading (or other configurations, depending on user input).
- Incorporates logic to reset highs/lows when a new trading session starts (
cnull
for regular sessions andpnull
for pre-market sessions). - Adjusts calculations based on whether prices are above or below the "Last Important Support" (
LIS
) level.
-
Gap Detection
- Determines whether there is a gap up or down in the market based on the opening price relative to the prior support level (
gap
variable).
- Determines whether there is a gap up or down in the market based on the opening price relative to the prior support level (
-
Plotting Zones
- Draws two primary levels: Upper Bound (
upper
) and Lower Bound (lower
) for the PMZ. - Extends these levels for after-hours trading when applicable (
ah_upper
,ahler
). - Zones are visualized graphically through colored clouds:
- "pbull" (bullish pre-market zone).
- "pbear" (bearish pre-market zone).
- "fbull", "fbear" for after-hours.
- Draws two primary levels: Upper Bound (
-
Chart Labels
- Adds visual labels (if
Banner
is enabled) to display:- PMZ High (upper zone boundary).
- PMZ Low (lower zone boundary).
- Risk, which is essentially the difference between the upper and lower PMZ levels.
- Adds visual labels (if
-
AddCloud
- Adds overlapping color-shaded zones to the chart for the computed upper and lower boundaries of both the PMZ and after-hours trading zones.
-
Purpose
- This code is used by traders to:
- Identify the key support and resistance levels established during the pre-market trading session.
- Visualize potential trade setups based on the gaps and risk levels derived from the PMZ.
- Recognize potential areas of price consolidation or breakout.
- This code is used by traders to:
At the end of the script, there's a Python snippet (a = [1, 2, 3]
, b = [2, 3, 4]
, c = set(a) & set(b)
), which calculates the intersection (c
) of two lists (a
and b
) using set operations. This is unrelated to the ThinkScript functionality above and would return {2, 3}
when executed in Python.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node