Pine Script v5 · Strategy
Optimized Zhaocaijinbao strategy
A Pine Script v5 strategy built on SMA (close, 6), EMA (close, 2) and Crossunder (sellLine, buyLine). It has 4 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 2 settings; defaults include Max Position Size (%) 0.01 and Risk Factor 2.0.
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 Optimized Zhaocaijinbao strategy 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 Optimized Zhaocaijinbao strategy do on BTCUSDT 1D with default settings?
- +15.63%
- From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Optimized Zhaocaijinbao strategy run in Pine Script v6?
- Yes
- Same 12 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 Optimized Zhaocaijinbao strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 51.
- Does Optimized Zhaocaijinbao strategy run in Zeal Terminal?
- Yes
- It compiles in 35 ms and runs 1,000 bars in 49 ms, in the browser.
BTCUSDT · 1D · default settings
- Shape
- Shape
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +15.63%
- $156,263.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 12
- 7 won · 5 lost
- Profitable
- 58.3%
- of closed trades
- Profit factor
- 1.94
- gross profit ÷ gross loss
- Max drawdown
- 9.85%
- −$98,458.30
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. 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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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.
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 |
|---|---|---|---|
| Max Position Size (%) | 0.01 | float · min 0.001 · max 0.5 · step 0.001 | positionSize |
| Risk Factor | 2.0 | float · min 0.1 · max 10.0 · step 0.1 | positionSize |
What it calculates
- SMAclose, 6
ma6 · line 7 - SMAclose, 35
ma35 · line 8 - EMAclose, 2
buyLine · line 10 - SMAclose, 8
sellLine · line 12 - EMAvolume, 20
volumeEMA · line 14 - SMAclose, 50
weeklyMa · line 16 - CrossundersellLine, buyLine
sellSignal · line 20 - ATR14
atr · line 25
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 Long long | (buyCondition) | On | 34 |
| Close Long | (sellCondition) | On | 37 |
| Exit Long Stop Loss stop | inPosition | On | 51 |
| Exit Long Take Profit limit | inPosition | On | 52 |
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 | +15.6% | +102.5% | 12 | 58% | 1.94 | 9.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.7% | +9.8% | 14 | 43% | 0.95 | 31.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +34.6% | +16.7% | 7 | 57% | 7.36 | 4.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +7.1% | +21.5% | 2 | 100% | — | 1.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −9.3% | +148.3% | 8 | 38% | 0.58 | 24.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 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 | 5 | 80% | $235,747.00 |
| Sideways market | 5 | 40% | −$78,468.30 |
| Falling market | 2 | 50% | −$1,015.83 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
12.6%
The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.3% to 12.6%; the tick is what actually happened, 7.3%. Order luck alone moves it this much.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Jun 2024 68,809.90 | 1 Jul 2024 62,772.00 | 27 | −$53,056.20 |
| long | 27 Sep 2024 65,174.00 | 7 Oct 2024 62,819.90 | 10 | −$19,993.00 |
| long | 7 Nov 2024 75,572.00 | 20 Nov 2024 92,310.80 | 13 | $121,538.00 |
| long | 5 Dec 2024 98,587.30 | 12 Dec 2024 101,125.00 | 7 | $15,750.00 |
| long | 19 May 2025 106,454.00 | 27 May 2025 109,435.00 | 8 | $23,410.80 |
| long | 3 Jul 2025 108,850.00 | 23 Jul 2025 119,954.00 | 20 | $88,129.00 |
| long | 14 Jan 2026 95,414.00 | 28 Jan 2026 89,250.00 | 14 | −$57,174.60 |
| long | 14 Apr 2026 74,418.00 | 22 Apr 2026 76,336.10 | 8 | $16,520.90 |
| long | 2 May 2026 78,231.10 | 15 May 2026 81,090.00 | 13 | $28,344.70 |
| long | 31 Jul 2026 64,780.00 | 4 Aug 2026 63,520.00 | 4 | −$17,536.70 |
| long | 15 Sep 2026 78,189.20 | 19 Sep 2026 80,883.90 | 4 | $28,169.60 |
| long | 2 Oct 2026 84,880.10 | 14 Oct 2026 83,169.00 | 12 | −$17,839.60 |
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 |
|---|---|---|---|---|---|
| Optimized Zhaocaijinbao strategy this page | — | v5 strategy | +15.6% | 12 | 9.8% |
| ATR with EOM and VORTEX by SoftKill21 | atr ema sma | v4 strategy | +66.2% | 22 | 29.9% |
| cATRpillar Strategy by Obi-wanClintobe | atr sma ema | v4 strategy | +1.02827e+24% | 27 | 88,097.2% |
| EMA & Supertrend by bhavikmota | ema sma atr | v4 strategy | +2,123.6% | 13 | 980.9% |
| Koala System EURUSD 15min by SoftKill21 | sma ema atr | v4 strategy | No trades on this market | ||
| Buy&Sell Bullish Engulfing - The Quant Science by thequantscience | sma ema atr | v5 strategy | No trades on this market | ||
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
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Same 12 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.
⋯// © fzj20020403-////@version=5+////@version=6//@version=5⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 35 ms | Yes 1,000 bars in 49 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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/// © fzj20020403////@version=5//@version=5strategy("Optimized Zhaocaijinbao", overlay=true, margin_long=100, margin_short=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Define two moving averagesma6 = ta.sma(close, 6)ma35 = ta.sma(close, 35)// Define buy and sell signal linesbuyLine = ta.ema(close, 2)sellSlope = (close - close[8]) / 8sellLine = sellSlope * 1 + ta.sma(close, 8)// Define volume indicatorvolumeEMA = ta.ema(volume, 20)// Define weekly slope factorweeklyMa = ta.sma(close, 50)weeklySlope = (weeklyMa - weeklyMa[4]) / 4 > 0// Generate buy and sell signalsbuySignal = ta.crossover(buyLine, sellLine) and close > ma35 and volume > volumeEMA and weeklySlopesellSignal = ta.crossunder(sellLine, buyLine)// Define dynamic position sizing factorequity = strategy.equitymaxPositionSize = equity * input.float(title='Max Position Size (%)', defval=0.01, minval=0.001, maxval=0.5, step=0.001)riskFactor = input.float(title='Risk Factor', defval=2.0, minval=0.1, maxval=10.0, step=0.1)atr = ta.atr(14)positionSize = maxPositionSize * riskFactor / atr// Define position statusvar inPosition = false// Define buy and sell conditionsbuyCondition = buySignal and not inPositionsellCondition = sellSignal and inPosition// Perform buy and sell operationsif (buyCondition) strategy.entry("Long", strategy.long, qty=positionSize) inPosition := trueif (sellCondition) strategy.close("Long") inPosition := false// Draw vertical line markers for buy and sell signalsplotshape(buyCondition, style=shape.arrowdown, location=location.belowbar, color=color.green, size=size.small)plotshape(sellCondition, style=shape.arrowup, location=location.abovebar, color=color.red, size=size.small)// Draw two moving averagesplot(ma6, color=color.blue)plot(ma35, color=color.orange)// Draw volume indicator lineplot(volumeEMA, color=color.yellow)// Define stop loss and take profitstopLoss = strategy.position_avg_price * 0.5takeProfit = strategy.position_avg_price * 1.25if inPosition strategy.exit("Long Stop Loss", "Long", stop=stopLoss) strategy.exit("Long Take Profit", "Long", limit=takeProfit)