OPEN-SOURCE SCRIPT

Top Strategy Finder [SpokoStocks]

2 382
Top Strategy Finder

What if your chart could tell you which trading rule has actually worked on it?

Add this script to any symbol, any timeframe, and it backtests up to 2,304 complete strategies on that exact chart, ranks them, and shows a leaderboard you can read like a sentence: "Buy when RSI(2) drops below 10, only in calm volatility, exit on the reverse signal." Pick a row. Its trades appear on your price chart, its open position shows entry, stop and target, and its alerts are ready. No coding, no settings to tune.

Then it does something most strategy finders never show you: it walks forward and reports, without hindsight, whether trusting its own picks would have made money.


The problem it solves

Every strategy finder finds a winner. That is the easy part. Test enough rules on the same data and something always looks brilliant. The question that decides whether you make money is different: would that rule have worked from the moment you picked it?

This script answers it on the chart. On every bar it re-ranks all strategies using only the bars seen so far and follows a basket of the current leaders. The blue curve is what following those picks, bar by bar, would have produced. The gold curve is the champion's in-sample record. The gap between them is selection bias, drawn in the open. When both rise, the edge survived being chosen. When only the gold one does, you were looking at luck.


What you get

Leaderboard
• The top strategies (6 by default, up to 10) in plain language: entry on the first line, exit and filter on the second
• Trades and win rate as a bar, profit factor, net and max drawdown, all heat-coloured, in a table kept narrow so the chart stays visible
• Rank 1 starred, your selected row highlighted
• A trading plan for the selected row: exactly when to buy or sell, in which market condition, and how to exit
• A walk-forward line: what following the top basket would have earned, and how often the champion changed
• A "now" line: what your selected strategy and the basket hold on this bar

Performance pane
• Growth from the same start bar: buy & hold, the walk-forward basket, the champion, your selected row
• Each curve named with its result at the right edge
• Basket profit or loss area, optional drawdown shading, optional log scale

Price chart
• The selected strategy's recent trades drawn as green or red segments
• Its open trade with entry, stop and target lines
• Exposure shading and markers whenever the followed strategy turns long, short or flat

Alerts
• Selected strategy enters long, enters short, exits
• Basket turns long or short
• Champion enters long or short, champion changed


What is tested

Each strategy = one entry signal × one direction × one exit rule × one market filter.

24 entries, each with a long and a mirrored short version: EMA 9/21 and 20/50 crosses · close crossing SMA 20 and SMA 50 · RSI(2) beyond 10/90 and 5/95 · RSI(14) leaving 30/70 and crossing 50 · close beyond the 2σ and 2.5σ Bollinger bands · 10, 20 and 55-bar breakouts · MACD histogram crossing zero · MACD line crossing signal · Supertrend (3,10) and (2,14) flips · Stochastic leaving 20/80 · inside-bar breakout · three closes against the trade · ADX above 20 with a DI cross · Williams %R beyond −90/−10 · fresh 10-bar extreme with a reversal close · gap continuation.

8 exits: after 5, 10 or 20 bars · stop 2 ATR / target 3 ATR · stop 1 ATR / target 2 ATR · stop and target 1.5 ATR · trailing stop 3 ATR · exit on the reverse signal.

6 filters: any market · with the 200-bar trend · against it · calm volatility · high volatility · with 20-bar momentum.

Search sizes: Quick 288 · Standard 768 · Deep 1,536 · Max 2,304.


How the backtest works

• Entries at the close of the signal bar.
• Stops and targets are checked against the following bars' highs and lows; if both are touched in one bar, the stop is assumed.
• Every side pays the cost you set (default 0.05%).
• A strategy must reach the minimum number of trades (default 30) and, by default, be net profitable to rank at all.
• Rank by Win %, SQN, profit factor, net profit, expectancy, return / drawdown, or average win / average loss.
• The champion keeps its title until a challenger beats it by a margin you set, so the title does not flip on noise.
• The walk-forward basket follows the top K (default 5) equally weighted, chosen at each bar's close and exposed to the next bar's move.


Repainting and data

All signals are evaluated on the chart's own OHLC data, with no higher-timeframe requests. Entries, exits and rankings are confirmed at the close of each bar; the walk-forward curve and every trade in the logs are built only from closed bars and do not change afterwards. The leaderboard order can change as new bars close, because new trades change the statistics; that is the ranking updating, not a redraw of history.


How to use it in five minutes

1. Add it to the chart you trade. Start with the Standard size.
2. Read the leaderboard. Favour rows with many trades and a modest drawdown over rows with a large net and few trades.
3. Look at the pane. Blue rising with gold: the edge survived being chosen. Blue flat while gold soars: the leaders are curve-fit to this chart.
4. Pick the row you want to trade. Read its plan under the table, check its drawn trades, set its alerts.
5. Switch the ranking metric. Rules that stay on top under several metrics are the robust ones.


What it is not

An indicator, not a strategy() script, so there is no order-by-order report from the built-in tester. It is a discovery tool: it tells you which rule to build and shows you, without hindsight, whether choosing that rule would have paid. Results depend on the bars tested (default the last 2,500) and on your cost setting. Past results do not guarantee future performance. This is not financial advice.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.