Search This Blog

Friday, August 15, 2025

Scanner for Backtesting a DownChannel Breakout

 # Scanner: Breakout + Backtest in Downtrend Channel (NASDAQ Composite)
# Scans NASDAQ index tickers (e.g. $COMP?) for breakout setups

input length = 60;
input stDevMult = 2.0;
input minDownSlope = -0.02;
input backtestWindow = 12;
input tol = 0.002;

def lr = Inertia(close, length);
def slope = lr - lr[1];
def resid = close - lr;
def sd = StDev(resid, length);
def upper = lr + stDevMult * sd;

def inDowntrend = slope < minDownSlope;
def breakout = inDowntrend[1] and close[1] <= upper[1] and close > upper;
def withinTol = AbsValue(low - upper) <= tol * upper;
def barsSinceBO = if breakout then 0 else if barsSinceBO[1] >= 1000 then 1000 else barsSinceBO[1] + 1;
def validBacktest = withinTol and barsSinceBO > 0 and barsSinceBO <= backtestWindow;

plot scan = validBacktest;
--------------------------

How to Use It in ThinkorSwim

Go to the Scan tab and create a Stock Hacker scan.

Set Symbol filter to tickers within the NASDAQ Composite.

You can use prebuilt sets like “All Tickers” or try custom filtering by exchange = NASDAQ.

Add the Custom Study filter and paste the above script.

Run the scan to highlight all tickers that recently broke out of a down-channel and are pulling back to retest.

You can also tailor the script—like adding minimum liquidity or focusing only on tech sectors.

Summary
Feature    Detail
Index    NASDAQ Composite (also NQ Computer index)
Scanner Purpose    Identify stocks with breakout + retest patterns within that index
How to Use    Paste into TOS Stock Hacker with NASDAQ filter; scan for valid setups
Why It Matters    Spot potential continuation setups across a wide universe, not just CRWV

Let me know if you'd like help adjusting the scanner (e.g., add volume filters, RSI thresholds, or limit to only AI/tech sectors)! 

No comments:

Post a Comment

TTM Squeeze Scan on Stock Charts

 Scanner for TTM squeeze , good daily liquidity, over $8.   Detailed explanation at the bottom.  ------------------------  [type is stock] a...