Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Mathias & Christer Timeframe RSI

A Pine Script v4 strategy built on RSI (ohlc4, 9), EMA (close, 200) and Crossunder (longMA[1], shortMA[1]). It has 8 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays no commission. 6 settings; defaults include Length 9, Source ohlc4 and Max Loss 3000.

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 Mathias & Christer Timeframe RSI repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did Mathias & Christer Timeframe RSI do on BTCUSDT 1D with default settings?
−0.68%
From 26 Jan 2024 to 21 Oct 2026, over 18 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Mathias & Christer Timeframe RSI 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 Mathias & Christer Timeframe RSI use a stop loss?
Yes
strategy.exit sets a stop on line 42, 49.
Does Mathias & Christer Timeframe RSI run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 57 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • BuySignal
  • BuySignalOut
  • SellSignal
  • SellSignalOut
  • 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 (6)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$99,317$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. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 41, 48) so the engine trades the way the script says.
Net profit
−0.68%
−$683.38
Buy and hold
+102.5%
same period
Closed trades
18
0 won · 18 lost
Profitable
0.0%
of closed trades
Profit factor
0.00
gross profit ÷ gross loss
Max drawdown
0.68%
−$683.38

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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog maxLoss (line 11) shows an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 26

    transp = on line 26, 32, 33, 37, 38. v5 folds the transparency into the colour with color.new(c, transp).

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 rsi → ta.rsi, ema → ta.ema, crossunder → ta.crossunder, barssince → ta.barssince, atr → ta.atr.

v4 → v5

Differs

Trades differ: 18 before, 18 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 1: //@version=4 → //@version=5
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.source) → input.source()
  • Line 12: rsi → ta.rsi
  • Line 14: rsi → ta.rsi
  • Line 17: input(type = input.integer) → input.int()
18 more edits
  • Line 18: input(type = input.integer) → input.int()
  • Line 19: input(type = input.integer) → input.int()
  • Line 20: ema → ta.ema
  • Line 21: ema → ta.ema
  • Line 22: ema → ta.ema
  • Line 26: crossunder → ta.crossunder
  • Line 26: transp = 10 → color.new(crossunder(shortMA,longMA) ? color.black : na, 10)
  • Line 29: barssince → ta.barssince
  • Line 31: crossunder → ta.crossunder
  • Line 32: transp = 70 → color.new(BuySignal ? color.green : na, 70)
  • Line 33: transp = 10 → color.new(BuySignalOut ? color.green : na, 10)
  • Line 34: barssince → ta.barssince
  • Line 36: crossunder → ta.crossunder
  • Line 37: transp = 70 → color.new(SellSignal ? color.red : na, 70)
  • Line 38: transp = 10 → color.new(SellSignalOut ? color.red : na, 10)
  • Line 41: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 48: strategy.entry(…, false) → strategy.entry(…, strategy.short)
  • Line 56: atr → ta.atr
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true, process_orders_on_close = true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)-len = input(9, title="Length", type=input.integer)+len = input.int(9, title="Length")-src = input(ohlc4, title="Source", type=input.source)+src = input.source(ohlc4, title="Source")//show4h = input(true, title="show 4h", type=input.bool)maxLoss = input(3000)-rsiCurrent = rsi(src, len)+rsiCurrent = ta.rsi(src, len)//rsi4h = security(syminfo.ticker, "240", rsi(src, len))-rsi4h   = rsi(src, len)+rsi4h   = ta.rsi(src, len)//--------------------------------------------------//MA-trendMAInput = input(200, title="trendMA", type=input.integer)+trendMAInput = input.int(200, title="trendMA")-shortMAInput = input(30, title="shortMA", type=input.integer)+shortMAInput = input.int(30, title="shortMA")-longMAInput = input(50, title="longMA", type=input.integer)+longMAInput = input.int(50, title="longMA")-trendMA = ema(close,trendMAInput)+trendMA = ta.ema(close,trendMAInput)-shortMA = ema(close,shortMAInput)+shortMA = ta.ema(close,shortMAInput)-longMA  = ema(close,longMAInput)+longMA  = ta.ema(close,longMAInput)plot(trendMA, color=color.black, linewidth=5)⋯plot(longMA, color=color.green, linewidth=2)-bgcolor(crossunder(shortMA,longMA) ? color.black : na, transp=10)+bgcolor(color.new(ta.crossunder(shortMA,longMA) ? color.black : na, 10))//--------------------------------------------------//RSI-BuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)+BuySignalBarssince = ta.barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)BuySignal       = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)-BuySignalOut   = crossunder(longMA[1],shortMA[1])+BuySignalOut   = ta.crossunder(longMA[1],shortMA[1])-bgcolor(BuySignal ? color.green : na, transp=70)+bgcolor(color.new(BuySignal ? color.green : na, 70))-bgcolor(BuySignalOut ? color.green : na, transp=10)+bgcolor(color.new(BuySignalOut ? color.green : na, 10))-SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)+SellSignalBarssince = ta.barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)SellSignal      = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)-SellSignalOut   = crossunder(shortMA[1],longMA[1])+SellSignalOut   = ta.crossunder(shortMA[1],longMA[1])-bgcolor(SellSignal ? color.red : na, transp=70)+bgcolor(color.new(SellSignal ? color.red : na, 70))-bgcolor(SellSignalOut ? color.red : na, transp=10)+bgcolor(color.new(SellSignalOut ? color.red : na, 10))if BuySignal    strategy.close("short", comment = "Exit short")-    strategy.entry("long", true)+    strategy.entry("long", strategy.long)    strategy.exit("Max Loss", "long", loss = maxLoss)⋯    strategy.close("long", comment = "Exit Long")-    strategy.entry("short", false)+    strategy.entry("short", strategy.short)    strategy.exit("Max Loss", "short", loss = maxLoss)⋯//ATR-MyAtr = atr(10)+MyAtr = ta.atr(10)AtrFactor = 10⋯

Clean v5

Verified

Same 18 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 11: input() → input.int()
⋯//show4h = input(true, title="show 4h", type=input.bool)-maxLoss = input(3000)+maxLoss = input.int(3000)rsiCurrent = ta.rsi(src, len)⋯

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: 18 before, 19 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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Length9int (written input.integer)rsiCurrent rsi4h
Sourceohlc4sourcersiCurrent rsi4h
Max Loss (no label in the script)3000intexit Max Loss
trendMA200int (written input.integer)trendMA
shortMA30int (written input.integer)shortMA
longMA50int (written input.integer)longMA

What it calculates

  • RSI (rsi, ta.rsi in v5)Source (ohlc4), Length (9)rsiCurrent · line 12
  • RSI (rsi, ta.rsi in v5)Source (ohlc4), Length (9)rsi4h · line 14
  • EMA (ema, ta.ema in v5)close, trendMA (200)trendMA · line 20
  • EMA (ema, ta.ema in v5)close, shortMA (30)shortMA · line 21
  • EMA (ema, ta.ema in v5)close, longMA (50)longMA · line 22
  • Crossunder (crossunder, ta.crossunder in v5)longMA[1], shortMA[1]BuySignalOut · line 31
  • Crossunder (crossunder, ta.crossunder in v5)shortMA[1], longMA[1]SellSignalOut · line 36
  • ATR (atr, ta.atr in v5)10MyAtr · line 56

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.

ohlc4ohlc4price datalenLengthsetting · 9closecloseprice datatrendMAInputtrendMAsetting · 200shortMAInputshortMAsetting · 30longMAInputlongMAsetting · 50high · low · closehigh · low · closeprice datarsiCurrentRSI→ rsiCurrentrsi4hRSI→ rsi4htrendMAEMA→ trendMAshortMAEMA→ shortMAlongMAEMA→ longMABuySignalOutCrossunder→ BuySignalOutSellSignalOutCrossunder→ SellSignalOutMyAtrATR→ MyAtrmySLBuymySLBuyvaluemySLSellmySLSellvalueBuySignalBuySignalconditionSellSignalSellSignalconditionBuySignalBarssince, SellSignalBarssinceBuySignalBarssince · Se…2 conditionsclose:shortClose shortstrategy.closeentry:longOpen longstrategy.entryexit:Max Lossexit Max Lossstrategy.exitclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryplot:23plotplotplot:24plotplotplot:25plotplotbgcolor:26bgcolorbgcolorbgcolor:32bgcolorbgcolorbgcolor:33bgcolorbgcolorbgcolor:37bgcolorbgcolorbgcolor:38bgcolorbgcolorplotchar:60plotcharplotcharplotchar:61plotcharplotcharplotchar:62plotcharplotcharplotchar:63plotcharplotchar

Order rules

OrderFires whenBy defaultLine
Close shortBuySignalOn40
Open long longBuySignalOn41
Exit Max Loss stopBuySignalOn42
Close longBuySignalOutOn44
Close longSellSignalOn47
Open short shortSellSignalOn48
Exit Max Loss stopSellSignalOn49
Close shortSellSignalOutOn52

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.

6/6trades 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 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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−0.7%+102.5%180%0.000.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.7%+5.5%170%0.000.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−17.7%+9.8%170%0.0017.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−16.1%+8.4%157%0.1416.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−1.7%+16.7%1958%0.9856.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−14.7%+21.5%1173%0.7540.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.3%+148.3%1724%1.0529.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+4.2%+17.1%1547%1.1118.8%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 market50%−$168.20
Sideways market100%−$404.99
Falling market30%−$110.18

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

0.7%

The 95th percentile of the worst drawdown when the same 18 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.7% to 0.7%; the tick is what actually happened, 0.7%. Order luck alone moves it this much.

0%1%
All 18 trades
SideEntryExitBarsP&L
short22 May 2024 69,166.6023 May 2024 69,196.601−$43.37
long26 Jun 2024 60,865.0027 Jun 2024 60,835.001−$49.27
long6 Aug 2024 56,022.007 Aug 2024 55,992.001−$53.50
short29 Sep 2024 65,602.0014 Oct 2024 65,632.0015−$45.66
short31 Oct 2024 70,292.001 Nov 2024 70,322.001−$42.60
short14 Nov 2024 87,325.6015 Nov 2024 87,355.601−$34.27
short18 Dec 2024 100,204.0019 Dec 2024 100,234.001−$29.86
long1 Mar 2025 86,064.502 Mar 2025 86,034.501−$34.75
short24 Apr 2025 93,980.5025 Apr 2025 94,010.501−$31.82
short15 Jul 2025 117,758.0016 Jul 2025 117,788.001−$25.38
short7 Oct 2025 121,333.008 Oct 2025 121,363.001−$24.63
long23 Nov 2025 86,830.0024 Nov 2025 86,800.001−$34.41
short7 Jan 2026 91,364.208 Jan 2026 91,394.201−$32.69
long7 Feb 2026 69,289.408 Feb 2026 69,259.401−$43.09
short7 May 2026 80,006.008 May 2026 80,036.001−$37.30
long7 Jun 2026 63,332.008 Jun 2026 63,302.001−$47.10
short23 Aug 2026 77,734.0024 Aug 2026 77,764.001−$38.36
short23 Sep 2026 84,397.6024 Sep 2026 84,427.601−$35.32

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
Mathias & Christer Timeframe RSI this page—v4 strategy−0.7%180.7%
Risk Management Strategy Template by kevinmck100ema rsi atrv5 strategy−0.3%73.6%
Dashboard table by Zeal Terminalrsi atr emav5 indicatorindicator
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi atrv4 strategy−42.3%1844.8%
Atrend by OTS by prim722ema rsi atrv4 strategy+12.1%7634.4%
EMA crossover (daily TF) by tradeswithashishema rsi atrv5 strategy+11.0%1211.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msWith a workaround 1,000 bars in 57 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 41, 48) so the engine trades the way the script says.

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

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © mattehalen// INPUT per TIMEFRAME// 5min     = Legnth = 9, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 4, LongMA = 10// 30min    = Legnth = 7, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 10, LongMA = 20strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true, process_orders_on_close = true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)len = input(9, title="Length", type=input.integer)src = input(ohlc4, title="Source", type=input.source)//show4h = input(true, title="show 4h", type=input.bool)maxLoss = input(3000)rsiCurrent = rsi(src, len)//rsi4h = security(syminfo.ticker, "240", rsi(src, len))rsi4h   = rsi(src, len)//--------------------------------------------------//MAtrendMAInput = input(200, title="trendMA", type=input.integer)shortMAInput = input(30, title="shortMA", type=input.integer)longMAInput = input(50, title="longMA", type=input.integer)trendMA = ema(close,trendMAInput)shortMA = ema(close,shortMAInput)longMA  = ema(close,longMAInput)plot(trendMA, color=color.black, linewidth=5)plot(shortMA, color=color.red, linewidth=2)plot(longMA, color=color.green, linewidth=2)bgcolor(crossunder(shortMA,longMA) ? color.black : na, transp=10)//--------------------------------------------------//RSIBuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)BuySignal       = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)BuySignalOut   = crossunder(longMA[1],shortMA[1])bgcolor(BuySignal ? color.green : na, transp=70)bgcolor(BuySignalOut ? color.green : na, transp=10)SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)SellSignal      = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)SellSignalOut   = crossunder(shortMA[1],longMA[1])bgcolor(SellSignal ? color.red : na, transp=70)bgcolor(SellSignalOut ? color.red : na, transp=10)if BuySignal    strategy.close("short", comment = "Exit short")    strategy.entry("long", true)    strategy.exit("Max Loss", "long", loss = maxLoss)if BuySignalOut    strategy.close("long", comment = "Exit Long")if SellSignal    // Enter trade and issue exit order on max loss.    strategy.close("long", comment = "Exit Long")    strategy.entry("short", false)    strategy.exit("Max Loss", "short", loss = maxLoss)if SellSignalOut    // Force trade exit.    strategy.close("short", comment = "Exit short")    //--------------------------------------------------//ATRMyAtr = atr(10)AtrFactor = 10mySLBuy  = close[BuySignalBarssince]mySLSell = close[SellSignalBarssince]plotchar(BuySignal, "BuySignal", "⬆", location.belowbar, color.lime,size =size.huge )plotchar(BuySignalOut, "BuySignalOut", "█", location.belowbar, color.lime,size =size.small)plotchar(SellSignal, "SellSignal", "⬇", location.abovebar ,color.red,size =size.huge)plotchar(SellSignalOut, "SellSignalOut", "█", location.abovebar, color.red,size =size.small)