Pine Script v4 · Strategy
STRATEGY R18-F-BTC
A Pine Script v4 strategy built on EMA (symClose, 15), Highest (i, 100) and Lowest (i, 100). It has 6 order rules, 4 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. 7 settings; defaults include Symbol BINANCE:BTCUSDT, Long Stop Loss (%) 2.5 and Short Stop Loss (%) 2.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 STRATEGY R18-F-BTC repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did STRATEGY R18-F-BTC do on BTCUSDT 1D with default settings?
- −8.56%
- From 26 Jan 2024 to 21 Oct 2026, over 11 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can STRATEGY R18-F-BTC 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 STRATEGY R18-F-BTC use a stop loss?
- Yes
- strategy.exit sets a stop on line 53, 55.
- Does STRATEGY R18-F-BTC run in Zeal Terminal?
- Yes
- It compiles in 18 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- Highest
- Lowest
- Lowest
- Lowest
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −8.56%
- −$8,558.22
- Buy and hold
- +102.5%
- same period
- Closed trades
- 11
- 2 won · 9 lost
- Profitable
- 18.2%
- of closed trades
- Profit factor
- 0.61
- gross profit ÷ gross loss
- Max drawdown
- 14.41%
- −$15,398.20
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.
-
Note
Uses an argument v6 removed
when = on line 43, 46, 48, 50. 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 security → request.security, ema → ta.ema, highest → ta.highest, lowest → ta.lowest, rsi → ta.rsi, crossover → ta.crossover, sma → ta.sma, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 43, 46, 48, 50). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 11 before, 12 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.symbol) → input.symbol()
- Line 22: input(type = input.bool) → input.bool()
- Line 23: security → request.security
- Line 24: security → request.security
- Line 25: security → request.security
18 more edits
- Line 26: ema → ta.ema
- Line 26: ema → ta.ema
- Line 27: ema → ta.ema
- Line 28: highest → ta.highest
- Line 29: lowest → ta.lowest
- Line 32: rsi → ta.rsi
- Line 35: lowest → ta.lowest
- Line 35: highest → ta.highest
- Line 35: lowest → ta.lowest
- Line 36: lowest → ta.lowest
- Line 36: highest → ta.highest
- Line 36: lowest → ta.lowest
- Line 38: crossover → ta.crossover
- Line 38: sma → ta.sma
- Line 38: sma → ta.sma
- Line 39: crossunder → ta.crossunder
- Line 39: sma → ta.sma
- Line 39: sma → ta.sma
⋯// © onurenginogutcu-//@version=4+//@version=5strategy("STRATEGY R18-F-BTC", overlay=true, margin_long=100, margin_short=100)///////////default girişler 1 saatlik btc grafiği için geçerli olmak üzere - stop loss'lar %2.5 - long'da %7.6 , short'ta %8.1-sym = input(title="Symbol", type=input.symbol, defval="BINANCE:BTCUSDT") /////////btc'yi indikatör olarak alıyoruz+sym = input.symbol(title="Symbol", defval="BINANCE:BTCUSDT") /////////btc'yi indikatör olarak alıyoruzlsl = input(title="Long Stop Loss (%)",⋯ -choice = input(title="Reverse ?", type=input.bool, defval=false)+choice = input.bool(title="Reverse ?", defval=false)-symClose = security(sym, "", close)+symClose = request.security(sym, "", close)-symHigh = security(sym, "", high)+symHigh = request.security(sym, "", high)-symLow = security(sym, "", low)+symLow = request.security(sym, "", low)-i = ema (symClose , 15) - ema (symClose , 30) ///////// ema close 15 ve 30 inanılmaz iyi sonuç verdi (macd standartı 12 26)+i = ta.ema (symClose , 15) - ta.ema (symClose , 30) ///////// ema close 15 ve 30 inanılmaz iyi sonuç verdi (macd standartı 12 26)-r = ema (i , 9)+r = ta.ema (i , 9)-sapust = highest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022+sapust = ta.highest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022-sapalt = lowest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022+sapalt = ta.lowest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022///////////highx = highest (close , 365) * 0.72 fibo belki dahiledilebilir///////////lowx = lowest (close , 365) * 1.272 fibo belki dahil edilebilir-simRSI = rsi (symClose , 50 ) /////// RSI DAHİL EDİLDİ "50 MUMLUK RSI EN İYİ SONUCU VERİYOR"+simRSI = ta.rsi (symClose , 50 ) /////// RSI DAHİL EDİLDİ "50 MUMLUK RSI EN İYİ SONUCU VERİYOR"//////////////fibonacci seviyesi eklenmesi amacı ile koyuldu fakat en iyi sonuç %50 seviyesinin altı ve üstü (low ve high 38 barlık) en iyi sonuç verdifibvar = 38-fibtop = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)+fibtop = ta.lowest (symLow , fibvar) + ((ta.highest (symHigh , fibvar) - ta.lowest (symLow , fibvar)) * 0.50)-fibbottom = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)+fibbottom = ta.lowest (symLow , fibvar) + ((ta.highest (symHigh , fibvar) - ta.lowest (symLow , fibvar)) * 0.50)///////////////////////////////////////////////////////////// INDICATOR CONDITIONS-longCondition = crossover(i, r) and i < sapalt and symClose < sma (symClose , 50) and simRSI < sma (simRSI , 50) and symClose < fibbottom+longCondition = ta.crossover(i, r) and i < sapalt and symClose < ta.sma (symClose , 50) and simRSI < ta.sma (simRSI , 50) and symClose < fibbottom-shortCondition = crossunder(i, r) and i > sapust and symClose > sma (symClose , 50) and simRSI > sma (simRSI , 50) and symClose > fibtop+shortCondition = ta.crossunder(i, r) and i > sapust and symClose > ta.sma (symClose , 50) and simRSI > ta.sma (simRSI , 50) and symClose > fibtop////////////////////////////////////////////////////////////////⋯Clean v5
VerifiedSame 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.float()
- Line 10: input() → input.float()
- Line 13: input() → input.float()
- Line 16: input() → input.float()
- Line 19: input() → input.int()
- Line 43: when = strategy.position_size == 0 → if block
3 more edits
- Line 46: when = strategy.position_size == 0 → if block
- Line 48: when = strategy.position_size == 0 → if block
- Line 50: when = strategy.position_size == 0 → if block
⋯sym = input.symbol(title="Symbol", defval="BINANCE:BTCUSDT") /////////btc'yi indikatör olarak alıyoruz-lsl = input(title="Long Stop Loss (%)",+lsl = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=2.5) * 0.01 -ssl = input(title="Short Stop Loss (%)",+ssl = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=2.5) * 0.01 -longtp = input(title="Long Take Profit (%)",+longtp = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=7.6) * 0.01 -shorttp = input(title="Short Take Profit (%)",+shorttp = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=7.5) * 0.01 -capperc = input(title="Capital Percentage to Invest (%)",+capperc = input.int(title="Capital Percentage to Invest (%)", minval=0.0, maxval=100, step=0.1, defval=90) * 0.01⋯if (choice == false and longCondition)- strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)+ if strategy.position_size == 0+ strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close ) if (choice == false and shortCondition)- strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)+ if strategy.position_size == 0+ strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close )if (choice == true and longCondition)- strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)+ if strategy.position_size == 0+ strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close )if (choice == true and shortCondition)- strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)+ if strategy.position_size == 0+ strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close ) ⋯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: 12 before, 0 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.
⋯// © onurenginogutcu-//@version=5+//@version=6strategy("STRATEGY R18-F-BTC", overlay=true, margin_long=100, margin_short=100)⋯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 |
|---|---|---|---|
| Symbol | BINANCE:BTCUSDT | symbol | symClose symHigh symLow |
| Long Stop Loss (%) | 2.5 | float · min 0.0 · step 0.1 | exit Exit Long |
| Short Stop Loss (%) | 2.5 | float · min 0.0 · step 0.1 | exit Exit Short |
| Long Take Profit (%) | 7.6 | float · min 0.0 · step 0.1 | exit Exit Long |
| Short Take Profit (%) | 7.5 | float · min 0.0 · step 0.1 | exit Exit Short |
| Capital Percentage to Invest (%) | 90 | int · min 0.0 · max 100 · step 0.1 | entry Long entry Short |
| Reverse ? | false | bool | entry Long entry Short entry Short entry Long line 42 line 45 line 47 line 49 |
What it calculates
- EMA (
ema,ta.emain v5)symClose, 15i · line 26 - EMA (
ema,ta.emain v5)i, 9r · line 27 - Highest (
highest,ta.highestin v5)i, 100sapust · line 28 - Lowest (
lowest,ta.lowestin v5)i, 100sapalt · line 29 - RSI (
rsi,ta.rsiin v5)symClose, 50simRSI · line 32 - Lowest / Highest (
lowest,ta.lowestin v5)symLow, fibvarfibtop · line 35 - Lowest / Highest (
lowest,ta.lowestin v5)symLow, fibvarfibbottom · line 36
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 | strategy.position_size == 0 | On | 43 |
| Open Short short | strategy.position_size == 0 | On | 46 |
| Open Short short | strategy.position_size == 0 | On | 48 |
| Open Long long | strategy.position_size == 0 | On | 50 |
| Exit Exit Long stop and limit | (strategy.position_size > 0) | On | 53 |
| Exit Exit Short stop and limit | (strategy.position_size < 0) | On | 55 |
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 data3 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 | −8.6% | +102.5% | 11 | 18% | 0.61 | 14.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.7% | +5.5% | 9 | 22% | 0.83 | 14.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −6.5% | +9.8% | 11 | 27% | 0.75 | 16.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +15.8% | +8.4% | 13 | 38% | 1.77 | 10.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +6.8% | +16.7% | 11 | 36% | 1.34 | 12.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +18.4% | +21.5% | 12 | 42% | 1.99 | 8.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −16.9% | +148.3% | 11 | 9% | 0.29 | 22.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +13.6% | +17.1% | 10 | 40% | 1.84 | 8.7% | 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 | 20% | −$4,067.43 |
| Sideways market | 3 | 33% | $2,433.24 |
| Falling market | 3 | 0% | −$6,924.02 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
19.8%
The 95th percentile of the worst drawdown when the same 11 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 8.9% to 19.8%; the tick is what actually happened, 14.4%. Order luck alone moves it this much.
All 11 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 14 Jul 2024 59,204.00 | 15 Jul 2024 63,703.50 | 1 | $6,840.01 |
| short | 4 Nov 2024 68,776.00 | 5 Nov 2024 70,495.40 | 1 | −$2,403.90 |
| short | 27 Nov 2024 91,965.20 | 28 Nov 2024 95,863.10 | 1 | −$3,983.88 |
| long | 18 Mar 2025 84,010.00 | 29 Mar 2025 81,909.80 | 11 | −$2,260.19 |
| short | 27 May 2025 109,435.00 | 5 Jun 2025 101,227.00 | 9 | $6,627.96 |
| long | 28 Nov 2025 91,333.90 | 1 Dec 2025 89,050.60 | 3 | −$2,358.45 |
| long | 18 Feb 2026 67,503.50 | 19 Feb 2026 65,815.90 | 1 | −$2,305.39 |
| short | 30 Apr 2026 75,780.00 | 1 May 2026 77,674.50 | 1 | −$2,253.51 |
| short | 14 May 2026 79,313.60 | 15 May 2026 81,296.50 | 1 | −$2,202.82 |
| long | 15 Jun 2026 65,746.40 | 17 Jun 2026 64,102.80 | 2 | −$2,153.26 |
| short | 8 Sep 2026 79,112.00 | 18 Sep 2026 81,089.80 | 10 | −$2,104.80 |
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 |
|---|---|---|---|---|---|
| STRATEGY R18-F-BTC this page | — | v4 strategy | −8.6% | 11 | 14.4% |
| M0PB (Momentum Pullback) by Marcns_ | rsi ema highest lowest | v5 strategy | +51.3% | 3 | 17.5% |
| Crypto High Potential Strategy by maxencetajet | ema rsi highest lowest | v5 strategy | No trades on this market | ||
| sma RSI & sudden buy and sell Strategy v1 by samwillington | ema rsi highest lowest | v5 strategy | +7.6% | 15 | 3.7% |
| PlanB Quant Investing 101 v2 by fillippone | rsi highest lowest | v4 strategy | No trades on this market | ||
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest lowest | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | Yes 1,000 bars in 46 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/// © onurenginogutcu//@version=4strategy("STRATEGY R18-F-BTC", overlay=true, margin_long=100, margin_short=100)///////////default girişler 1 saatlik btc grafiği için geçerli olmak üzere - stop loss'lar %2.5 - long'da %7.6 , short'ta %8.1sym = input(title="Symbol", type=input.symbol, defval="BINANCE:BTCUSDT") /////////btc'yi indikatör olarak alıyoruzlsl = input(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=2.5) * 0.01 ssl = input(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=2.5) * 0.01 longtp = input(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=7.6) * 0.01 shorttp = input(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=7.5) * 0.01 capperc = input(title="Capital Percentage to Invest (%)", minval=0.0, maxval=100, step=0.1, defval=90) * 0.01 choice = input(title="Reverse ?", type=input.bool, defval=false)symClose = security(sym, "", close)symHigh = security(sym, "", high)symLow = security(sym, "", low)i = ema (symClose , 15) - ema (symClose , 30) ///////// ema close 15 ve 30 inanılmaz iyi sonuç verdi (macd standartı 12 26)r = ema (i , 9)sapust = highest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022sapalt = lowest (i , 100) * 0.729 //////////0.729 altın oran oldu 09.01.2022///////////highx = highest (close , 365) * 0.72 fibo belki dahiledilebilir///////////lowx = lowest (close , 365) * 1.272 fibo belki dahil edilebilirsimRSI = rsi (symClose , 50 ) /////// RSI DAHİL EDİLDİ "50 MUMLUK RSI EN İYİ SONUCU VERİYOR"//////////////fibonacci seviyesi eklenmesi amacı ile koyuldu fakat en iyi sonuç %50 seviyesinin altı ve üstü (low ve high 38 barlık) en iyi sonuç verdifibvar = 38fibtop = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)fibbottom = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)///////////////////////////////////////////////////////////// INDICATOR CONDITIONSlongCondition = crossover(i, r) and i < sapalt and symClose < sma (symClose , 50) and simRSI < sma (simRSI , 50) and symClose < fibbottomshortCondition = crossunder(i, r) and i > sapust and symClose > sma (symClose , 50) and simRSI > sma (simRSI , 50) and symClose > fibtop///////////////////////////////////////////////////////////////////////////////////////////////////////////STRATEGY ENTRIES AND STOP LOSSES /////stratejilerde kalan capital için strategy.equity kullan (bunun üzerinden işlem yap)if (choice == false and longCondition) strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close , when = strategy.position_size == 0) if (choice == false and shortCondition) strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)if (choice == true and longCondition) strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close , when = strategy.position_size == 0)if (choice == true and shortCondition) strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close , when = strategy.position_size == 0) if (strategy.position_size > 0) strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price*(1 - lsl) , limit=strategy.position_avg_price*(1 + longtp))if (strategy.position_size < 0) strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price*(1 + ssl) , limit=strategy.position_avg_price*(1 - shorttp))////////////////////////vertical colouring signalsbgcolor(color=longCondition ? color.new (color.green , 70) : na)bgcolor(color=shortCondition ? color.new (color.red , 70) : na)