Pine Script v4 · Strategy
SSL Backtester With ATR SL TP and Money Management
A Pine Script v4 strategy built on SMA (high, 16) and ATR (14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 8 settings; defaults include SSL Period 16, ATR Period 14 and ATR Stop Loss Factor 1.5.
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 SSL Backtester With ATR SL TP and Money Management repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 16 of 16 trades.
- How did SSL Backtester With ATR SL TP and Money Management do on BTCUSDT 1D with default settings?
- +8.48%
- From 26 Jan 2024 to 21 Oct 2026, over 55 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can SSL Backtester With ATR SL TP and Money Management be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does SSL Backtester With ATR SL TP and Money Management use a stop loss?
- Yes
- strategy.exit sets a stop on line 45, 50.
- Does SSL Backtester With ATR SL TP and Money Management run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 29 ms, in the browser.
BTCUSDT · 1D · default settings
- SSL
- SSL
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +8.48%
- $8,484.41
- Buy and hold
- +102.5%
- same period
- Closed trades
- 55
- 37 won · 18 lost
- Profitable
- 67.3%
- of closed trades
- Profit factor
- 1.50
- gross profit ÷ gross loss
- Max drawdown
- 3.94%
- −$3,940.40
One run with the author's default settings, $100,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.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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, atr → ta.atr.
v4 → v5
DiffersTrades differ: 55 before, 55 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 19: sma → ta.sma
- Line 20: sma → ta.sma
- Line 27: atr → ta.atr
⋯// © comiclysm-//@version=4+//@version=5strategy("SSL Backtester", overlay=false)⋯ -sma_high = sma(high, ssl_period)+sma_high = ta.sma(high, ssl_period)-sma_low = sma(low, ssl_period)+sma_low = ta.sma(low, ssl_period)ssl_value = 0⋯ -atr = atr(atr_period)+atr = ta.atr(atr_period)//--TRADE LOGIC----------------------------------------------------------⋯Clean v5
VerifiedSame 55 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: input() → input.bool()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.float()
- Line 12: input() → input.float()
- Line 13: input() → input.bool()
- Line 14: input() → input.int()
- Line 15: input() → input.float()
⋯//--USER INPUTS-two_digit = input(false, "Check this for 2-digit pairs (JPY, Gold, Etc)")+two_digit = input.bool(false, "Check this for 2-digit pairs (JPY, Gold, Etc)")-ssl_period = input(16, "SSL Period")+ssl_period = input.int(16, "SSL Period")-atr_period = input(14, "ATR Period")+atr_period = input.int(14, "ATR Period")-atr_stop_factor = input(1.5, "ATR Stop Loss Factor")+atr_stop_factor = input.float(1.5, "ATR Stop Loss Factor")-atr_target_factor = input(1.0, "ATR Target Factor")+atr_target_factor = input.float(1.0, "ATR Target Factor")-use_mm = input(true, "Check this to use Money Management")+use_mm = input.bool(true, "Check this to use Money Management")-position_size = input(1000, "Position size (for Fixed Risk)")+position_size = input.int(1000, "Position size (for Fixed Risk)")-risk = input(0.01, "Risk % in Decimal Form")+risk = input.float(0.01, "Risk % in Decimal Form")//--INDICATORS------------------------------------------------------------⋯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: 55 before, 55 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.
⋯// © comiclysm-//@version=5+//@version=6strategy("SSL Backtester", overlay=false)⋯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 |
|---|---|---|---|
| Check this for 2-digit pairs (JPY, Gold, Etc) | false | bool | line 34 |
| SSL Period | 16 | int | sma_high sma_low |
| ATR Period | 14 | int | atr |
| ATR Stop Loss Factor | 1.5 | float | risk_pips stop_loss |
| ATR Target Factor | 1.0 | float | target |
| Check this to use Money Management | true | bool | final_risk |
| Position size (for Fixed Risk) | 1000 | int | final_risk |
| Risk % in Decimal Form | 0.01 | float | risk_in_value |
What it calculates
- SMA (
sma,ta.smain v5)high, SSL Period (16)sma_high · line 19 - SMA (
sma,ta.smain v5)low, SSL Period (16)sma_low · line 20 - ATR (
atr,ta.atrin v5)ATR Period (14)atr · line 27
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 | (signal_long) | On | 44 |
| Exit X stop and limit | (signal_long) | On | 45 |
| Open Short short | (signal_short) | On | 49 |
| Exit X stop and limit | (signal_short) | On | 50 |
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 | +8.5% | +102.5% | 55 | 67% | 1.50 | 3.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +4.3% | +5.5% | 64 | 63% | 1.19 | 4.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 59 | 59% | 1.00 | 3.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.9% | +8.4% | 71 | 51% | 0.77 | 11.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +8.6% | +16.7% | 55 | 69% | 1.48 | 2.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +6.6% | +21.5% | 59 | 63% | 1.34 | 4.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1.9% | +148.3% | 56 | 61% | 1.09 | 3.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.9% | +17.1% | 71 | 59% | 1.03 | 7.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 | 18 | 61% | $390.58 |
| Sideways market | 26 | 73% | $6,061.05 |
| Falling market | 11 | 64% | $2,032.78 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.9%
The 95th percentile of the worst drawdown when the same 55 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.3% to 5.9%; the tick is what actually happened, 3.9%. Order luck alone moves it this much.
All 55 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 20 Mar 2024 61,937.40 | 20 Mar 2024 67,619.80 | 0 | −$1,000.00 |
| long | 29 Mar 2024 70,780.60 | 2 Apr 2024 65,120.50 | 4 | −$990.00 |
| short | 3 Apr 2024 65,464.00 | 8 Apr 2024 70,626.90 | 5 | −$980.10 |
| long | 9 Apr 2024 71,620.00 | 12 Apr 2024 66,794.20 | 3 | −$970.30 |
| short | 13 Apr 2024 67,116.50 | 13 Apr 2024 63,742.70 | 0 | $640.40 |
| long | 16 May 2024 66,206.50 | 20 May 2024 69,032.30 | 4 | $644.67 |
| short | 12 Jun 2024 67,314.20 | 14 Jun 2024 65,230.00 | 2 | $648.96 |
| long | 15 Jul 2024 60,797.90 | 15 Jul 2024 63,126.90 | 0 | $653.29 |
| short | 1 Aug 2024 64,628.00 | 2 Aug 2024 62,229.00 | 1 | $657.65 |
| long | 22 Aug 2024 61,156.00 | 23 Aug 2024 64,080.70 | 1 | $662.03 |
| short | 29 Aug 2024 59,034.90 | 4 Sep 2024 56,251.80 | 6 | $666.45 |
| long | 14 Sep 2024 60,498.00 | 19 Sep 2024 62,955.80 | 5 | $670.89 |
| short | 2 Oct 2024 60,804.90 | 7 Oct 2024 64,079.90 | 5 | −$1,013.31 |
| long | 15 Oct 2024 66,084.00 | 16 Oct 2024 68,199.80 | 1 | $668.60 |
| short | 20 Dec 2024 97,461.90 | 20 Dec 2024 93,123.50 | 0 | $673.06 |
| long | 4 Jan 2025 98,174.20 | 6 Jan 2025 101,881.00 | 2 | $677.55 |
| short | 10 Jan 2025 92,552.50 | 15 Jan 2025 98,252.20 | 5 | −$1,023.10 |
| long | 16 Jan 2025 100,497.00 | 17 Jan 2025 104,187.00 | 1 | $675.25 |
| short | 2 Feb 2025 100,636.00 | 2 Feb 2025 96,606.60 | 0 | $679.75 |
| long | 21 Feb 2025 98,305.00 | 24 Feb 2025 93,511.70 | 3 | −$1,026.42 |
| short | 25 Feb 2025 91,552.90 | 25 Feb 2025 88,377.20 | 0 | $677.44 |
| long | 20 Mar 2025 86,845.90 | 30 Mar 2025 82,648.50 | 10 | −$662.84 |
| short | 30 Mar 2025 82,648.50 | 2 Apr 2025 87,777.50 | 3 | −$1,022.93 |
| long | 13 Apr 2025 85,276.90 | 22 Apr 2025 89,469.40 | 9 | $670.71 |
| short | 31 May 2025 103,985.00 | 5 Jun 2025 100,995.00 | 5 | $675.18 |
| long | 10 Jun 2025 110,263.00 | 12 Jun 2025 105,785.00 | 2 | −$1,019.53 |
| short | 21 Jun 2025 103,298.00 | 22 Jun 2025 100,404.00 | 1 | $672.89 |
| long | 26 Jun 2025 107,341.00 | 3 Jul 2025 110,478.00 | 7 | $677.37 |
| short | 1 Aug 2025 115,764.00 | 1 Aug 2025 112,970.00 | 0 | $681.89 |
| long | 11 Aug 2025 119,294.00 | 11 Aug 2025 121,886.00 | 0 | $686.37 |
| short | 20 Aug 2025 112,873.00 | 22 Aug 2025 117,226.00 | 2 | −$1,036.52 |
| long | 11 Sep 2025 113,960.00 | 15 Sep 2025 116,726.00 | 4 | $684.10 |
| short | 23 Sep 2025 112,651.00 | 25 Sep 2025 110,398.00 | 2 | $688.66 |
| long | 2 Oct 2025 118,595.00 | 3 Oct 2025 121,121.00 | 1 | $693.25 |
| short | 11 Oct 2025 112,774.00 | 16 Oct 2025 108,578.00 | 5 | $697.87 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 108,833.00 | 3 | −$1,053.80 |
| short | 31 Oct 2025 108,323.00 | 4 Nov 2025 104,426.00 | 4 | $695.50 |
| long | 3 Dec 2025 91,277.90 | 15 Dec 2025 88,172.20 | 12 | −$548.93 |
| short | 15 Dec 2025 88,172.20 | 18 Dec 2025 84,699.70 | 3 | $700.14 |
| long | 3 Jan 2026 89,995.10 | 5 Jan 2026 92,609.40 | 2 | $701.15 |
| short | 21 Jan 2026 88,427.70 | 29 Jan 2026 85,953.60 | 8 | $705.82 |
| long | 3 Mar 2026 68,830.10 | 4 Mar 2026 72,284.40 | 1 | $710.53 |
| short | 22 Mar 2026 68,918.10 | 27 Mar 2026 65,983.60 | 5 | $715.26 |
| long | 8 Apr 2026 71,924.20 | 13 Apr 2026 74,532.00 | 5 | $720.03 |
| short | 17 May 2026 78,148.10 | 22 May 2026 75,993.60 | 5 | $724.84 |
| long | 16 Jun 2026 66,328.70 | 18 Jun 2026 62,873.20 | 2 | −$1,094.50 |
| short | 24 Jun 2026 62,734.60 | 24 Jun 2026 60,609.10 | 0 | $722.37 |
| long | 5 Jul 2026 63,144.00 | 15 Jul 2026 65,345.20 | 10 | $727.18 |
| short | 28 Jul 2026 63,755.90 | 8 Aug 2026 64,923.20 | 11 | −$496.51 |
| long | 8 Aug 2026 64,923.20 | 14 Aug 2026 62,649.50 | 6 | −$1,098.06 |
| short | 15 Aug 2026 63,043.60 | 18 Aug 2026 64,532.10 | 3 | −$798.06 |
| long | 18 Aug 2026 64,532.10 | 19 Aug 2026 65,803.40 | 1 | $721.40 |
| short | 11 Sep 2026 76,568.70 | 18 Sep 2026 79,903.20 | 7 | −$1,081.33 |
| long | 19 Sep 2026 80,883.90 | 21 Sep 2026 83,236.50 | 2 | $713.69 |
| short | 8 Oct 2026 83,321.80 | 8 Oct 2026 81,134.60 | 0 | $718.44 |
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 |
|---|---|---|---|---|---|
| SSL Backtester With ATR SL TP and Money Management this page | — | v4 strategy | +8.5% | 55 | 3.9% |
| I11L - Better Buy Low Volatility or High Volatility- by I11L | atr sma | v5 strategy | +19.2% | 83 | 37.4% |
| Vortex Cross w-MA Confirmation by DraftVenture | atr sma | v5 strategy | +2.4% | 52 | 4.7% |
| Configurable Multi MA Crossover Voting System by levieux | sma atr | v5 strategy | +28.5% | 5 | 39.4% |
| Swing Trend Strategy by Inkedlau | sma atr | v5 strategy | +11.2% | 5 | 16.2% |
| Baseline Cross Qualifier Volatility Strategy with HMA Trend Bias by sevencampbell | sma atr | v5 strategy | −1.4% | 214 | 1.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | Yes 1,000 bars in 29 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/// © comiclysm//@version=4strategy("SSL Backtester", overlay=false)//--This strategy will simply test the effectiveness of the SSL using//--money management and an ATR-derived stop loss//--USER INPUTStwo_digit = input(false, "Check this for 2-digit pairs (JPY, Gold, Etc)")ssl_period = input(16, "SSL Period")atr_period = input(14, "ATR Period")atr_stop_factor = input(1.5, "ATR Stop Loss Factor")atr_target_factor = input(1.0, "ATR Target Factor")use_mm = input(true, "Check this to use Money Management")position_size = input(1000, "Position size (for Fixed Risk)")risk = input(0.01, "Risk % in Decimal Form")//--INDICATORS------------------------------------------------------------ //--SSL sma_high = sma(high, ssl_period)sma_low = sma(low, ssl_period)ssl_value = 0ssl_value := close > sma_high ? 1 : close < sma_low ? -1 : ssl_value[1]ssl_low = ssl_value < 0 ? sma_high : sma_lowssl_high = ssl_value < 0 ? sma_low : sma_high //--Average True Range atr = atr(atr_period)//--TRADE LOGIC----------------------------------------------------------signal_long = ssl_value > 0 and ssl_value[1] < 0signal_short = ssl_value < 0 and ssl_value[1] > 0//--RISK MANAGMENT-------------------------------------------------------balance = strategy.netprofit + strategy.initial_capitalrisk_pips = atr*10000*atr_stop_factorif(two_digit) risk_pips := risk_pips / 100risk_in_value = balance * riskpoint_value = syminfo.pointvaluerisk_lots = risk_in_value / point_value / risk_pipsfinal_risk = use_mm ? risk_lots * 10000 : position_size//--TRADE EXECUTION-----------------------------------------------------if (signal_long) stop_loss = close - atr * atr_stop_factor target = close + atr * atr_target_factor strategy.entry("Long", strategy.long, final_risk) strategy.exit("X", "Long", stop=stop_loss, limit=target)if (signal_short) stop_loss = close + atr * atr_stop_factor target = close - atr * atr_target_factor strategy.entry("Short", strategy.short, final_risk) strategy.exit("X", "Short", stop=stop_loss, limit=target) //--PLOTTING-----------------------------------------------------------plot(ssl_low, "SSL", color.red, linewidth=1)plot(ssl_high, "SSL", color.lime, linewidth=1)