Trendbox for TOS

Khaynes

New member
Hi everyone, I was wondering if anyone had a tool similar to the picture shared. This tool is used for MT4 and MT5 so I am unclear how to grab the code. With all the trend indicators I have seen figured I would ask if this was one of them.

At the basics I am looking for a breakout box tool that allows for # candles (could be user define could be specified) that calculates potential profit from breakout candles with trend direction.


 
Solution
Hi everyone, I was wondering if anyone had a tool similar to the picture shared. This tool is used for MT4 and MT5 so I am unclear how to grab the code. With all the trend indicators I have seen figured I would ask if this was one of them.

At the basics I am looking for a breakout box tool that allows for # candles (could be user define could be specified) that calculates potential profit from breakout candles with trend direction.

i searched for box and found these.
maybe one of them can give you some ideas, and be a starting point for what you want...



b3
https://usethinkscript.com/threads/...akout-breakdown-indicator-for-thinkorswim.103/

darvas convert...
Thanks Ramesh16 the consolidation box I have seen showed possible direction post consolidation but I don't recall it having profit targets. I will search here to see if I can find it though and take a look again.
 
Hi everyone, I was wondering if anyone had a tool similar to the picture shared. This tool is used for MT4 and MT5 so I am unclear how to grab the code. With all the trend indicators I have seen figured I would ask if this was one of them.

At the basics I am looking for a breakout box tool that allows for # candles (could be user define could be specified) that calculates potential profit from breakout candles with trend direction.

i searched for box and found these.
maybe one of them can give you some ideas, and be a starting point for what you want...



b3
https://usethinkscript.com/threads/...akout-breakdown-indicator-for-thinkorswim.103/

darvas convert
https://usethinkscript.com/threads/convert-tradingview-darvas-box-strategy-v2.12140/#post-115154

https://usethinkscript.com/threads/high-low-range-chart-setup-for-thinkorswim.13750/#post-115131

https://usethinkscript.com/threads/fractal-boxes-by-mobius-for-thinkorswim.377/#post-113906

https://usethinkscript.com/threads/code-help-range-box.12970/#post-111568

https://usethinkscript.com/threads/squeeze-box-dw-for-thinkorswim.12967/

https://usethinkscript.com/threads/psar-transition-box.12706/#post-109424

https://usethinkscript.com/threads/...the-series-for-thinkorswim.12792/#post-109326

https://usethinkscript.com/threads/...inkorswim-scalping-strategy.9595/#post-109241

https://usethinkscript.com/threads/congestion-zone.10503/

https://usethinkscript.com/threads/choppiness-index-indicator-for-thinkorswim.1277/
 
Last edited:
Solution
Code:
# =========================================
# SMART DARVAS ENGINE v2 (EXTENDED + RANKED)
# ANTWERKS 04/06/2026
# =========================================

declare upper;

# =========================
# INPUTS
# =========================
input lookback = 10;
input minBarsInBox = 5;
input breakoutBuffer = 0.001;
input strongBoxBars = 6;   # threshold for strong vs weak

# =========================
# CORE LEVELS
# =========================
def hh = Highest(high, lookback);
def ll = Lowest(low, lookback);

# =========================
# STABILITY (RELAXED)
# =========================
def stableHigh = AbsValue(hh - hh[1]) < TickSize();
def stableLow  = AbsValue(ll - ll[1]) < TickSize();

def formingBox = stableHigh and stableLow;

# =========================
# COUNT BARS IN BOX
# =========================
rec boxBars =
    if formingBox then boxBars[1] + 1
    else 0;

def validBox = boxBars >= minBarsInBox;

# =========================
# LOCK BOX (EXTENDS UNTIL TRUE BREAK)
# =========================
rec boxHigh =
    if validBox and !validBox[1] then hh
    else if !IsNaN(boxHigh[1]) then boxHigh[1]
    else Double.NaN;

rec boxLow =
    if validBox and !validBox[1] then ll
    else if !IsNaN(boxLow[1]) then boxLow[1]
    else Double.NaN;

# =========================
# TRUE BREAK CONDITIONS
# =========================
def breakout =
    close > boxHigh * (1 + breakoutBuffer);

def breakdown =
    close < boxLow * (1 - breakoutBuffer);

# RESET ONLY ON TRUE BREAK
rec activeHigh =
    if breakout or breakdown then Double.NaN
    else if !IsNaN(boxHigh) then boxHigh
    else activeHigh[1];

rec activeLow =
    if breakout or breakdown then Double.NaN
    else if !IsNaN(boxLow) then boxLow
    else activeLow[1];

# =========================
# BOX STRENGTH
# =========================
def strongBox = boxBars >= strongBoxBars;
def weakBox = validBox and boxBars < strongBoxBars;

# =========================
# FAILED BREAKS (TRAPS)
# =========================
def failedBreakout =
    high > activeHigh and close <= activeHigh;

def failedBreakdown =
    low < activeLow and close >= activeLow;

# =========================
# PLOTS
# =========================
plot BoxHighPlot =
    if !IsNaN(activeHigh) then activeHigh else Double.NaN;

plot BoxLowPlot =
    if !IsNaN(activeLow) then activeLow else Double.NaN;

BoxHighPlot.SetLineWeight(2);
BoxLowPlot.SetLineWeight(2);

BoxHighPlot.SetDefaultColor(Color.YELLOW);
BoxLowPlot.SetDefaultColor(Color.YELLOW);

AddCloud(BoxHighPlot, BoxLowPlot, Color.DARK_GRAY, Color.DARK_GRAY);

# =========================
# LABELS (UPGRADED)
# =========================
AddLabel(yes,

    if breakout then "DARVAS BREAKOUT"
    else if breakdown then "DARVAS BREAKDOWN"
    else if failedBreakout then "FAILED BREAKOUT"
    else if failedBreakdown then "FAILED BREAKDOWN"
    else if strongBox then "STRONG BOX (ACCUMULATION)"
    else if weakBox then "WEAK BOX (TRANSITION)"
    else "NO BOX",

    if breakout then Color.GREEN
    else if breakdown then Color.RED
    else if failedBreakout then Color.ORANGE
    else if failedBreakdown then Color.CYAN
    else if strongBox then Color.GREEN
    else if weakBox then Color.YELLOW
    else Color.GRAY
);


BEST SETTINGS BY TIMEFRAME

1. SCALPING (1m – 5m)​

Settings:

lookback = 10–15
minBarsInBox = 3–5
strongBoxBars = 6–8

Behavior:
  • Fast boxes
  • Lots of signals
  • More WEAK BOXES
Use case: Combine with:
  • A volume panel
  • An absorption detection
2. INTRADAY (5m – 15m) ** SWEET SPOT

Settings:

lookback = 15–25
minBarsInBox = 5–8
strongBoxBars = 10–15

Behavior:
  • Clean structure
  • Balanced signals
  • Best for your system

3. SWING (30m – 1H)

Settings:

lookback = 20–40
minBarsInBox = 8–12
strongBoxBars = 15–25

Behavior:
  • Fewer boxes
  • Much stronger
  • Institutional positioning
4. DAILY (POSITION TRADING)

Settings:

lookback = 30–60
minBarsInBox = 10–20
strongBoxBars = 20–40

Behavior:
  • Very clean zones
  • Big moves
  • Slow signals
HOW TO THINK ABOUT IT (IMPORTANT)

LOWER TIMEFRAME

More boxes
More noise
More fake breakouts

You MUST use:
  • volume
  • EMA structure
  • flow
HIGHER TIMEFRAME

Fewer boxes
Cleaner structure
More reliable breakouts

You can trust:
  • box breaks alone more
 
Something to keep as a reference while learning to use the Darvas or any other "play the extremes" tool like support/resistance - supply/demand. Or even measures like VWAP and AVWAP, POC or ATR.
 

Attachments

  • trading_playbook_full.pdf
    3.8 KB · Views: 62

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
2171 Online
Create Post

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