Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$91,442$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
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

Differs

Trades 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

Verified

Same 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.

SettingDefaultType and rangeFeeds
SymbolBINANCE:BTCUSDTsymbolsymClose symHigh symLow
Long Stop Loss (%)2.5float · min 0.0 · step 0.1exit Exit Long
Short Stop Loss (%)2.5float · min 0.0 · step 0.1exit Exit Short
Long Take Profit (%)7.6float · min 0.0 · step 0.1exit Exit Long
Short Take Profit (%)7.5float · min 0.0 · step 0.1exit Exit Short
Capital Percentage to Invest (%)90int · min 0.0 · max 100 · step 0.1entry Long entry Short
Reverse ?falseboolentry Long entry Short entry Short entry Long line 42 line 45 line 47 line 49

What it calculates

  • EMA (ema, ta.ema in v5)symClose, 15i · line 26
  • EMA (ema, ta.ema in v5)i, 9r · line 27
  • Highest (highest, ta.highest in v5)i, 100sapust · line 28
  • Lowest (lowest, ta.lowest in v5)i, 100sapalt · line 29
  • RSI (rsi, ta.rsi in v5)symClose, 50simRSI · line 32
  • Lowest / Highest (lowest, ta.lowest in v5)symLow, fibvarfibtop · line 35
  • Lowest / Highest (lowest, ta.lowest in 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.

closecloseprice datasymSymbolsetting · BINANCE:BTCUSDThighhighprice datalowlowprice dataiEMA→ irEMA→ rsapustHighest→ sapustsapaltLowest→ sapaltsimRSIRSI→ simRSIfibtopLowest / Highest→ fibtopfibbottomLowest / Highest→ fibbottomsymClosesymClosevaluesymHighsymHighvaluesymLowsymLowvaluelongConditionlongConditionconditionshortConditionshortConditionconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Exit Longexit Exit Longstrategy.exitexit:Exit Shortexit Exit Shortstrategy.exitbgcolor:57bgcolorbgcolorbgcolor:58bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open Long longstrategy.position_size == 0On43
Open Short shortstrategy.position_size == 0On46
Open Short shortstrategy.position_size == 0On48
Open Long longstrategy.position_size == 0On50
Exit Exit Long stop and limit(strategy.position_size > 0)On53
Exit Exit Short stop and limit(strategy.position_size < 0)On55

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.

5/5trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−8.6%+102.5%1118%0.6114.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−2.7%+5.5%922%0.8314.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−6.5%+9.8%1127%0.7516.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+15.8%+8.4%1338%1.7710.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+6.8%+16.7%1136%1.3412.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+18.4%+21.5%1242%1.998.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−16.9%+148.3%119%0.2922.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+13.6%+17.1%1040%1.848.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 barsTradesWonP&L
Rising market520%−$4,067.43
Sideways market333%$2,433.24
Falling market30%−$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.

0%23%
All 11 trades
SideEntryExitBarsP&L
long14 Jul 2024 59,204.0015 Jul 2024 63,703.501$6,840.01
short4 Nov 2024 68,776.005 Nov 2024 70,495.401−$2,403.90
short27 Nov 2024 91,965.2028 Nov 2024 95,863.101−$3,983.88
long18 Mar 2025 84,010.0029 Mar 2025 81,909.8011−$2,260.19
short27 May 2025 109,435.005 Jun 2025 101,227.009$6,627.96
long28 Nov 2025 91,333.901 Dec 2025 89,050.603−$2,358.45
long18 Feb 2026 67,503.5019 Feb 2026 65,815.901−$2,305.39
short30 Apr 2026 75,780.001 May 2026 77,674.501−$2,253.51
short14 May 2026 79,313.6015 May 2026 81,296.501−$2,202.82
long15 Jun 2026 65,746.4017 Jun 2026 64,102.802−$2,153.26
short8 Sep 2026 79,112.0018 Sep 2026 81,089.8010−$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.

ScriptSharesTypeNetTradesMax drawdown
STRATEGY R18-F-BTC this page—v4 strategy−8.6%1114.4%
M0PB (Momentum Pullback) by Marcns_rsi ema highest lowestv5 strategy+51.3%317.5%
Crypto High Potential Strategy by maxencetajetema rsi highest lowestv5 strategyNo trades on this market
sma RSI & sudden buy and sell Strategy v1 by samwillingtonema rsi highest lowestv5 strategy+7.6%153.7%
PlanB Quant Investing 101 v2 by fillipponersi highest lowestv4 strategyNo trades on this market
CC Trend strategy 2- Downtrend Short by CheatCode1ema highest lowestv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msYes 1,000 bars in 46 msNot measured
PineTSNo 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)