Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

MFI Simple Strategy

A Pine Script v5 strategy built on SMA or MFI (close, len, 18) and SMA (close, 200). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 1 setting; defaults include Length 18.

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 MFI Simple Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did MFI Simple Strategy do on BTCUSDT 1D with default settings?
−0.21%
From 26 Jan 2024 to 21 Oct 2026, over 28 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does MFI Simple Strategy 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: 28 before, 27 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does MFI Simple Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 12.
Does MFI Simple Strategy run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 36 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • 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 (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$997,869$2,025,273Equity from $1,000,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.
Net profit
−0.21%
−$2,132.46
Buy and hold
+102.5%
same period
Closed trades
28
10 won · 18 lost
Profitable
35.7%
of closed trades
Profit factor
0.96
gross profit ÷ gross loss
Max drawdown
3.23%
−$33,011.80

One run with the author's default settings, $1,000,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.

  • Likely bug

    ta.sma(close, 200) ignores the settings line 9

    Line 9 hard-codes 200 where line 6 uses “Length”. Changing those settings moves one band but not this one.

    ta.sma(close, 200)ta.sma(close, len)
  • 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 11, 13. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Length18intmfi

What it calculates

  • SMA / MFIta.mfi(close, len), Length (18)mfi · line 6
  • SMAclose, 200goldsma · line 9

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 datalenLengthsetting · 18mfiSMA / MFI→ mfigoldsmaSMA→ goldsmamfiupmfiupconditionmfidnmfidnconditionfillclrColourfillclrentry:LongOpen Longstrategy.entryexit:Longexit Longstrategy.exitclose:LongClose Longstrategy.closeplot:14plotplotplot:15plotplotplot:16plotplotfill:18Fillfill

Order rules

OrderFires whenBy defaultLine
Open Long longmfiup(mfi[1] < mfi) and (mfi[2] < mfi[1])On11
Exit Long stopevery barOn12
Close Longmfidn(mfi[1] > mfi) and (mfi[2] < mfi[1])On13

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.

2/2trades 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 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−0.2%+102.5%2836%0.963.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.4%+5.5%3529%1.260.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.0%+9.8%1331%0.830.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%2748%2.370.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%2040%1.410.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3339%2.300.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%4529%0.860.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%3722%1.620.0%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 market1258%$20,061.10
Sideways market1520%−$21,728.70
Falling market10%−$464.82

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

How bad could the drawdown be?

3.8%

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

0%4%
All 28 trades
SideEntryExitBarsP&L
long24 Aug 2024 64,037.2026 Aug 2024 63,324.002−$713.23
long25 Sep 2024 64,262.7025 Sep 2024 63,904.500−$358.16
long27 Sep 2024 65,174.0030 Sep 2024 63,763.003−$1,411.02
long21 Oct 2024 69,032.0022 Oct 2024 67,377.501−$1,654.50
long27 Oct 2024 67,092.804 Nov 2024 68,776.008$1,683.23
long10 Nov 2024 76,677.5016 Nov 2024 91,032.106$14,354.60
long20 Nov 2024 92,310.8027 Nov 2024 91,965.207−$345.64
long30 Dec 2024 93,738.204 Jan 2025 98,174.205$4,435.98
long12 Jan 2025 94,600.0013 Jan 2025 94,545.101−$54.92
long16 Jan 2025 100,497.006 Feb 2025 96,612.4021−$3,884.91
long16 Mar 2025 84,338.4016 Mar 2025 83,873.600−$464.82
long20 Mar 2025 86,845.9020 Mar 2025 84,371.900−$2,474.04
long26 Mar 2025 87,392.9028 Mar 2025 85,552.902−$1,839.99
long23 Apr 2025 93,443.0011 May 2025 104,810.0018$11,366.50
long5 Jun 2025 104,697.006 Jun 2025 101,509.001−$3,188.17
long8 Jun 2025 105,552.009 Jun 2025 105,734.001$181.86
long18 Jun 2025 104,551.0021 Jun 2025 103,298.003−$1,253.19
long25 Jun 2025 106,083.0029 Jun 2025 107,297.004$1,213.79
long1 Jul 2025 107,147.005 Jul 2025 107,984.004$837.74
long10 Jul 2025 111,234.0027 Jul 2025 117,920.0017$6,685.99
long19 Aug 2025 116,227.001 Sep 2025 108,246.0013−$7,980.69
long3 Sep 2025 111,240.008 Sep 2025 111,137.005−$102.66
long13 Sep 2025 116,029.0030 Sep 2025 114,312.0017−$1,717.44
long7 Oct 2025 124,659.0010 Oct 2025 106,442.003−$18,216.80
long11 Oct 2025 112,774.0012 Oct 2025 110,644.001−$2,130.09
long15 Oct 2025 113,028.0016 Oct 2025 110,763.001−$2,264.85
long21 Aug 2026 73,027.008 Sep 2026 79,112.0018$6,084.98
long28 Sep 2026 84,472.007 Oct 2026 85,549.909$1,077.93

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
MFI Simple Strategy this page—v5 strategy−0.2%283.2%
[VJ]Thor for MFI by vikrismfi smav4 strategyNo trades on this market
CCU MFI + RSI + STOCH RSI by Bangsoulmfi smav4 strategy+41.8%637.4%
3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders by ggekko21sma mfiv5 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 11, 13). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 1 setting uses the untyped input() (line 5). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.int()
  • Line 11: when = mfiup → if block
  • Line 13: when = mfidn → if block
⋯strategy("MFI Simple Strategy", overlay=false)-len = input(18, "Length")+len = input.int(18, "Length")mfi = ta.sma(ta.mfi(close, len), len)⋯if goldsma < close-    strategy.entry("Long", strategy.long, when=mfiup)+    if mfiup+        strategy.entry("Long", strategy.long)strategy.exit("Long", stop=goldsma)-strategy.close("Long", when=mfidn)+if mfidn+    strategy.close("Long")a = plot(mfi)⋯

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: 28 before, 27 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.

⋯// © OztheWoz-//@version=5+//@version=6strategy("MFI Simple Strategy", overlay=false)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msYes 1,000 bars in 36 msNot measured
PineTSNot testedNot testedNot 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.

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/// © OztheWoz//@version=5strategy("MFI Simple Strategy", overlay=false)len = input(18, "Length")mfi = ta.sma(ta.mfi(close, len), len)mfiup = (mfi[1] < mfi) and (mfi[2] < mfi[1])mfidn = (mfi[1] > mfi) and (mfi[2] < mfi[1])goldsma = ta.sma(close, 200)if goldsma < close    strategy.entry("Long", strategy.long, when=mfiup)strategy.exit("Long", stop=goldsma)strategy.close("Long", when=mfidn)a = plot(mfi)b = plot(80, color=color.gray)c = plot(20, color=color.gray)fillclr = color.new(color.blue, 70)fill(a, b, color=(mfi > 80) ? fillclr : na)// fill(a, c)