Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,260$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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

Verified

Same 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))

Clean v5

VerifiedDownload the v5 script

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.

Download the v6 script

⋯// © 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.

SettingDefaultType and rangeFeeds
decrement0.1float · min 0.0001hl
polynomial degree 2int · min 1.0hl
period SMA20intSMA
period MIN_for20intMIN

What it calculates

  • SMA (sma, ta.sma in v5)close, period SMA (20)SMA · line 9
  • Lowest (lowest, ta.lowest in 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.

closecloseprice dataMAperiod SMAsetting · 20lowlowprice dataMNperiod MIN_forsetting · 20Ddecrementsetting · 0.1Spolynomial degree setting · 2SMASMA→ SMAMINLowest→ MINstopstopvaluenumnumvaluehlhlvalueentry:buyOpen buystrategy.entryclose:buyClose buystrategy.closeplot:24plotplotplot:25plotplot

Order rules

OrderFires whenBy defaultLine
Open buy longclose[1] < SMA[1] and close > SMAOn26
Close buycrossover(hl, close)On27

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.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−6.9%+102.5%425%0.8233.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−17.3%+5.5%813%0.1122.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−31.8%+9.8%1436%0.6861.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.4%+8.4%2429%1.0121.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+4.1%+16.7%3250%1.0162.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−32.5%+21.5%4732%0.3836.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.6%+148.3%2446%0.9730.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+5.5%+17.1%3749%1.1614.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 barsTradesWonP&L
Rising market10%−$167.52
Sideways market250%$232.06
Falling market10%−$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.

0%38%
All 4 trades
SideEntryExitBarsP&L
long18 Mar 2024 68,393.505 Jul 2024 57,050.00109−$167.52
long15 Jul 2024 60,797.9030 Jan 2026 84,650.20564$324.28
long3 Mar 2026 68,830.106 Jun 2026 61,056.5095−$132.69
long21 Jun 2026 64,298.001 Jul 2026 58,624.7010−$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.

ScriptSharesTypeNetTradesMax drawdown
polynomic_stop this page—v4 strategy−6.9%433.0%
Buying Dip Strategy With Take Profit And Stop Loss [racer8] by racer8sma lowestv4 strategy−22.3%3434.7%
ChBrkOutStrategySMA by anshuanshu333sma lowestv4 strategy−4.5%4220.9%
KDJ Strategy @ionvolution by ionvolutionsma lowestv5 strategyNo trades on this market
Trading range display with Box by potatoshopsma lowestv5 strategy+0.7%273.9%
Open Drive by Marcns_lowest smav5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 msWith a workaround 1,000 bars in 21 msNot measured
PineTSNo 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))