Pine Script v4 · Strategy
Flawless Victory Strategy - 15min BTC Machine Learning Strategy
A Pine Script v4 strategy built on RMA or Change (max(change(src), 0), len), Change (MFIsrc) and SMA (src1, length1). It has 8 order rules, 3 entries 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. 7 settings; defaults include Stop Loss % 6.604, Take Profit % 2.328 and Stop Loss % 8.882.
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 Flawless Victory Strategy - 15min BTC Machine Learning Strategy 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 Flawless Victory Strategy - 15min BTC Machine Learning Strategy do on BTCUSDT 1D with default settings?
- +21.26%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Flawless Victory Strategy - 15min BTC Machine Learning Strategy 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 Flawless Victory Strategy - 15min BTC Machine Learning Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 94, 101.
- Does Flawless Victory Strategy - 15min BTC Machine Learning Strategy run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 52 ms, in the browser.
BTCUSDT · 1D · default settings
- RMA
- RMA
- Change
- Change
- SMA
- Stdev
- SMA
- Stdev
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +21.26%
- $21,262.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 5 won · 1 lost
- Profitable
- 83.3%
- of closed trades
- Profit factor
- 1.68
- gross profit ÷ gross loss
- Max drawdown
- 35.39%
- −$48,937.90
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.
-
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.
-
Note
Uses an argument v6 removed
when = on line 86, 87, 92, 93, 99, 100. 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 rma → ta.rma, max → math.max, change → ta.change, min → math.min, sum → math.sum, sma → ta.sma, stdev → ta.stdev.
- 6 strategy calls use the when = argument (line 86, 87, 92, 93, 99, 100). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: input(type = input.float) → input.float()
- Line 11: input(type = input.float) → input.float()
- Line 14: input(type = input.float) → input.float()
- Line 15: input(type = input.float) → input.float()
- Line 26: rma → ta.rma
13 more edits
- Line 26: max → math.max
- Line 26: change → ta.change
- Line 27: rma → ta.rma
- Line 27: min → math.min
- Line 27: change → ta.change
- Line 32: sum → math.sum
- Line 32: change → ta.change
- Line 33: sum → math.sum
- Line 33: change → ta.change
- Line 45: sma → ta.sma
- Line 46: stdev → ta.stdev
- Line 53: sma → ta.sma
- Line 54: stdev → ta.stdev
⋯// © Bunghole-//@version=4+//@version=5strategy(overlay=true, shorttitle="Flawless Victory Strategy", default_qty_type = strategy.percent_of_equity, initial_capital = 100000, default_qty_value = 100, pyramiding = 0, title="Flawless Victory Strategy", currency = 'USD')⋯v3 = input(false, title="Version 3 - Uses SL/TP")-v2stoploss_input = input(6.604, title='Stop Loss %', type=input.float, minval=0.01)/100+v2stoploss_input = input.float(6.604, title='Stop Loss %', minval=0.01)/100-v2takeprofit_input = input(2.328, title='Take Profit %', type=input.float, minval=0.01)/100+v2takeprofit_input = input.float(2.328, title='Take Profit %', minval=0.01)/100v2stoploss_level = strategy.position_avg_price * (1 - v2stoploss_input)v2takeprofit_level = strategy.position_avg_price * (1 + v2takeprofit_input)-v3stoploss_input = input(8.882, title='Stop Loss %', type=input.float, minval=0.01)/100+v3stoploss_input = input.float(8.882, title='Stop Loss %', minval=0.01)/100-v3takeprofit_input = input(2.317, title='Take Profit %', type=input.float, minval=0.01)/100+v3takeprofit_input = input.float(2.317, title='Take Profit %', minval=0.01)/100v3stoploss_level = strategy.position_avg_price * (1 - v3stoploss_input)⋯src = close-up = rma(max(change(src), 0), len)+up = ta.rma(math.max(ta.change(src), 0), len)-down = rma(-min(change(src), 0), len)+down = ta.rma(-math.min(ta.change(src), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)⋯MFIsrc = hlc3-MFIupper = sum(volume * (change(MFIsrc) <= 0 ? 0 : MFIsrc), MFIlength)+MFIupper = math.sum(volume * (ta.change(MFIsrc) <= 0 ? 0 : MFIsrc), MFIlength)-MFIlower = sum(volume * (change(MFIsrc) >= 0 ? 0 : MFIsrc), MFIlength)+MFIlower = math.sum(volume * (ta.change(MFIsrc) >= 0 ? 0 : MFIsrc), MFIlength)_rsi(MFIupper, MFIlower) =>⋯mult1 = 1.0-basis1 = sma(src1, length1)+basis1 = ta.sma(src1, length1)-dev1 = mult1 * stdev(src1, length1)+dev1 = mult1 * ta.stdev(src1, length1)upper1 = basis1 + dev1⋯mult2 = 1.0-basis2 = sma(src2, length2)+basis2 = ta.sma(src2, length2)-dev2 = mult2 * stdev(src2, length2)+dev2 = mult2 * ta.stdev(src2, length2)upper2 = basis2 + dev2⋯Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.bool()
- Line 8: input() → input.bool()
- Line 9: input() → input.bool()
- Line 86: when = Buy_1 → if block
- Line 87: when = Sell_1 → if block
- Line 92: when = Buy_2 → if block
3 more edits
- Line 93: when = Sell_2 → if block
- Line 99: when = Buy_3 → if block
- Line 100: when = Sell_3 → if block
⋯// Stoploss and Profits Inputs-v1 = input(true, title="Version 1 - Doesn't Use SL/TP")+v1 = input.bool(true, title="Version 1 - Doesn't Use SL/TP")-v2 = input(false, title="Version 2 - Uses SL/TP")+v2 = input.bool(false, title="Version 2 - Uses SL/TP")-v3 = input(false, title="Version 3 - Uses SL/TP")+v3 = input.bool(false, title="Version 3 - Uses SL/TP")v2stoploss_input = input.float(6.604, title='Stop Loss %', minval=0.01)/100⋯if v1 == true- strategy.entry("Long", strategy.long, when = Buy_1, alert_message = "v1 - Buy Signal!")+ if Buy_1+ strategy.entry("Long", strategy.long, alert_message = "v1 - Buy Signal!")- strategy.close("Long", when = Sell_1, alert_message = "v1 - Sell Signal!")+ if Sell_1+ strategy.close("Long", alert_message = "v1 - Sell Signal!")// v2 Signals⋯if v2 == true- strategy.entry("Long", strategy.long, when = Buy_2, alert_message = "v2 - Buy Signal!")+ if Buy_2+ strategy.entry("Long", strategy.long, alert_message = "v2 - Buy Signal!")- strategy.close("Long", when = Sell_2, alert_message = "v2 - Sell Signal!")+ if Sell_2+ strategy.close("Long", alert_message = "v2 - Sell Signal!") strategy.exit("Stoploss/TP", "Long", stop = v2stoploss_level, limit = v2takeprofit_level)⋯if v3 == true- strategy.entry("Long", strategy.long, when = Buy_3, alert_message = "v2 - Buy Signal!")+ if Buy_3+ strategy.entry("Long", strategy.long, alert_message = "v2 - Buy Signal!")- strategy.close("Long", when = Sell_3, alert_message = "v2 - Sell Signal!")+ if Sell_3+ strategy.close("Long", alert_message = "v2 - Sell Signal!") strategy.exit("Stoploss/TP", "Long", stop = v3stoploss_level, limit = v3takeprofit_level)Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 6 before, 6 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Bunghole-//@version=5+//@version=6strategy(overlay=true, shorttitle="Flawless Victory Strategy", default_qty_type = strategy.percent_of_equity, initial_capital = 100000, default_qty_value = 100, pyramiding = 0, title="Flawless Victory Strategy", currency = 'USD')⋯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 |
|---|---|---|---|
| Version 1 - Doesn't Use SL/TP | true | bool | entry Long close Long line 85 |
| Version 2 - Uses SL/TP | false | bool | entry Long close Long exit Stoploss/TP v2 Stoploss v2 Profit line 91 |
| Version 3 - Uses SL/TP | false | bool | entry Long close Long exit Stoploss/TP v3 Stoploss v3 Profit line 98 |
| Stop Loss % | 6.604 | float · min 0.01 | v2stoploss_level v2 Stoploss |
| Take Profit % | 2.328 | float · min 0.01 | v2takeprofit_level v2 Profit |
| Stop Loss % | 8.882 | float · min 0.01 | v3stoploss_level v3 Stoploss |
| Take Profit % | 2.317 | float · min 0.01 | v3takeprofit_level v3 Profit |
What it calculates
- RMA / Change (
rma,ta.rmain v5)max(change(src), 0), lenup · line 26 - RMA / Change (
rma,ta.rmain v5)-min(change(src), 0), lendown · line 27 - Change (
change,ta.changein v5)MFIsrcMFIupper · line 32 - Change (
change,ta.changein v5)MFIsrcMFIlower · line 33 - SMA (
sma,ta.smain v5)src1, length1basis1 · line 45 - Stdev (
stdev,ta.stdevin v5)src1, length1dev1 · line 46 - SMA (
sma,ta.smain v5)src2, length2basis2 · line 53 - Stdev (
stdev,ta.stdevin v5)src2, length2dev2 · line 54
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 | Buy_1BBBuyTrigger1 and rsiBuyGuard1 | On | 86 |
| Close Long | Sell_1BBSellTrigger1 and rsiSellGuard1 | On | 87 |
| Open Long long | Buy_2BBBuyTrigger2 and rsiBuyGuard2 | On | 92 |
| Close Long | Sell_2BBSellTrigger2 and rsiSellGuard2 | On | 93 |
| Exit Stoploss/TP stop and limit | v2 == true | On | 94 |
| Open Long long | Buy_3BBBuyTrigger3 and mfiBuyGuard3 | On | 99 |
| Close Long | Sell_3BBSellTrigger3 and rsiSellGuard3 and mfiSellGuard3 | On | 100 |
| Exit Stoploss/TP stop and limit | v3 == true | On | 101 |
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 | +21.3% | +102.5% | 6 | 83% | 1.68 | 35.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −4.9% | +5.5% | 7 | 57% | 0.73 | 26.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −54.6% | +9.8% | 6 | 50% | 0.34 | 76.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +4.1% | +8.4% | 7 | 71% | 1.17 | 34.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +39.3% | +16.7% | 10 | 80% | 1.18 | 68.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.2% | +21.5% | 5 | 60% | 0.95 | 34.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +50.8% | +148.3% | 7 | 86% | 1.83 | 46.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +7.5% | +17.1% | 7 | 86% | 1.57 | 20.8% | 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 | 100% | $52,368.10 |
| Sideways market | 0 | — | $0.00 |
| Falling market | 1 | 0% | −$31,105.40 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
22.5%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 22.5% to 22.5%; the tick is what actually happened, 22.5%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 20 Mar 2024 61,937.40 | 21 Oct 2024 69,032.00 | 215 | $11,454.50 |
| long | 23 Dec 2024 95,186.30 | 3 May 2025 96,887.10 | 131 | $1,991.54 |
| long | 6 Jun 2025 101,509.00 | 11 Jul 2025 116,010.00 | 35 | $16,206.70 |
| long | 1 Aug 2025 115,764.00 | 6 Oct 2025 123,482.00 | 66 | $8,644.23 |
| long | 22 Jan 2026 89,454.70 | 20 Aug 2026 69,334.80 | 210 | −$31,105.40 |
| long | 11 Sep 2026 76,568.70 | 22 Sep 2026 86,620.00 | 11 | $14,071.20 |
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 |
|---|---|---|---|---|---|
| Flawless Victory Strategy - 15min BTC Machine Learning Strategy this page | — | v4 strategy | +21.3% | 6 | 35.4% |
| Contrarian Scalping Counter Trend Bb Envelope Adx and Stochastic by exlux99 | sma stdev rma | v5 strategy | +1.9% | 15 | 3.2% |
| Forex Scalping 1min Bollinger Bands, RSI and ADX Trading System by exlux99 | sma stdev rma | v4 strategy | −0.0% | 3 | 0.0% |
| Best TradingView Strategy - For NASDAQ and DOW30 and other Index by The_Bigger_Bull | sma stdev rma | v5 strategy | +2.2% | 17 | 3.4% |
| ADX_TSI_Bol Band Trend Chaser by gary_trades | sma stdev rma | v4 strategy | No trades on this market | ||
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | Yes 1,000 bars in 52 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © Bunghole//@version=4strategy(overlay=true, shorttitle="Flawless Victory Strategy", default_qty_type = strategy.percent_of_equity, initial_capital = 100000, default_qty_value = 100, pyramiding = 0, title="Flawless Victory Strategy", currency = 'USD')////////// ** Inputs ** //////////// Stoploss and Profits Inputsv1 = input(true, title="Version 1 - Doesn't Use SL/TP")v2 = input(false, title="Version 2 - Uses SL/TP")v3 = input(false, title="Version 3 - Uses SL/TP")v2stoploss_input = input(6.604, title='Stop Loss %', type=input.float, minval=0.01)/100v2takeprofit_input = input(2.328, title='Take Profit %', type=input.float, minval=0.01)/100v2stoploss_level = strategy.position_avg_price * (1 - v2stoploss_input)v2takeprofit_level = strategy.position_avg_price * (1 + v2takeprofit_input)v3stoploss_input = input(8.882, title='Stop Loss %', type=input.float, minval=0.01)/100v3takeprofit_input = input(2.317, title='Take Profit %', type=input.float, minval=0.01)/100v3stoploss_level = strategy.position_avg_price * (1 - v3stoploss_input)v3takeprofit_level = strategy.position_avg_price * (1 + v3takeprofit_input)plot(v2 and v2stoploss_input and v2stoploss_level ? v2stoploss_level: na, color=color.red, style=plot.style_linebr, linewidth=2, title="v2 Stoploss")plot(v2 and v2takeprofit_input ? v2takeprofit_level: na, color=color.green, style=plot.style_linebr, linewidth=2, title="v2 Profit")plot(v3 and v3stoploss_input and v3stoploss_level ? v3stoploss_level: na, color=color.red, style=plot.style_linebr, linewidth=2, title="v3 Stoploss")plot(v3 and v3takeprofit_input ? v3takeprofit_level: na, color=color.green, style=plot.style_linebr, linewidth=2, title="v3 Profit")////////// ** Indicators ** //////////// RSIlen = 14src = closeup = rma(max(change(src), 0), len)down = rma(-min(change(src), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)// MFIMFIlength = 14MFIsrc = hlc3MFIupper = sum(volume * (change(MFIsrc) <= 0 ? 0 : MFIsrc), MFIlength)MFIlower = sum(volume * (change(MFIsrc) >= 0 ? 0 : MFIsrc), MFIlength)_rsi(MFIupper, MFIlower) => if MFIlower == 0 100 if MFIupper == 0 0 100.0 - (100.0 / (1.0 + MFIupper / MFIlower))mfi = _rsi(MFIupper, MFIlower)// v1 Bollinger Bandslength1 = 20src1 = closemult1 = 1.0basis1 = sma(src1, length1)dev1 = mult1 * stdev(src1, length1)upper1 = basis1 + dev1lower1 = basis1 - dev1// v2 Bollinger Bandslength2 = 17src2 = closemult2 = 1.0basis2 = sma(src2, length2)dev2 = mult2 * stdev(src2, length2)upper2 = basis2 + dev2lower2 = basis2 - dev2////////// ** Triggers and Guards ** //////////// v1 Strategy ParametersRSILowerLevel1 = 42RSIUpperLevel1 = 70BBBuyTrigger1 = src1 < lower1BBSellTrigger1 = src1 > upper1rsiBuyGuard1 = rsi > RSILowerLevel1rsiSellGuard1 = rsi > RSIUpperLevel1// v2 Strategy ParametersRSILowerLevel2 = 42RSIUpperLevel2 = 76BBBuyTrigger2 = src2 < lower2BBSellTrigger2 = src2 > upper2rsiBuyGuard2 = rsi > RSILowerLevel2rsiSellGuard2 = rsi > RSIUpperLevel2// v3 Strategy ParametersMFILowerLevel3 = 60RSIUpperLevel3 = 65MFIUpperLevel3 = 64BBBuyTrigger3 = src1 < lower1BBSellTrigger3 = src1 > upper1mfiBuyGuard3 = mfi < MFILowerLevel3rsiSellGuard3 = rsi > RSIUpperLevel3mfiSellGuard3 = mfi > MFIUpperLevel3 //////////** Strategy Signals ** //////////// v1 SignalsBuy_1 = BBBuyTrigger1 and rsiBuyGuard1Sell_1 = BBSellTrigger1 and rsiSellGuard1if v1 == true strategy.entry("Long", strategy.long, when = Buy_1, alert_message = "v1 - Buy Signal!") strategy.close("Long", when = Sell_1, alert_message = "v1 - Sell Signal!")// v2 SignalsBuy_2 = BBBuyTrigger2 and rsiBuyGuard2Sell_2 = BBSellTrigger2 and rsiSellGuard2if v2 == true strategy.entry("Long", strategy.long, when = Buy_2, alert_message = "v2 - Buy Signal!") strategy.close("Long", when = Sell_2, alert_message = "v2 - Sell Signal!") strategy.exit("Stoploss/TP", "Long", stop = v2stoploss_level, limit = v2takeprofit_level)// v3 SignalsBuy_3 = BBBuyTrigger3 and mfiBuyGuard3Sell_3 = BBSellTrigger3 and rsiSellGuard3 and mfiSellGuard3if v3 == true strategy.entry("Long", strategy.long, when = Buy_3, alert_message = "v2 - Buy Signal!") strategy.close("Long", when = Sell_3, alert_message = "v2 - Sell Signal!") strategy.exit("Stoploss/TP", "Long", stop = v3stoploss_level, limit = v3takeprofit_level)