Trade Wzrd Null Range for ThinkOrSwim

chewie76

Well-known member
VIP
VIP Enthusiast
This is a simplified conversion of the Trade Wzrd Null Range indicator. Additional Watchlist Column code and lower indicator code are below.

This is a good reversion to the mean (centerline) indicator. The outside bands are extension zones where price will have a good probability of reverting back to the center line. This picture is a 5 minute chart of /NQ. Notice every time price is in the extension zones, it reverted back to the mean. It doesn't always revert back. It may stay extended for awhile. But, it'll always eventually get back to center.

Original concept: https://www.tradingview.com/script/P9cPymVG-Trade-Wzrd-Null-Range-Rampage-Series/

1789675282126.png




Code:
# ============================================================================
# Trade Wzrd - Null Range
# Original Code:  https://www.tradingview.com/script/P9cPymVG-Trade-Wzrd-Null-Range-Rampage-Series/
# Converted by Chewie 8/9/2026
# ============================================================================

declare upper;

# ============================================================================
# INPUTS
# ============================================================================

input colorbar           = yes;
input RangeLookback      = 200;
input OuterWallSigma0    = 1.5;
input OuterWallSigma     = 2.0;
input OuterWallSigma2    = 2.5;
input ShowWalls          = yes;
input ShowNullRange      = yes;


# --- Style Colors ---
DefineGlobalColor("Premium",  CreateColor(255, 61, 113));
DefineGlobalColor("Discount", CreateColor(0, 225, 255));
DefineGlobalColor("EQSolid",  CreateColor(178, 181, 190));

# ============================================================================
# CORE STRUCTURE
# ============================================================================

def res    = Highest(high, RangeLookback);
def sup    = Lowest(low,   RangeLookback);
def chanOK = !IsNaN(res) and !IsNaN(sup) and res > sup;

# ============================================================================
# NULL RANGE
# ============================================================================

def volSum  = fold i = 0 to RangeLookback with s  = 0 do s  + GetValue(volume, i);
def vwapNum = fold j = 0 to RangeLookback with sv = 0 do sv + GetValue(volume, j) * GetValue(close, j);
def rawVWAP = if volSum > 0 then vwapNum / volSum else (res + sup) / 2;

def varNum  = fold k = 0 to RangeLookback with sv2 = 0 do
    sv2 + GetValue(volume, k) * Power(GetValue(close, k) - rawVWAP, 2);
def sigV    = if volSum > 0 then Sqrt(varNum / volSum) else (res - sup) / 4;

def rangeMid  = (res + sup) / 2;
def rangeSpan = res - sup;
def eqV       = if chanOK then rawVWAP else (res + sup) / 2;

# ============================================================================
# CHANNEL WALLS
# ============================================================================

def up1 = if chanOK then eqV + sigV * OuterWallSigma0 else Double.NaN;
def lo1 = if chanOK then eqV - sigV * OuterWallSigma0 else Double.NaN;
def up2 = if chanOK then eqV + sigV * OuterWallSigma  else Double.NaN;
def lo2 = if chanOK then eqV - sigV * OuterWallSigma  else Double.NaN;
def up3 = if chanOK then eqV + sigV * OuterWallSigma2 else Double.NaN;
def lo3 = if chanOK then eqV - sigV * OuterWallSigma2 else Double.NaN;

# ============================================================================
# PLOTS
# ============================================================================

plot NullRangeLine = if ShowNullRange and chanOK then eqV else Double.NaN;
NullRangeLine.SetLineWeight(3);
NullRangeLine.setdefaultColor(color.GRAY);

plot UpperWall0 = if ShowWalls and chanOK then up1 else Double.NaN;
UpperWall0.SetDefaultColor(GlobalColor("Premium"));
UpperWall0.SetLineWeight(2);

plot LowerWall0 = if ShowWalls and chanOK then lo1 else Double.NaN;
LowerWall0.SetDefaultColor(GlobalColor("Discount"));
LowerWall0.SetLineWeight(2);

plot UpperWall = if ShowWalls and chanOK then up2 else Double.NaN;
UpperWall.SetDefaultColor(GlobalColor("Premium"));
UpperWall.SetLineWeight(2);

plot LowerWall = if ShowWalls and chanOK then lo2 else Double.NaN;
LowerWall.SetDefaultColor(GlobalColor("Discount"));
LowerWall.SetLineWeight(2);

plot UpperWall2 = if ShowWalls and chanOK then up3 else Double.NaN;
UpperWall2.SetDefaultColor(GlobalColor("Premium"));
UpperWall2.SetLineWeight(2);

plot LowerWall2 = if ShowWalls and chanOK then lo3 else Double.NaN;
LowerWall2.SetDefaultColor(GlobalColor("Discount"));
LowerWall2.SetLineWeight(2);

AssignPriceColor(if !colorbar then Color.CURRENT else if high > UpperWall then Color.MAGENTA else if high > UpperWall0 then Color.RED else if low < LowerWall then Color.CYAN else if low < LowerWall0 then Color.GREEN else Color.GRAY);

AddCloud(UpperWall0, UpperWall,    CreateColor(255, 70, 123), CreateColor(255, 70, 123));
AddCloud(UpperWall0,  NullRangeLine, CreateColor(155, 10, 23), CreateColor(155, 10, 23));
AddCloud(NullRangeLine, LowerWall0,  CreateColor(0, 120, 90),  CreateColor(0, 120, 90));
AddCloud(LowerWall0, LowerWall,    CreateColor(30, 245, 225),  CreateColor(30, 245, 225));


Watchlist Column Code:
Code:
# ============================================================================
# Trade Wzrd - Null Range Watchlist Column
# Original Code:  https://www.tradingview.com/script/P9cPymVG-Trade-Wzrd-Null-Range-Rampage-Series/
# Converted by Chewie 8/9/2026
# ============================================================================

declare upper;

# ============================================================================
# INPUTS
# ============================================================================

input RangeLookback      = 200;
input OuterWallSigma0    = 1.5;
input OuterWallSigma     = 2.0;
input OuterWallSigma2    = 2.5;
input ShowWalls          = yes;
input ShowNullRange      = yes;

# ============================================================================
# CORE STRUCTURE
# ============================================================================

def res    = Highest(high, RangeLookback);
def sup    = Lowest(low,   RangeLookback);
def chanOK = !IsNaN(res) and !IsNaN(sup) and res > sup;

# ============================================================================
# NULL RANGE
# ============================================================================

def volSum  = fold i = 0 to RangeLookback with s  = 0 do s  + GetValue(volume, i);
def vwapNum = fold j = 0 to RangeLookback with sv = 0 do sv + GetValue(volume, j) * GetValue(close, j);
def rawVWAP = if volSum > 0 then vwapNum / volSum else (res + sup) / 2;

def varNum  = fold k = 0 to RangeLookback with sv2 = 0 do
    sv2 + GetValue(volume, k) * Power(GetValue(close, k) - rawVWAP, 2);
def sigV    = if volSum > 0 then Sqrt(varNum / volSum) else (res - sup) / 4;

def rangeMid  = (res + sup) / 2;
def rangeSpan = res - sup;
def eqV       = if chanOK then rawVWAP else (res + sup) / 2;

# ============================================================================
# CHANNEL WALLS
# ============================================================================

def up1 = if chanOK then eqV + sigV * OuterWallSigma0 else Double.NaN;
def lo1 = if chanOK then eqV - sigV * OuterWallSigma0 else Double.NaN;
def up2 = if chanOK then eqV + sigV * OuterWallSigma  else Double.NaN;
def lo2 = if chanOK then eqV - sigV * OuterWallSigma  else Double.NaN;
def up3 = if chanOK then eqV + sigV * OuterWallSigma2 else Double.NaN;
def lo3 = if chanOK then eqV - sigV * OuterWallSigma2 else Double.NaN;

# ============================================================================
# PLOTS
# ============================================================================

plot NullRangeLine = if ShowNullRange and chanOK then eqV else Double.NaN;
NullRangeLine.SetLineWeight(3);
NullRangeLine.setdefaultColor(color.GRAY);

plot UpperWall0 = if ShowWalls and chanOK then up1 else Double.NaN;
UpperWall0.SetDefaultColor(GlobalColor("Premium"));
UpperWall0.SetLineWeight(2);

plot LowerWall0 = if ShowWalls and chanOK then lo1 else Double.NaN;
LowerWall0.SetDefaultColor(GlobalColor("Discount"));
LowerWall0.SetLineWeight(2);

plot UpperWall = if ShowWalls and chanOK then up2 else Double.NaN;
UpperWall.SetDefaultColor(GlobalColor("Premium"));
UpperWall.SetLineWeight(2);

plot LowerWall = if ShowWalls and chanOK then lo2 else Double.NaN;
LowerWall.SetDefaultColor(GlobalColor("Discount"));
LowerWall.SetLineWeight(2);

plot UpperWall2 = if ShowWalls and chanOK then up3 else Double.NaN;
UpperWall2.SetDefaultColor(GlobalColor("Premium"));
UpperWall2.SetLineWeight(2);

plot LowerWall2 = if ShowWalls and chanOK then lo3 else Double.NaN;
LowerWall2.SetDefaultColor(GlobalColor("Discount"));
LowerWall2.SetLineWeight(2);


plot XBUY = low < Lowerwall;
plot XSELL =  high > UpperWall;
plot BUY = low < Lowerwall0;
plot SELL =  high > UpperWall0;

AddLabel(yes, if XBUY then "XBUY" else if XSELL then "XSELL" else if sell then "SELL" else if buy then "BUY"  else " ", if XBUY then color.BLACK else if XSELL then color.BLACK else if sell then color.yellow else if buy then color.dark_green else Color.BLACK);

AssignBACKGROUNDColor(if XBUY then color.cyan else if Xsell then color.MAGENTA else if buy then color.GREEN else if sell then color.red else color.black);

Lower Oscillator code:

Code:
# ============================================================================
# Trade Wzrd - Null Range Oscillator
# Based on Trade Wzrd - Null Range
# Original Code:  https://www.tradingview.com/script/P9cPymVG-Trade-Wzrd-Null-Range-Rampage-Series/
# Converted by Chewie 8/9/2026
# Oscillator version by Chewie 9/17/2026
# ============================================================================

declare lower;

# ============================================================================
# INPUTS
# ============================================================================

input RangeLookback   = 200;
input OuterWallSigma0 = 1.5;
input OuterWallSigma  = 2.0;
input OuterWallSigma2 = 2.5;

# --- Style Colors ---
DefineGlobalColor("Premium",  CreateColor(255, 61, 113));
DefineGlobalColor("Discount", CreateColor(0, 225, 255));
DefineGlobalColor("EQSolid",  CreateColor(178, 181, 190));
DefineGlobalColor("UpperZone", CreateColor(255, 70, 123));
DefineGlobalColor("LowerZone", CreateColor(0, 120, 90));
DefineGlobalColor("UpperOuter", CreateColor(155, 10, 23));
DefineGlobalColor("LowerOuter", CreateColor(30, 245, 225));

# ============================================================================
# CORE STRUCTURE
# ============================================================================

def res    = Highest(high, RangeLookback);
def sup    = Lowest(low,   RangeLookback);
def chanOK = !IsNaN(res) and !IsNaN(sup) and res > sup;

# ============================================================================
# NULL RANGE MATH - identical to overlay
# ============================================================================

def volSum  = fold i = 0 to RangeLookback with s  = 0 do s  + GetValue(volume, i);
def vwapNum = fold j = 0 to RangeLookback with sv = 0 do sv + GetValue(volume, j) * GetValue(close, j);
def rawVWAP = if volSum > 0 then vwapNum / volSum else (res + sup) / 2;

def varNum  = fold k = 0 to RangeLookback with sv2 = 0 do
    sv2 + GetValue(volume, k) * Power(GetValue(close, k) - rawVWAP, 2);
def sigV    = if volSum > 0 then Sqrt(varNum / volSum) else (res - sup) / 4;

def eqV = if chanOK then rawVWAP else (res + sup) / 2;

def oscVal = if chanOK and sigV > 0 then (close - eqV) / sigV else 0;

# ============================================================================
# FIXED HORIZONTAL LEVELS
# ============================================================================

plot ZeroLine  = 0;
ZeroLine.SetDefaultColor(GlobalColor("EQSolid"));
ZeroLine.SetLineWeight(2);

plot UpL0  =  OuterWallSigma0;
plot DnL0  = -OuterWallSigma0;
plot UpL1  =  OuterWallSigma;
plot DnL1  = -OuterWallSigma;
plot UpL2  =  OuterWallSigma2;
plot DnL2  = -OuterWallSigma2;

UpL0.SetDefaultColor(GlobalColor("Premium"));
UpL0.SetLineWeight(2);

DnL0.SetDefaultColor(GlobalColor("Discount"));
DnL0.SetLineWeight(2);

UpL1.SetDefaultColor(GlobalColor("Premium"));
UpL1.SetLineWeight(2);

DnL1.SetDefaultColor(GlobalColor("Discount"));
DnL1.SetLineWeight(2);

UpL2.SetDefaultColor(GlobalColor("Premium"));
UpL2.SetLineWeight(2);

DnL2.SetDefaultColor(GlobalColor("Discount"));
DnL2.SetLineWeight(2);


# ============================================================================
# OSCILLATOR PLOT
# ============================================================================

plot Osc = if chanOK then oscVal else Double.NaN;
Osc.SetLineWeight(2);
Osc.AssignValueColor(
    if oscVal >  OuterWallSigma  then Color.MAGENTA
    else if oscVal >  OuterWallSigma0 then GlobalColor("Premium")
    else if oscVal < -OuterWallSigma  then Color.CYAN
    else if oscVal < -OuterWallSigma0 then GlobalColor("Discount")
    else Color.GRAY
);

# ============================================================================
# CLOUDS - mirror the overlay zone fills
# ============================================================================

AddCloud(UpL0,  UpL1,  GlobalColor("UpperZone"),  GlobalColor("UpperZone"));
AddCloud(UpL0,  ZeroLine, GlobalColor("UpperOuter"), GlobalColor("UpperOuter"));
AddCloud(ZeroLine, DnL0,  GlobalColor("LowerZone"),  GlobalColor("LowerZone"));
AddCloud(DnL0,  DnL1,  GlobalColor("LowerOuter"), GlobalColor("LowerOuter"));
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
893 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top