Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Trading the Equity Curve Position Sizing Example

A Pine Script v5 strategy built on SMA (slowequityseed, 25), CMO (close, 9) and MOM (price, 12). It has 4 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10% of equity and pays no commission. 12 settings; defaults include Initial % Equity 10.0, Slow SMA Period 25 and Fast SMA Period 9.

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 Trading the Equity Curve Position Sizing Example repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did Trading the Equity Curve Position Sizing Example do on BTCUSDT 1D with default settings?
+3.34%
From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Trading the Equity Curve Position Sizing Example run in Pine Script v6?
Yes
Same 14 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. The v6 script can be downloaded below.
Does Trading the Equity Curve Position Sizing Example use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Trading the Equity Curve Position Sizing Example run in Zeal Terminal?
Yes
It compiles in 23 ms and runs 1,000 bars in 63 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • 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 (12)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$106,439$202,527Equity from $100,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. 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
+3.34%
$3,339.72
Buy and hold
+102.5%
same period
Closed trades
14
6 won · 8 lost
Profitable
42.9%
of closed trades
Profit factor
1.66
gross profit ÷ gross loss
Max drawdown
4.07%
−$4,150.89

One run with the author's default settings, $100,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.

  • Likely bug

    ta.mom(mom0, 1) ignores the settings line 61

    Line 61 hard-codes 1 where line 60 uses “Momentum Length”. Changing those settings moves one band but not this one.

    ta.mom( mom0, 1)ta.mom(mom0, Momentum_Length)
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Use Trading the Equity Curve Position Sizingtruebooldefulttraderule longCondition shortCondition line 45
Initial % Equity10.0floatsizeadjdown sizeadjup qty
Slow SMA Period25intsmaslowequity
Fast SMA Period9intsmafastequity
Use Fast/Slow AvgFast Equity Avg is below Slow---otherwise if unchecked uses Slow Equity Avg below Equitytrueboolequitymethod
Position Size AdjustmentReduce size by (%)string · options ["Reduce size by (%)","Increase size by (%)"]line 39 line 46
Increase/Decrease % Equity by:50intsizeadjdown sizeadjup qty
Chande Momentum Length9int · min 1chandeMO
Chande Momentum Signal10int · min 1cmosignal
SuperTrend ATR Length10intsupertrend direction
SuperTrend Factor3.0float · step 0.01supertrend direction
Momentum Length12intmom0

What it calculates

  • SMAslowequityseed, Slow SMA Period (25)smaslowequity · line 31
  • SMAfastequityseed, Fast SMA Period (9)smafastequity · line 32
  • CMOclose, Chande Momentum Length (9)chandeMO · line 54
  • SMAchandeMO, Chande Momentum Signal (10)cmosignal · line 55
  • MOMprice, Momentum Length (12)mom0 · line 60
  • MOMmom0, 1mom1 · line 61
  • SupertrendSuperTrend Factor (3.0), SuperTrend ATR Length (10)supertrend · line 62
  • SupertrendSuperTrend Factor (3.0), SuperTrend ATR Length (10)direction · line 62

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.

slowequitylengthSlow SMA Periodsetting · 25fastequitylengthFast SMA Periodsetting · 9closecloseprice dataCMO_LengthChande Momentum Lengthsetting · 9CMO_SignalChande Momentum Signalsetting · 10Momentum_LengthMomentum Lengthsetting · 12high · low · closehigh · low · closeprice dataSuperTrend_FactorSuperTrend Factorsetting · 3.0SuperTrend_atrPeriodSuperTrend ATR Lengthsetting · 10initialsizeInitial % Equitysetting · 10.0sizeadjintIncrease/Decrease % Equ…setting · 50smaslowequitySMA→ smaslowequitysmafastequitySMA→ smafastequitychandeMOCMO→ chandeMOcmosignalSMA→ cmosignalmom0MOM→ mom0mom1MOM→ mom1supertrendSupertrend→ supertrenddirectionSupertrend→ directiondefulttraderule, slowequityseed, fastequityseeddefulttraderule · slowe…3 valuesequitymethodequitymethodvaluesizeadjdown, sizeadjupsizeadjdown · sizeadjup2 valuesc, pricec · price2 valuesqtyqtyvaluestupind, stdownindstupind · stdownind2 valueslongConditiondefaultlongConditiondefaultconditionshortConditiondefaultshortConditiondefaultconditionlongConditionlongConditionconditionshortConditionshortConditionconditionequitydowntrendavgsequitydowntrendavgsconditionslowequitylessequityslowequitylessequityconditionentry:DefLongOpen DefLongstrategy.entryentry:DefShortOpen DefShortstrategy.entryentry:AdjLongOpen AdjLongstrategy.entryentry:AdjShortOpen AdjShortstrategy.entryplot:79plotplotplot:80plotplotplot:81plotplot

Order rules

OrderFires whenBy defaultLine
Open DefLong long(longConditiondefault)On68
Open DefShort short(shortConditiondefault)On71
Open AdjLong long(longCondition)On75
Open AdjShort short(shortCondition)On78

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.

6/6trades 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+3.3%+102.5%1443%1.664.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.3%+5.5%1050%2.300.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.8%+9.8%850%1.193.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.0%+8.4%1233%2.291.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+2.8%+16.7%667%1.975.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−1.0%+21.5%1040%0.755.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+6.8%+148.3%838%2.463.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−2.0%+17.1%1331%0.272.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Chande Momentum Length 9, Chande Momentum Signal 12) made +5.8% before 26 Dec 2025 and −1.1% after it, worse than the defaults' −1.0% after. Tuning on the past did not carry forward. 88% of the 56 combinations made money in-sample and 30% out-of-sample.

Before 26 Dec 2025 · in-sample
Chande Momentum Signal ↓ · Chande Momentum Length →5689111315
5+3%+4%+2%+2%+1%+3%+3%
6+5%+4%+1%+2%−0%+3%+2%
7+2%+0%+1%+2%+2%+4%+2%
9+3%+3%+3%+2%+3%+1%−0%
10+3%+4%+4%+4%+3%−0%+2%
12+3%+3%+3%+6%+3%+2%+1%
14+5%+3%+1%+2%−2%+2%+1%
17+5%+1%−3%−1%−0%+2%+4%
From 26 Dec 2025 · out-of-sample
Chande Momentum Signal ↓ · Chande Momentum Length →5689111315
5−1%−0%+0%−2%−1%+2%+0%
6−0%+0%+0%−3%−1%+1%+1%
7+1%+0%−1%−2%−1%−0%−2%
9+0%+0%−1%−1%−1%−0%−4%
10−0%0%−1%−1%−1%−0%−4%
12−0%+0%−0%−1%−2%−2%−5%
14+0%+1%+1%−3%−2%−2%−5%
17+1%+1%−0%−2%−4%−3%−1%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market333%$639.53
Sideways market667%$3,935.59
Falling market520%−$1,235.41

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

3.9%

The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.7% to 3.9%; the tick is what actually happened, 2.3%. Order luck alone moves it this much.

0%5%
All 14 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.503 Apr 2024 65,464.0036$2,016.93
short3 Apr 2024 65,464.005 Jun 2024 70,537.8063−$775.06
long5 Jun 2024 70,537.805 Jul 2024 57,050.0030−$967.94
short5 Jul 2024 57,050.0024 Aug 2024 64,037.2050−$614.05
long24 Aug 2024 64,037.2010 Jan 2025 92,552.50139$4,452.92
short10 Jan 2025 92,552.509 May 2025 103,262.00119−$602.34
long9 May 2025 103,262.0030 Aug 2025 108,377.00113$256.41
short30 Aug 2025 108,377.0014 Jan 2026 95,414.00137$620.60
long14 Jan 2026 95,414.001 Feb 2026 78,741.1018−$912.05
short1 Feb 2026 78,741.1011 Mar 2026 69,948.6038$577.72
long11 Mar 2026 69,948.602 Apr 2026 68,113.9022−$136.46
short2 Apr 2026 68,113.9018 Apr 2026 77,072.0016−$683.34
long18 Apr 2026 77,072.002 Jun 2026 71,408.9045−$379.27
short2 Jun 2026 71,408.906 Aug 2026 64,665.2065$485.66

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
Trading the Equity Curve Position Sizing Example this page—v5 strategy+3.3%144.1%
Strategy Template by Trendoscopesma supertrendv4 strategy−21.8%1140.5%
Dual-Supertrend with MACD - Strategy [presentTrading] by PresentTradingsma supertrendv5 strategy−0.9%365.3%
[VJ] Hulk Smash Intra by vikrissupertrend smav4 strategyNo trades on this market
Higher TF - Repainting + Limiting backtest results by Trendoscopesma supertrendv4 strategyNo trades on this market
Momentum by Zeal Terminalmom smav5 indicatorindicator

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

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

⋯// © shardison-//@version=5+//@version=6//EXPLANATION⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 23 msWith a workaround 1,000 bars in 63 msNot measured
PineTSNot testedNot testedNot measured

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.

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/// © shardison//@version=5//EXPLANATION//"Trading the equity curve" as a risk management method is the //process of acting on trade signals depending on whether a system’s performance//is indicating the strategy is in a profitable or losing phase.//The point of managing equity curve is to minimize risk in trading when the equity curve is  in a downtrend. //This strategy has two modes to determine the equity curve downtrend://By creating two simple moving averages of a portfolio's equity curve - a short-term//and a longer-term one - and acting on their crossings. If the fast SMA is below//the slow SMA, equity downtrend is detected (smafastequity < smaslowequity).//The second method is by using the crossings of equity itself with the longer-period SMA (equity < smasloweequity).//When "Reduce size by %" is active, the position size will be reduced by a specified percentage//if the equity is "under water" according to a selected rule. If you're a risk seeker, select "Increase size by %"//- for some robust systems, it could help overcome their small drawdowns quicker.strategy("Use Trading the Equity Curve Postion Sizing", shorttitle="TEC", default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital = 100000)//TRADING THE EQUITY CURVE INPUTSuseTEC           = input.bool(true, title="Use Trading the Equity Curve Position Sizing")defulttraderule  = useTEC ? false: trueinitialsize      = input.float(defval=10.0, title="Initial % Equity")slowequitylength = input.int(25, title="Slow SMA Period")fastequitylength = input.int(9, title="Fast SMA Period")seedequity = 100000 * .10if strategy.equity == 0    seedequityelse    strategy.equityslowequityseed   = strategy.equity > seedequity ? strategy.equity : seedequityfastequityseed   = strategy.equity > seedequity ? strategy.equity : seedequitysmaslowequity    = ta.sma(slowequityseed, slowequitylength)smafastequity    = ta.sma(fastequityseed, fastequitylength)equitycalc       = input.bool(true, title="Use Fast/Slow Avg", tooltip="Fast Equity Avg is below Slow---otherwise if unchecked uses Slow Equity Avg below Equity")sizeadjstring    = input.string("Reduce size by (%)", title="Position Size Adjustment", options=["Reduce size by (%)","Increase size by (%)"])sizeadjint       = input.int(50, title="Increase/Decrease % Equity by:")equitydowntrendavgs = smafastequity < smaslowequityslowequitylessequity = strategy.equity < smaslowequityequitymethod = equitycalc ? equitydowntrendavgs : slowequitylessequityif sizeadjstring == ("Reduce size by (%)")    sizeadjdown = initialsize * (1 - (sizeadjint/100))else    sizeadjup = initialsize * (1 + (sizeadjint/100))c = closeqty = 100000 * (initialsize / 100) / cif useTEC and equitymethod    if sizeadjstring == "Reduce size by (%)"        qty := (strategy.equity * (initialsize / 100) * (1 - (sizeadjint/100))) / c    else        qty := (strategy.equity * (initialsize / 100) * (1 + (sizeadjint/100))) / c    //EXAMPLE TRADING STRATEGY INPUTSCMO_Length = input.int(defval=9, minval=1, title='Chande Momentum Length')CMO_Signal = input.int(defval=10, minval=1, title='Chande Momentum Signal')chandeMO = ta.cmo(close, CMO_Length)cmosignal = ta.sma(chandeMO, CMO_Signal)SuperTrend_atrPeriod = input.int(10, "SuperTrend ATR Length")SuperTrend_Factor = input.float(3.0, "SuperTrend Factor", step = 0.01)Momentum_Length = input.int(12, "Momentum Length")price = closemom0 = ta.mom(price, Momentum_Length)mom1 = ta.mom( mom0, 1)[supertrend, direction] = ta.supertrend(SuperTrend_Factor, SuperTrend_atrPeriod)stupind = (direction < 0 ? supertrend : na)stdownind = (direction < 0? na : supertrend)//TRADING CONDITIONSlongConditiondefault = ta.crossover(chandeMO, cmosignal) and (mom0 > 0 and mom1 > 0 and close > stupind) and defulttraderuleif (longConditiondefault)    strategy.entry("DefLong", strategy.long, qty=qty)shortConditiondefault = ta.crossunder(chandeMO, cmosignal) and (mom0 < 0 and mom1 < 0 and close < stdownind) and defulttraderuleif (shortConditiondefault)    strategy.entry("DefShort", strategy.short, qty=qty)    longCondition = ta.crossover(chandeMO, cmosignal) and (mom0 > 0 and mom1 > 0 and close > stupind) and useTECif (longCondition)    strategy.entry("AdjLong", strategy.long, qty = qty)shortCondition = ta.crossunder(chandeMO, cmosignal) and (mom0 < 0 and mom1 < 0 and close < stdownind) and useTECif (shortCondition)    strategy.entry("AdjShort", strategy.short, qty = qty)plot(strategy.equity)plot(smaslowequity, color=color.new(color.red, 0))plot(smafastequity, color=color.new(color.green, 0))