This code is a **ThinkScript** (used in the ThinkorSwim platform)...

August 26, 2025 at 01:22 PM

## # Tr3ndy PMZ - https://www.trendytrading.co/scripts/script-shop#PMZ # Copyright trendytrading.co, for information visit https://www.trendytrading.co/utilities/terms-conditions # @beezy # 2023 - Simpler Trading # http://www.simplertrading.com # *** Sharing and/or modification of this source code is expressly prohibited by the terms of your user agreement *** # Revision date: June 16,2023 ## input Premarket = {default "PRE", "ALL"}; #hint futures: Use premarket or All when calculating PMZ. input futures = no; #hint futures: Plot PMZ after hours on futures. input Banner = yes; #hint Banner: Show banner on chart for PMZ H/L and Risk. def period = if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN then AggregationPeriod.FIVE_MIN else GetAggregationPeriod(); def tclose = 1600; def topen = 930; def fut_close = 1800; def nt2 = 2355; def nt3 = 0000; def nt4 = 0930; def price = close(period = period); def h = high(period = period); def l = low(period = period); def c = close(period = period); def o = open(period = period); def cnull = if period <= AggregationPeriod.FIVE_MIN then 1555 else if period == AggregationPeriod.TEN_MIN then 1550 else if period == AggregationPeriod.FIFTEEN_MIN then 1545 else if period == AggregationPeriod.THIRTY_MIN then 1530 else if period == AggregationPeriod.HOUR then 1500 else 0; def pnull = if period <= AggregationPeriod.FIVE_MIN then 0725 else if period == AggregationPeriod.TEN_MIN then 0720 else if period == AggregationPeriod.FIFTEEN_MIN then 0715 else 0700; plot color = Double.NaN; color.Hide(); color.DefineColor("pbull", Color.CYAN); color.DefineColor("pbear", Color.RED); color.DefineColor("fbull", Color.GREEN); color.DefineColor("fbear", Color.YELLOW); def LIS = If(SecondsTillTime(tclose) == 0, price, LIS[1]); def otime = If(SecondsTillTime(topen) == 0, o, otime[1]); def nperiod; def nperiod1 = SecondsFromTime(nt2) <= 0 and SecondsFromTime(cnull) > 0; def nperiod2 = SecondsFromTime(nt3) >= 0 and SecondsFromTime(nt4) < 0; def fut_time = SecondsFromTime(cnull) > 0 and SecondsFromTime(fut_close) < 0; switch (Premarket) { case "ALL": nperiod = nperiod1 or nperiod2; case "PRE": nperiod = SecondsFromTime(pnull) > 0 and SecondsFromTime(nt4) < 0; } def pmh = if SecondsTillTime(cnull) == 0 then 0 else if nperiod then if pmh[1] > h then pmh[1] else h else pmh[1]; def pml = if SecondsTillTime(cnull) == 0 then 100000 else if nperiod then if pml[1] < l then pml[1] else l else pml[1]; def gap = if nperiod then if o < LIS then 0 else 1 else gap[1]; plot upper = if SecondsFromTime(0930) >= 0 and SecondsFromTime(cnull) < 0 then if gap then pmh - ((pmh - pml) * .2) else pml + ((pmh - pml) * .2) else Double.NaN; plot lower = if SecondsFromTime(0930) >= 0 and SecondsFromTime(cnull) < 0 then if gap then pmh - ((pmh - pml) * .4) else pml + ((pmh - pml) * .4) else Double.NaN; def ahh = if SecondsTillTime(cnull) == 0 then 0 else if fut_time then if ahh[1] > h then ahh[1] else h else ahh[1]; def ahl = if SecondsTillTime(cnull) == 0 then 100000 else if fut_time then if ahl[1] < l then ahl[1] else l else ahl[1]; def ah_set = if fut_time then if o < LIS then 0 else 1 else ah_set[1]; plot ah_upper = if futures and (nperiod1 or nperiod2) then if ah_set then ahh - ((ahh - ahl) * .2) else ahl + ((ahh - ahl) * .2) else Double.NaN; plot ahler = if futures and (nperiod1 or nperiod2) then if ah_set then ahh - ((ahh - ahl) * .4) else ahl + ((ahh - ahl) * .4) else Double.NaN; AddCloud(upper, lower, color.Color("pbull"), color.Color("pbear"), no); AddCloud(ah_upper, ahler, color.Color("fbull"), color.Color("fbear"), no); AddLabel(Banner, Concat("PMZ High: ", if SecondsFromTime(pnull) > 0 and SecondsFromTime(cnull) < 0 then if gap then pmh - ((pmh - pml) * .2) else pml + ((pmh - pml) * .4) else Double.NaN), Color.GREEN); AddLabel(Banner, Concat("PMZ Low: ", if SecondsFromTime(pnull) > 0 and SecondsFromTime(cnull) < 0 then if gap then pmh - ((pmh - pml) * .4) else pml + ((pmh - pml) * .2) else Double.NaN), Color.RED); AddLabel(Banner, Concat("Risk: ", if SecondsFromTime(pnull) > 0 and SecondsFromTime(cnull) < 0 then if gap then (pmh - ((pmh - pml) * .2)) - ( pmh - ((pmh - pml) * .4)) else (pml + ((pmh - pml) * .4)) - (pml + ((pmh - pml) * .2)) else Double.NaN) , Color.YELLOW); AddCloud(upper, lower, color.Color("pbull"), color.Color("pbear"), no); AddCloud(ah_upper, ahler, color.Color("fbull"), color.Color("fbear"), no);a = [1,2,3] b = [2,3,4] c = set(a) & set(b)

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:

  1. 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.
  2. Core Definitions

    • topen and tclose: 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), and c (close) are used to assess market behavior during different periods.
  3. 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 and pnull for pre-market sessions).
    • Adjusts calculations based on whether prices are above or below the "Last Important Support" (LIS) level.
  4. 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).
  5. 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.
  6. 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.
  7. 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.
  8. 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.

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