Pine Script v5 · Strategy
Fixed price Stop Loss [Takazudo]
A Pine Script v5 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 9 settings; defaults include Risk price for each entry 100, Deposit currency USD and Entry band bar count 100.
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 Fixed price Stop Loss [Takazudo] repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- Does Fixed price Stop Loss [Takazudo] 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 Fixed price Stop Loss [Takazudo] use a stop loss?
- Yes
- strategy.exit sets a stop on line 173, 174.
- Does Fixed price Stop Loss [Takazudo] run in Zeal Terminal?
- Yes
- It compiles in 34 ms and runs 1,000 bars in 305 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- 0.0%
- 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, $0 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.
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 |
|---|---|---|---|
| Money management | |||
| Risk price for each entry | 100 | int · min 1 | line 92 |
| Deposit currency | USD | string · options ["USD"] | _deposit depositExchangeRate |
| Entry strategy | |||
| Entry band bar count | 100 | int · min 1 | line 111 line 116 |
| Backtesting range | |||
| From Year | 2016 | int · min 1970 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Day | 1 | int · min 1 · max 31 | startDate |
| To Year | 2020 | int · min 1970 | finishDate |
| To Month | 12 | int · min 1 · max 12 | finishDate |
| To Day | 31 | int · min 1 · max 31 | finishDate |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 | shouldMakeEntryLong | On | 168 |
| Open Short short | shouldMakeEntryShort | On | 171 |
| Exit Long-SL/TP stop | every bar | On | 173 |
| Exit Short-SL/TP stop | every bar | On | 174 |
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 data1 request.security call(s), none with lookahead on.
- 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% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6//@author=Takazudo⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 34 ms | With a workaround 1,000 bars in 305 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 168, 171) so the engine trades the way the script says. 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///@version=5//@author=Takazudostrategy("Fixed price SL", overlay=true, default_qty_type=strategy.fixed, initial_capital=0, currency=currency.USD)var COLOR_TRANSPARENT = color.new(#000000, 100)var COLOR_ENTRY_BAND = color.new(#43A6F5, 30)var COLOR_RANGE_BREAK_BULL = color.new(#315F2E, 80)var COLOR_RANGE_BREAK_BEAR = color.new(#802A1C, 80)//============================================================================// config//============================================================================// Money management_g1 = 'Money management'var config_riskPrice = input.int(100, minval=1, title="Risk price for each entry", group=_g1)var config_depositCurrency = input.string(title="Deposit currency", defval="USD", options=["USD"], group=_g1)// Entry strategy_g2 = 'Entry strategy'var config_entryBandBars = input.int(defval = 100, title = "Entry band bar count", minval=1, group=_g2)// Backtesting range_g3 = 'Backtesting range'fromYear = input.int(defval = 2016, title = "From Year", minval = 1970, group=_g3)fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12, group=_g3)fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31, group=_g3)toYear = input.int(defval = 2020, title = "To Year", minval = 1970, group=_g3)toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12, group=_g3)toDay = input.int(defval = 31, title = "To Day", minval = 1, maxval = 31, group=_g3)//============================================================================// exchange calculations//============================================================================// mico pip size calculation// ex1: AUDCAD -> 0.0001// ex2: USDJPY -> 0.01f_calcMicroPipSize() => _base = syminfo.basecurrency _quote = syminfo.currency _result = 0.0001 if _quote == 'JPY' _result := _result * 100 if _base == 'BTC' _result := _result * 100 _result// convert price to pipsf_convertPriceToPips(_price) => _microPipSize = f_calcMicroPipSize() _price / _microPipSize// calculate exchange rate between deposit and quote currencyf_calcDepositExchangeSymbolId() => _result = '' _deposit = config_depositCurrency _quote = syminfo.currency if (_deposit == 'USD') and (_quote == 'USD') _result := na if (_deposit == 'USD') and (_quote == 'AUD') _result := 'OANDA:AUDUSD' if (_deposit == 'EUR') and (_quote == 'USD') _result := 'OANDA:EURUSD' if (_deposit == 'USD') and (_quote == 'GBP') _result := 'OANDA:GBPUSD' if (_deposit == 'USD') and (_quote == 'NZD') _result := 'OANDA:NZDUSD' if (_deposit == 'USD') and (_quote == 'CAD') _result := 'OANDA:USDCAD' if (_deposit == 'USD') and (_quote == 'CHF') _result := 'OANDA:USDCHF' if (_deposit == 'USD') and (_quote == 'JPY') _result := 'OANDA:USDJPY' _result// Let's say we need CAD to USD exchange// However there's only "OANDA:USDCAD" symbol.// Then we need to invert the exhchange rate.// this function tells us whether we should invert the rate or notf_calcShouldInvert() => _result = false _deposit = config_depositCurrency _quote = syminfo.currency if (_deposit == 'USD') and (_quote == 'CAD') _result := true if (_deposit == 'USD') and (_quote == 'CHF') _result := true if (_deposit == 'USD') and (_quote == 'JPY') _result := true _result// calculate how much quantity should I buy or sellf_calcQuantitiesForEntry(_depositExchangeRate, _slPips) => _microPipSize = f_calcMicroPipSize() _priceForEachPipAsDeposit = _microPipSize * _depositExchangeRate _losePriceOnSl = _priceForEachPipAsDeposit * _slPips math.floor(config_riskPrice / _losePriceOnSl)//============================================================================// Quantity calculation//============================================================================depositExchangeSymbolId = f_calcDepositExchangeSymbolId()// calculate deposit exchange raterate = request.security(depositExchangeSymbolId, timeframe.period, hl2)shouldInvert = f_calcShouldInvert()depositExchangeRate = if config_depositCurrency == syminfo.currency // if USDUSD, no exchange of course 1else // else, USDCAD to CADUSD invert if we need shouldInvert ? (1 / rate) : rate//============================================================================// Range Edge calculation//============================================================================f_calcEntryBand_high() => _highest = math.max(open[3], close[3]) for i = 4 to (config_entryBandBars - 1) _highest := math.max(_highest, open[i], close[i]) _highestf_calcEntryBand_low() => _lowest = math.min(open[3], close[3]) for i = 4 to (config_entryBandBars - 1) _lowest := math.min(_lowest, open[i], close[i]) _lowestentryBand_high = f_calcEntryBand_high()entryBand_low = f_calcEntryBand_low()entryBand_height = entryBand_high - entryBand_lowplot(entryBand_high, color=COLOR_ENTRY_BAND, linewidth=1)plot(entryBand_low, color=COLOR_ENTRY_BAND, linewidth=1)rangeBreakDetected_long = entryBand_high < closerangeBreakDetected_short = entryBand_low > closeshouldMakeEntryLong = (strategy.position_size == 0) and rangeBreakDetected_longshouldMakeEntryShort = (strategy.position_size == 0) and rangeBreakDetected_short//============================================================================// SL & Quantity//============================================================================var sl_long = hl2var sl_short = hl2entryQty = 0slPips = 0.0// just show info bubblef_showEntryInfo(_isLong) => _str = 'SL pips: ' + str.tostring(slPips) + '\n' + 'Qty: ' + str.tostring(entryQty) _bandHeight = entryBand_high - entryBand_low _y = _isLong ? (entryBand_low + _bandHeight * 1/4) : (entryBand_high - _bandHeight * 1/4) _style = _isLong ? label.style_label_up : label.style_label_down label.new(bar_index, _y, _str, size=size.large, style=_style)if shouldMakeEntryLong sl_long := (entryBand_high + entryBand_low) / 2 slPips := f_convertPriceToPips(close - sl_long) entryQty := f_calcQuantitiesForEntry(depositExchangeRate, slPips)if shouldMakeEntryShort sl_short := (entryBand_high + entryBand_low) / 2 slPips := f_convertPriceToPips(sl_short - close) entryQty := f_calcQuantitiesForEntry(depositExchangeRate, slPips)// trailing SLif strategy.position_size > 0 sl_long := math.max(sl_long, entryBand_low)if strategy.position_size < 0 sl_short := math.min(sl_short, entryBand_high)//============================================================================// backtest duration//============================================================================// Calculate start/end date and time conditionstartDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)//============================================================================// make entries//============================================================================if (time >= startDate and time <= finishDate) if shouldMakeEntryLong strategy.entry(id="Long", direction=strategy.long, stop=close, qty=entryQty) f_showEntryInfo(true) if shouldMakeEntryShort strategy.entry(id="Short", direction=strategy.short, stop=close, qty=entryQty) f_showEntryInfo(false)strategy.exit('Long-SL/TP', 'Long', stop=sl_long)strategy.exit('Short-SL/TP', 'Short', stop=sl_short)//============================================================================// plot misc//============================================================================sl = strategy.position_size > 0 ? sl_long : strategy.position_size < 0 ? sl_short : naplot(sl, color=color.red, style=plot.style_cross, linewidth=2, title="SL")value_bgcolor = rangeBreakDetected_long ? COLOR_RANGE_BREAK_BULL : rangeBreakDetected_short ? COLOR_RANGE_BREAK_BEAR : COLOR_TRANSPARENTbgcolor(value_bgcolor)