Pine Script v4 · Strategy
polynomic_stop
A Pine Script v4 strategy built on SMA (close, 20) and Lowest (low, 20). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1 commission. 4 settings; defaults include decrement 0.1, polynomial degree 2 and period SMA 20.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does polynomic_stop repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did polynomic_stop do on BTCUSDT 1D with default settings?
- −6.91%
- From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can polynomic_stop be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does polynomic_stop use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does polynomic_stop run in Zeal Terminal?
- Yes
- It compiles in 9 ms and runs 1,000 bars in 21 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −6.91%
- −$69.09
- Buy and hold
- +102.5%
- same period
- Closed trades
- 4
- 1 won · 3 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 0.82
- gross profit ÷ gross loss
- Max drawdown
- 32.97%
- −$329.74
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 26, 27. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames sma → ta.sma, lowest → ta.lowest, pow → math.pow, crossover → ta.crossover.
- 2 strategy calls use the when = argument (line 26, 27). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 9: sma → ta.sma
- Line 10: lowest → ta.lowest
- Line 23: pow → math.pow
- Line 26: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 27: crossover → ta.crossover
⋯// © Alferow-//@version=4+//@version=5strategy("polynomic_stop", overlay=true, initial_capital=1000, commission_value=0.1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯MN = input(20, title = 'period MIN_for')-SMA = sma(close, MA)+SMA = ta.sma(close, MA)-MIN = lowest(low, MN)+MIN = ta.lowest(low, MN)var stop = 0.0⋯ -hl = stop + D * pow(num, S)+hl = stop + D * math.pow(num, S)plot(hl)plot(SMA, color = color.red)-strategy.entry("buy", true, when = close[1] < SMA[1] and close > SMA)+strategy.entry("buy", strategy.long, when = close[1] < SMA[1] and close > SMA)-strategy.close("buy", when = crossover(hl, close))+strategy.close("buy", when = ta.crossover(hl, close))Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.float()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 26: when = close[1] < SMA[1] and close > SMA → if block
- Line 27: when = ta.crossover(hl, close) → if block
⋯strategy("polynomic_stop", overlay=true, initial_capital=1000, commission_value=0.1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)-D = input(0.1, minval = 0.0001, title = 'decrement')+D = input.float(0.1, minval = 0.0001, title = 'decrement')-S = input(2, minval = 1.0, title = 'polynomial degree ')+S = input.int(2, minval = 1.0, title = 'polynomial degree ')-MA = input(20, title = 'period SMA')+MA = input.int(20, title = 'period SMA')-MN = input(20, title = 'period MIN_for')+MN = input.int(20, title = 'period MIN_for')SMA = ta.sma(close, MA)⋯plot(SMA, color = color.red)-strategy.entry("buy", strategy.long, when = close[1] < SMA[1] and close > SMA)+if close[1] < SMA[1] and close > SMA+ strategy.entry("buy", strategy.long)-strategy.close("buy", when = ta.crossover(hl, close))+if ta.crossover(hl, close)+ strategy.close("buy")Does it run in Pine Script v6?
Yes
Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © Alferow-//@version=5+//@version=6strategy("polynomic_stop", overlay=true, initial_capital=1000, commission_value=0.1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| decrement | 0.1 | float · min 0.0001 | hl |
| polynomial degree | 2 | int · min 1.0 | hl |
| period SMA | 20 | int | SMA |
| period MIN_for | 20 | int | MIN |
What it calculates
- SMA (
sma,ta.smain v5)close, period SMA (20)SMA · line 9 - Lowest (
lowest,ta.lowestin v5)low, period MIN_for (20)MIN · line 10
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open buy long | close[1] < SMA[1] and close > SMA | On | 26 |
| Close buy | crossover(hl, close) | On | 27 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −6.9% | +102.5% | 4 | 25% | 0.82 | 33.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −17.3% | +5.5% | 8 | 13% | 0.11 | 22.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −31.8% | +9.8% | 14 | 36% | 0.68 | 61.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.4% | +8.4% | 24 | 29% | 1.01 | 21.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +4.1% | +16.7% | 32 | 50% | 1.01 | 62.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −32.5% | +21.5% | 47 | 32% | 0.38 | 36.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.6% | +148.3% | 24 | 46% | 0.97 | 30.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +5.5% | +17.1% | 37 | 49% | 1.16 | 14.5% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 0% | −$167.52 |
| Sideways market | 2 | 50% | $232.06 |
| Falling market | 1 | 0% | −$132.69 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
32.9%
The 95th percentile of the worst drawdown when the same 4 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 19.4% to 32.9%; the tick is what actually happened, 19.4%. Order luck alone moves it this much.
All 4 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 18 Mar 2024 68,393.50 | 5 Jul 2024 57,050.00 | 109 | −$167.52 |
| long | 15 Jul 2024 60,797.90 | 30 Jan 2026 84,650.20 | 564 | $324.28 |
| long | 3 Mar 2026 68,830.10 | 6 Jun 2026 61,056.50 | 95 | −$132.69 |
| long | 21 Jun 2026 64,298.00 | 1 Jul 2026 58,624.70 | 10 | −$92.22 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| polynomic_stop this page | — | v4 strategy | −6.9% | 4 | 33.0% |
| Buying Dip Strategy With Take Profit And Stop Loss [racer8] by racer8 | sma lowest | v4 strategy | −22.3% | 34 | 34.7% |
| ChBrkOutStrategySMA by anshuanshu333 | sma lowest | v4 strategy | −4.5% | 42 | 20.9% |
| KDJ Strategy @ionvolution by ionvolution | sma lowest | v5 strategy | No trades on this market | ||
| Trading range display with Box by potatoshop | sma lowest | v5 strategy | +0.7% | 27 | 3.9% |
| Open Drive by Marcns_ | lowest sma | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 9 ms | With a workaround 1,000 bars in 21 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 26) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Alferow//@version=4strategy("polynomic_stop", overlay=true, initial_capital=1000, commission_value=0.1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)D = input(0.1, minval = 0.0001, title = 'decrement')S = input(2, minval = 1.0, title = 'polynomial degree ')MA = input(20, title = 'period SMA')MN = input(20, title = 'period MIN_for')SMA = sma(close, MA)MIN = lowest(low, MN)var stop = 0.0var num = 0if strategy.opentrades[1] == 0 and strategy.opentrades != 0 stop := MIN if strategy.opentrades != 0 num := num + 1 if strategy.opentrades == 0 num := 0 stop := MIN hl = stop + D * pow(num, S)plot(hl)plot(SMA, color = color.red)strategy.entry("buy", true, when = close[1] < SMA[1] and close > SMA)strategy.close("buy", when = crossover(hl, close))