Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Madri

A Pine Script v4 strategy built on RSI (price, 2), SMA (price, 150) and Stdev (price, 150). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include A 2 and B 150.

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 Madri repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Madri do on BTCUSDT 1D with default settings?
+24.97%
From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Madri be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Madri use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Madri run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 20 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • Stdev
  • Crossover
  • Crossunder
  • 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 (2)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$106,333$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
+24.97%
$24,965.10
Buy and hold
+102.5%
same period
Closed trades
4
3 won · 1 lost
Profitable
75.0%
of closed trades
Profit factor
3.03
gross profit ÷ gross loss
Max drawdown
36.44%
−$45,538.90

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

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

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, sma → ta.sma, stdev → ta.stdev, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 11: rsi → ta.rsi
  • Line 15: sma → ta.sma
  • Line 16: stdev → ta.stdev
  • Line 20: crossover → ta.crossover
  • Line 21: crossunder → ta.crossunder
4 more edits
  • Line 30: crossover → ta.crossover
  • Line 30: crossover → ta.crossover
  • Line 35: crossunder → ta.crossunder
  • Line 35: crossunder → ta.crossunder
⋯// © Mdemoio-//@version=4+//@version=5strategy("Madri", shorttitle="Madri", overlay=true)⋯price = close-vrsi = rsi(price, RSIlength)+vrsi = ta.rsi(price, RSIlength)///////////// Bollinger Bands⋯BBmult = 2// input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")-BBbasis = sma(price, BBlength)+BBbasis = ta.sma(price, BBlength)-BBdev = BBmult * stdev(price, BBlength)+BBdev = BBmult * ta.stdev(price, BBlength)BBupper = BBbasis + BBdev⋯source = close-buyEntry = crossover(source, BBlower)+buyEntry = ta.crossover(source, BBlower)-sellEntry = crossunder(source, BBupper)+sellEntry = ta.crossunder(source, BBupper)///////////// Colors⋯if (not na(vrsi))-    if (crossover(vrsi, RSIoverSold) and crossover(source, BBlower))+    if (ta.crossover(vrsi, RSIoverSold) and ta.crossover(source, BBlower))        strategy.entry("RSI_BB_L", strategy.long, stop=BBlower, oca_type=strategy.oca.cancel, comment="Buy")⋯        -    if (crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))+    if (ta.crossunder(vrsi, RSIoverBought) and ta.crossunder(source, BBupper))        strategy.entry("RSI_BB_S", strategy.short, stop=BBupper, oca_type=strategy.oca.cancel, comment="Sell")⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 7: input() → input.int()
  • Line 13: input() → input.int()
⋯///////////// RSI-RSIlength = input(2,title="A") +RSIlength = input.int(2,title="A") RSIoverSold = 45⋯///////////// Bollinger Bands-BBlength = input(150, minval=1,title="B")+BBlength = input.int(150, minval=1,title="B")BBmult = 2// input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")⋯

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: 4 before, 1 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.

⋯// © Mdemoio-//@version=5+//@version=6strategy("Madri", shorttitle="Madri", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
A2intvrsi
B150int · min 1BBbasis BBdev

What it calculates

  • RSI (rsi, ta.rsi in v5)price, A (2)vrsi · line 11
  • SMA (sma, ta.sma in v5)price, B (150)BBbasis · line 15
  • Stdev (stdev, ta.stdev in v5)price, B (150)BBdev · line 16
  • Crossover (crossover, ta.crossover in v5)source, BBlowerbuyEntry · line 20
  • Crossunder (crossunder, ta.crossunder in v5)source, BBuppersellEntry · line 21

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.

RSIlengthAsetting · 2BBlengthBsetting · 150closecloseprice datavrsiRSI→ vrsiBBbasisSMA→ BBbasisBBdevStdev→ BBdevbuyEntryCrossover→ buyEntrysellEntryCrossunder→ sellEntryprice, sourceprice · source2 valuesBBupper, BBlowerBBupper · BBlower2 valuesentry:RSI_BB_LOpen RSI_BB_Lstrategy.entrycancel:RSI_BB_Lcancel RSI_BB_Lstrategy.cancelentry:RSI_BB_SOpen RSI_BB_Sstrategy.entrycancel:RSI_BB_Scancel RSI_BB_Sstrategy.cancel

Order rules

OrderFires whenBy defaultLine
Open RSI_BB_L long(crossover(vrsi, RSIoverSold) and crossover(source, BBlower))On31
cancel RSI_BB_L(crossover(vrsi, RSIoverSold) and crossover(source, BBlower))On33
Open RSI_BB_S short(crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))On36
cancel RSI_BB_S(crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))On38

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 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+25.0%+102.5%475%3.0336.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+17.4%+5.5%2100%—5.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+8.7%+9.8%5100%—0.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.3%+8.4%250%0.440.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%475%10.620.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%2100%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.7%+148.3%5100%—0.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%250%0.190.2%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 market0—$0.00
Sideways market367%$262.01
Falling market1100%$24,703.10

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

How bad could the drawdown be?

11.3%

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

0%13%
All 4 trades
SideEntryExitBarsP&L
long9 Aug 2024 61,686.001 Nov 2024 70,292.0084$8,606.01
short1 Nov 2024 70,292.0010 Apr 2025 82,615.20160−$12,323.20
long10 Apr 2025 82,615.2024 May 2025 107,318.0044$24,703.10
short24 May 2025 107,318.008 Nov 2025 103,339.00168$3,979.21

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
Madri this page—v4 strategy+25.0%436.4%
Bottom catch strategy by footlzsma stdev rsiv4 strategy+3.9%37.1%
Bollinger Bands and RSI Short Selling (by Coinrule) by Coinrulesma stdev rsiv5 strategy+7.6%34.3%
Shorting when Bollinger Band Above Price with RSI (by Coinrule) by Coinrulesma stdev rsiv5 strategyNo trades on this market
RSI_Boll-TP-SL by BigCoinHuntersma stdev rsiv5 strategyNo trades on this market
FMC by oliverbadaouisma rsi stdevv4 strategy+139.5%44111.9%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msYes 1,000 bars in 20 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/// © Mdemoio//@version=4strategy("Madri", shorttitle="Madri", overlay=true)// Version 1.1///////////// RSIRSIlength = input(2,title="A") RSIoverSold = 45RSIoverBought = 40price = closevrsi = rsi(price, RSIlength)///////////// Bollinger BandsBBlength = input(150, minval=1,title="B")BBmult = 2// input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")BBbasis = sma(price, BBlength)BBdev = BBmult * stdev(price, BBlength)BBupper = BBbasis + BBdevBBlower = BBbasis - BBdevsource = closebuyEntry = crossover(source, BBlower)sellEntry = crossunder(source, BBupper)///////////// Colors//switch1=input(true, title="Enable Bar Color?")//switch2=input(true, title="Enable Background Color?")//TrendColor = RSIoverBought and (price[1] > BBupper and price < BBupper) and BBbasis < BBbasis[1] ? red : RSIoverSold and (price[1] < BBlower and price > BBlower) and BBbasis > BBbasis[1] ? green : na//barcolor(switch1?TrendColor:na)//bgcolor(switch2?TrendColor:na,transp=50)///////////// RSI + Bollinger Bands Strategyif (not na(vrsi))    if (crossover(vrsi, RSIoverSold) and crossover(source, BBlower))        strategy.entry("RSI_BB_L", strategy.long, stop=BBlower, oca_type=strategy.oca.cancel, comment="Buy")    else        strategy.cancel(id="RSI_BB_L")            if (crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))        strategy.entry("RSI_BB_S", strategy.short, stop=BBupper, oca_type=strategy.oca.cancel, comment="Sell")    else        strategy.cancel(id="RSI_BB_S")//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)