Pine Script v5 · Strategy
Risk to Reward - FIXED SL Backtester
A Pine Script v5 strategy built on SMA (low, 14), RMA or TR (true, 14) and Lowest (low, 8). It has 2 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 33% of equity and pays 0.075% commission. 16 settings; defaults include External indicator close, External Value 100 and 🌀 Risk Type Risk To Reward.
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 Risk to Reward - FIXED SL Backtester repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Risk to Reward - FIXED SL Backtester do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Risk to Reward - FIXED SL Backtester run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Risk to Reward - FIXED SL Backtester use a stop loss?
- Yes
- strategy.exit sets a stop on line 90.
- Does Risk to Reward - FIXED SL Backtester run in Zeal Terminal?
- Yes
- It compiles in 34 ms and runs 1,000 bars in 68 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- RMA
- Lowest
- VWAP
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $10,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.
-
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 |
|---|---|---|---|
| ➞ Main Core Settings 🔸 | |||
| External indicator Select external indicator plot | close | source | deal_start_condition |
| External Value Plot Value | 100 | int | deal_start_condition |
| ➞ TP/SL ( Risk System ) 🔸 | |||
| 🌀 Risk TypeSelect Which risk system you wanna use ?! Risk to Reward or fixed system | Risk To Reward | string · options ['Risk To Reward', 'Fixed TP & SL'] | longTP sl |
| ➞ Risk to Reward 🔸 | |||
| Risk To Reward RatioYour Risk to Reward Ratio ? 2:1 then put 2 | 1.5 | float · min 0 · step 0.1 | longTP |
| ⬇️ Stoploss Type Select the Stoploss Method | ATR SL | string · options ["ATR SL", "Pivot low", "VWAP SL"] | line 58 |
| ATR Factor Only used with ATR SL | 1.4 | float · step 0.1 | x2 |
| Pivot Lookback looks for lower low ,Only used with Pivot Low | 8 | int · min 0 | stopLong |
| Vwap Multiplier Gets the SMMA value ,Only used with SMMA SL | 2.5 | float · step 0.1 | longstoploss |
| ➞ Fixed TP & SL 🔸 | |||
| Fixed TP | 1.5 | float · min 0 · step 0.1 | longTP |
| Fixed SL | 1.5 | float · min 0 · step 0.1 | sl |
| ➞ BreakEven Settings 🔸 | |||
| BreakEven ?Breakeven w | true | bool | exit Long 3 AVG Price |
| Risk To Reward Ratio | 1.0 | float · step 0.1 | BreakevenTP |
| Percent Above EntryMUST be higher than '0'. This input front loads the new breakeven stop loss so that it is actually in profit. | 0.1 | float · step 0.1 | BreakevenSL |
| Backtest date range | |||
| Limit Date Range | true | bool | line 75 |
| Start Time | timestamp('01 Aug 2022 00:00 +0000') | time | in_date_range |
| End Time | timestamp('31 Dec 2025 00:00 +0000') | time | in_date_range |
What it calculates
- SMAlow, 14
smma · line 28 - RMA / TRta.tr(true), 14
x2 · line 49 - Lowestlow, Pivot Lookback (8)
stopLong · line 50 - VWAP / TRta.tr(true)
vwap · line 51
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 | (in_date_range and longCondition) | On | 89 |
| Exit Long 3 stop and limit | every bar | On | 90 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.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 | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 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.
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 |
|---|---|---|---|---|---|
| Risk to Reward - FIXED SL Backtester this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| JBravo Swing with GoGo Juice by bradvaughn | sma vwap lowest | v4 strategy | +68.7% | 93 | 22.3% |
| ATR GOD Strategy by TradeSmart (PineConnector-compatible) by TradeSmart22 | tr lowest sma rma | v5 strategy | No trades on this market | ||
| Strategy Myth-Busting #7 - MACDBB+SSL+VSF - [MYN] by myncrypto | sma tr lowest rma | v5 strategy | No trades on this market | ||
| Stochastic RSI Strategy (with SMA and VWAP Filters) by thedoggwalker | lowest sma vwap | v4 strategy | −0.0% | 3 | 0.0% |
| Bagheri IG Ether by Bagheri_IG | lowest rma sma | v4 strategy | +0.0% | 3 | 0.0% |
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?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © TZack88-//@version=5+//@version=6strategy(title='RR - FIXED SL Backtester', shorttitle='ZCrypto Backtester',overlay=true,pyramiding=1, initial_capital=10000,⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 34 ms | Yes 1,000 bars in 68 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/// © TZack88//@version=5strategy(title='RR - FIXED SL Backtester', shorttitle='ZCrypto Backtester',overlay=true,pyramiding=1, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.075,default_qty_value = 33, default_qty_type = strategy.percent_of_equity) var float slVal = 0.0float longTP = navar float SL = nafloat BreakevenTP = nafloat BreakevenSL = navar float TPlong = nadeal_start_condition = falsevar float long_sl_level = na color bgray = color.rgb(128, 223, 236, 81)color WHITE = color.rgb(210, 210, 210)color red = color.rgb(163, 46, 46, 29)color white = color.rgb(248, 248, 248, 14)color olive = color.olivecolor blue = color.rgb(23, 43, 77)color Green = color.rgb(10, 218, 103, 34)string core = "➞ Main Core Settings 🔸"string Breakeeven = "➞ Breakeven Settings 🔸" string SLZ2 = "➞ TP/SL ( Risk System ) 🔸"string RRS = "➞ Risk to Reward 🔸"string FTPS = "➞ Fixed TP & SL 🔸"string BES = "➞ BreakEven Settings 🔸"float smma = ta.sma(low,14)string SLZ2TOOL = "Select Which risk system you wanna use ?! Risk to Reward or fixed system"string RRT = "Your Risk to Reward Ratio ? 2:1 then put 2"string _tooltip3 = "Select external indicator plot"string SLSelect = "Select the Stoploss Method"float external_indicator = input.source(defval=close, title='External indicator ', group=core, tooltip=_tooltip3,inline = "00")float deal_start_value = input.int(defval=100, title='External Value ', group=core, tooltip="Plot Value",inline = "01")bool Risktype = input.string('Risk To Reward', title = ' 🌀 Risk Type',group=SLZ2,inline = "000",options = ['Risk To Reward', 'Fixed TP & SL'],tooltip = SLZ2TOOL) == 'Risk To Reward'float RRTP = input.float(1.5, minval=0,step = 0.1,title="Risk To Reward Ratio",group=RRS,inline = "01",tooltip = RRT)string stoploss = input.string("ATR SL", title=" ⬇️ Stoploss Type ", options=["ATR SL", "Pivot low", "VWAP SL"], group=RRS,inline = "02",tooltip = SLSelect)float ATRSL = input.float(1.4," ATR Factor ",step = 0.1,group = RRS,inline = "03",tooltip = "Only used with ATR SL")int LB = input.int(8, minval=0,title=" Pivot Lookback ",group=RRS,inline = "04",tooltip = "looks for lower low ,Only used with Pivot Low")float VWAPSL = input.float(2.5," Vwap Multiplier ",step = 0.1,group=RRS,inline = "05",tooltip = "Gets the SMMA value ,Only used with SMMA SL")float FixedTP = input.float(1.5, minval=0,step = 0.1,title="Fixed TP",group=FTPS,inline = "01") / 100float FixedSL = input.float(1.5, minval=0,step = 0.1,title="Fixed SL",group=FTPS,inline = "01") / 100bool breakon = input.bool(true,"BreakEven ?" ,group = BES, inline="06",tooltip = "Breakeven w")float breakRR = input.float(1.0, " Risk To Reward Ratio",step = 0.1, group = BES, inline="07")float BEper = input.float(0.1, " Percent Above Entry",step = 0.1, group = BES, inline="08",tooltip="MUST be higher than '0'. This input front loads the new breakeven stop loss so that it is actually in profit.")/100deal_start_condition := if external_indicator == deal_start_value true//-----SL core calculation-----{x2 = low - ta.rma(ta.tr(true), 14) * ATRSLstopLong = ta.lowest(low,LB)vwap = math.sum(ta.vwap(ta.tr(true)),14) * volumevolumz = math.sum(volume,14)atr_vwap_volume = math.abs(vwap / volumz)longstoploss = low - atr_vwap_volume * VWAPSL//}// Lets get the SL and return it my_stop() => switch stoploss "ATR SL" => x2 "Pivot low" => stopLong "SMMA SL" => longstoplosssl = Risktype ? my_stop() : close * (1 - FixedSL)// lets set the SL , TP Valuesif deal_start_condition and strategy.position_size == 0 slVal:= slelse slVal:= slVal longDiffSL = math.abs(close - slVal)longTP := deal_start_condition and strategy.position_size == 0 ? Risktype ? close + (RRTP * longDiffSL) : close * (1 + FixedTP) : longTP[1]// -- Backtest Date ?! {limit_date_range = input.bool(title='Limit Date Range', defval=true, group='Backtest date range')start_time = input.time(defval=timestamp('01 Aug 2022 00:00 +0000'), title='Start Time', group='Backtest date range')end_time = input.time(defval=timestamp('31 Dec 2025 00:00 +0000'), title='End Time', group='Backtest date range')in_date_range = trueif limit_date_range in_date_range := time >= start_time and time <= end_time else in_date_range := true//-- }longCondition = (deal_start_condition== true) and strategy.position_size == 0//BreakevenBreakevenTP := longCondition ? close + (breakRR * longDiffSL) : BreakevenTP[1]BREAKPLOT = strategy.position_size > 0 ? BreakevenTP : naBreakevenSL := strategy.position_size > 0 ? strategy.position_avg_price * (1 + BEper) :nalong_tp_hit = close >= BreakevenTP or high>= BreakevenTPlong_sl_level := longCondition ? slVal : long_tp_hit ? BreakevenSL: long_sl_level[1]if (in_date_range and longCondition) strategy.entry("LONG", strategy.long ) strategy.exit("Long 3","LONG", limit=longTP, stop=(breakon ? long_sl_level : slVal), comment_profit = "TP HIT", comment_loss = breakon ? "BE Close" : "Loss" ) // PLOTSSLplot = strategy.position_size > 0 ? slVal : naSSL = plot(SLplot, title='LONG STOP LOSS', linewidth=2, style=plot.style_linebr, color=red)longPlotTP = strategy.position_size > 0 ? longTP : naTTP = plot(longPlotTP, title='LONG TAKE PROFIT', linewidth=2, style=plot.style_linebr, color=Green)avg = plot( strategy.position_avg_price, style = plot.style_linebr,color=WHITE )BREKEVENLINE = strategy.position_size > 0 ? long_sl_level : na plot(breakon ? BREKEVENLINE : na, 'AVG Price',color=color.white, style=plot.style_linebr,editable = false,linewidth = 2)fill(TTP, avg, color = color.new(Green,80))fill(avg, SSL, color =color.new(red,80))