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
- 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
DiffersTrades 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
VerifiedSame 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length | 9 | int (written input.integer) | rsiCurrent rsi4h |
| Source | ohlc4 | source | rsiCurrent rsi4h |
| Max Loss (no label in the script) | 3000 | int | exit Max Loss |
| trendMA | 200 | int (written input.integer) | trendMA |
| shortMA | 30 | int (written input.integer) | shortMA |
| longMA | 50 | int (written input.integer) | longMA |
What it calculates
- RSI (
rsi,ta.rsiin v5)Source (ohlc4), Length (9)rsiCurrent · line 12 - RSI (
rsi,ta.rsiin v5)Source (ohlc4), Length (9)rsi4h · line 14 - EMA (
ema,ta.emain v5)close, trendMA (200)trendMA · line 20 - EMA (
ema,ta.emain v5)close, shortMA (30)shortMA · line 21 - EMA (
ema,ta.emain v5)close, longMA (50)longMA · line 22 - Crossunder (
crossunder,ta.crossunderin v5)longMA[1], shortMA[1]BuySignalOut · line 31 - Crossunder (
crossunder,ta.crossunderin v5)shortMA[1], longMA[1]SellSignalOut · line 36 - ATR (
atr,ta.atrin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close short | BuySignal | On | 40 |
| Open long long | BuySignal | On | 41 |
| Exit Max Loss stop | BuySignal | On | 42 |
| Close long | BuySignalOut | On | 44 |
| Close long | SellSignal | On | 47 |
| Open short short | SellSignal | On | 48 |
| Exit Max Loss stop | SellSignal | On | 49 |
| Close short | SellSignalOut | On | 52 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −0.7% | +102.5% | 18 | 0% | 0.00 | 0.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.7% | +5.5% | 17 | 0% | 0.00 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −17.7% | +9.8% | 17 | 0% | 0.00 | 17.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −16.1% | +8.4% | 15 | 7% | 0.14 | 16.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1.7% | +16.7% | 19 | 58% | 0.98 | 56.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −14.7% | +21.5% | 11 | 73% | 0.75 | 40.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +3.3% | +148.3% | 17 | 24% | 1.05 | 29.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +4.2% | +17.1% | 15 | 47% | 1.11 | 18.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 5 | 0% | −$168.20 |
| Sideways market | 10 | 0% | −$404.99 |
| Falling market | 3 | 0% | −$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.
All 18 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 22 May 2024 69,166.60 | 23 May 2024 69,196.60 | 1 | −$43.37 |
| long | 26 Jun 2024 60,865.00 | 27 Jun 2024 60,835.00 | 1 | −$49.27 |
| long | 6 Aug 2024 56,022.00 | 7 Aug 2024 55,992.00 | 1 | −$53.50 |
| short | 29 Sep 2024 65,602.00 | 14 Oct 2024 65,632.00 | 15 | −$45.66 |
| short | 31 Oct 2024 70,292.00 | 1 Nov 2024 70,322.00 | 1 | −$42.60 |
| short | 14 Nov 2024 87,325.60 | 15 Nov 2024 87,355.60 | 1 | −$34.27 |
| short | 18 Dec 2024 100,204.00 | 19 Dec 2024 100,234.00 | 1 | −$29.86 |
| long | 1 Mar 2025 86,064.50 | 2 Mar 2025 86,034.50 | 1 | −$34.75 |
| short | 24 Apr 2025 93,980.50 | 25 Apr 2025 94,010.50 | 1 | −$31.82 |
| short | 15 Jul 2025 117,758.00 | 16 Jul 2025 117,788.00 | 1 | −$25.38 |
| short | 7 Oct 2025 121,333.00 | 8 Oct 2025 121,363.00 | 1 | −$24.63 |
| long | 23 Nov 2025 86,830.00 | 24 Nov 2025 86,800.00 | 1 | −$34.41 |
| short | 7 Jan 2026 91,364.20 | 8 Jan 2026 91,394.20 | 1 | −$32.69 |
| long | 7 Feb 2026 69,289.40 | 8 Feb 2026 69,259.40 | 1 | −$43.09 |
| short | 7 May 2026 80,006.00 | 8 May 2026 80,036.00 | 1 | −$37.30 |
| long | 7 Jun 2026 63,332.00 | 8 Jun 2026 63,302.00 | 1 | −$47.10 |
| short | 23 Aug 2026 77,734.00 | 24 Aug 2026 77,764.00 | 1 | −$38.36 |
| short | 23 Sep 2026 84,397.60 | 24 Sep 2026 84,427.60 | 1 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Mathias & Christer Timeframe RSI this page | — | v4 strategy | −0.7% | 18 | 0.7% |
| Risk Management Strategy Template by kevinmck100 | ema rsi atr | v5 strategy | −0.3% | 7 | 3.6% |
| Dashboard table by Zeal Terminal | rsi atr ema | v5 indicator | indicator | ||
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi atr | v4 strategy | −42.3% | 18 | 44.8% |
| Atrend by OTS by prim722 | ema rsi atr | v4 strategy | +12.1% | 76 | 34.4% |
| EMA crossover (daily TF) by tradeswithashish | ema rsi atr | v5 strategy | +11.0% | 12 | 11.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 57 ms | Not measured |
| PineTS | No 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)