OPEN-SOURCE SCRIPT

Trend Engine | Scored Trend Strategy with Squeeze Breakout

5 790
Trend Engine enters when the trend changes direction, and only when that change is backed by a multi-factor strength score. It manages each trade with structured stops, scaled take-profits and optional trailing exits.

How it works
Trend Tracker: a stepped line set a multiple of ATR away from price. In an uptrend it can only move up; in a downtrend it can only move down. When price closes through it, the trend flips direction. This flip is the core entry trigger.
Trend Score: six independent checks each vote +1 (bullish) or −1 (bearish):
  • Tracker direction
  • Price above or below the Equilibrium line
  • Slope of the Equilibrium line
  • RSI above or below 50
  • RSI above or below its own average
  • +DI versus −DI

The score is shown as a percentage of the checks you have enabled, so −100% is fully bearish and +100% is fully bullish. A flip only becomes a trade if the score agrees with it strongly enough.

Equilibrium Cloud: the Equilibrium line is a Hull-smoothed linear regression of price. ATR-based inner and outer bands around it show when price has stretched away from its mean.

Squeeze Zones: when the recent price range stays narrower than a set multiple of ATR for a set number of bars, the script draws a consolidation zone with a gradient fill. If price then closes outside the zone, the zone turns green or red and a separate breakout trailing stop starts tracking the move.

Execution: when every enabled filter passes, the strategy opens a position. It then manages the trade with your chosen stop-loss, up to three take-profit targets, a breakeven move, trailing logic and time-based exits.

The idea is to trade only when trend direction, momentum, directional movement and price structure all agree, and to stay out of trend flips that happen in choppy, low-conviction conditions.

Features
  • Entries and filters (each can be switched on or off and tuned)
  • A minimum Trend Score %, with each of the six score checks individually selectable
  • An ADX strength minimum
  • RSI momentum levels, set separately for longs and shorts
  • Price above or below the Equilibrium line
  • A volume surge (volume above its average by a multiplier)
  • Multi-timeframe alignment: a minimum number of higher timeframes must agree on direction
  • A cooldown in bars between signals
  • A consolidation filter: either block entries inside an active zone, or require a breakout in the same direction within a set number of bars
  • Delayed entry: if filters block a flip, the trade can still trigger later in the same trend once every filter passes
  • Long only, short only or both, and either reverse or just close on an opposite signal


Risk management
  • Initial stop based on the Trend Tracker, ATR, a percent, or the recent swing high/low
  • Up to three take-profit targets in R multiples, ATR or percent, each closing a quantity you choose
  • Move the stop to breakeven after the first target
  • A trailing stop that follows the Trend Tracker or trails a set ATR distance from the best price, starting immediately or after the first target
  • Exit on an opposite trend flip, or after a maximum number of bars
  • Position sizing from the Properties tab, a fixed quantity, or a percent of equity risked per trade
  • A date range to limit the backtest window


Visuals and dashboards
  • Trend Tracker line with a glow and a fill between it and price
  • Candles coloured by trend direction or by score strength, plus an optional background tint
  • The Equilibrium Cloud
  • Gradient squeeze zones with range labels and a breakout trailing stop
  • Signal labels with tooltips showing the score, ADX, RSI and how many timeframes agree, with "Strong" marking high-conviction entries
  • A strategy panel showing trend, strength, ADX regime, momentum, range status, timeframe alignment, open position, stop and target, net P/L, win rate, profit factor, max drawdown and breakout win rate
  • A table covering five timeframes with trend, score, RSI and ADX for each
  • Optional RSI exhaustion dots and grey × markers on flips the filters blocked


Tips
  • Start simple: run it with only the default Trend Score filter, then add one filter at a time and check the effect in the Strategy Tester.
  • Trending markets: try a Trend Score of 60–70% plus an ADX minimum of about 20 to reduce whipsaws.
  • Choppy markets: use the consolidation filter set to "Block Inside Active Zone", or raise the Tracker multiplier to 2.5–3.5.
  • Multi-timeframe alignment: pick timeframes at or above your chart's timeframe. Lower ones don't give meaningful results.
  • Sizing: "Risk % of Equity" sizing works best with a fixed stop type (ATR, Swing or Percent), so the risk per trade stays consistent.
  • Faster exits: setting the trailing stop to "Trend Tracker" and starting it after the first target lets the remaining position ride the trend after you've banked some profit.
  • Tuning the zones: if they appear too often, lower "Max Range Width"; if they almost never appear, raise it.
  • Costs: always set commission, slippage and initial capital in the Properties tab to match your broker before trusting the results.


Warnings
  • This script is for educational and research purposes only and is not financial advice. Past backtest performance does not guarantee future results.
  • Fills and R-multiples: orders fill on the next bar's open. Stops and targets are measured from the signal bar's close, so real R-multiples will be slightly different.
  • Order of fills within a bar: when a bar reaches both a stop and a target, the Strategy Tester has to assume which was hit first. Use Bar Magnifier (on plans that have it) for more realistic results.
  • Higher-timeframe data: with "Non-Repainting MTF" turned off, higher-timeframe values can repaint during live bars. Keep it on for backtesting.
  • Overfitting: heavily tuned settings usually stop working on new data. Test them on several symbols and time periods, and do a forward or out-of-sample test before trading live.
  • Market conditions: trend-following strategies lose money in sideways markets. Expect strings of small losses between larger winning trends.
  • Symbols without volume: some forex and index symbols have no volume data, so the volume filter is automatically skipped there.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.