Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Money Flow Index 5 min Strategy

A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen (bought, LL). It has 11 order rules, 8 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.04 commission. 21 settings; defaults include Strategy Direction 0, MFI Length 3 and Overbought Level 100.

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 Money Flow Index 5 min Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did Money Flow Index 5 min Strategy do on BTCUSDT 1D with default settings?
−6.79%
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 Money Flow Index 5 min Strategy 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 Money Flow Index 5 min Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 133, 134.
Does Money Flow Index 5 min Strategy run in Zeal Terminal?
Yes
It compiles in 38 ms and runs 1,000 bars in 101 ms, in the browser.

BTCUSDT · 1D · default settings

  • Trade Day Start
  • SL
  • SSL
  • TP
  • STP
  • Bullish Setup
  • Bearish Setup
  • 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 (21)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$9,321$20,253Equity from $10,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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
−6.79%
−$678.93
Buy and hold
+102.5%
same period
Closed trades
18
10 won · 8 lost
Profitable
55.6%
of closed trades
Profit factor
0.88
gross profit ÷ gross loss
Max drawdown
28.44%
−$3,229.99

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

    2 settings do nothing

    “-----------------Strategy Inputs-------------------”, “-----------------General Inputs-------------------” are declared but never read.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses an argument v6 removed

    when = on line 94, 95, 97, 98, 101, 102, 104, 105, 107, 133, 134. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 68

    transp = on line 68, 87. 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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, atr → ta.atr, mfi → ta.mfi, sma → ta.sma.
  • 11 strategy calls use the when = argument (line 94, 95, 97, 98, 101, 102, 104, 105, 107, 133, 134). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 12: //@version=4 → //@version=5
  • Line 21: input(type = input.integer) → input.int()
  • Line 48: lowest → ta.lowest
  • Line 49: highest → ta.highest
  • Line 50: valuewhen → ta.valuewhen
  • Line 51: valuewhen → ta.valuewhen
12 more edits
  • Line 57: atr → ta.atr
  • Line 60: valuewhen → ta.valuewhen
  • Line 61: valuewhen → ta.valuewhen
  • Line 68: transp = 80 → color.new(color.silver, 80)
  • Line 69: valuewhen → ta.valuewhen
  • Line 70: valuewhen → ta.valuewhen
  • Line 74: mfi → ta.mfi
  • Line 78: sma → ta.sma
  • Line 80: valuewhen → ta.valuewhen
  • Line 87: transp = 100 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 113: valuewhen → ta.valuewhen
  • Line 125: valuewhen → ta.valuewhen
⋯// © tweakerID-//@version=4+//@version=5strategy("Money Flow Index 5 min Strategy", ⋯     slippage=0)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯// Price Action Stop and Take Profit-LL=(lowest(i_SPL))*(1-i_PercIncrement)+LL=(ta.lowest(i_SPL))*(1-i_PercIncrement)-HH=(highest(i_SPL))*(1+i_PercIncrement)+HH=(ta.highest(i_SPL))*(1+i_PercIncrement)-LL_price = valuewhen(bought, LL, 0)+LL_price = ta.valuewhen(bought, LL, 0)-HH_price = valuewhen(bought, HH, 0)+HH_price = ta.valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na ⋯// ATR Stop-ATR=atr(i_ATR)*i_ATRMult+ATR=ta.atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATR-ATRLongStop = valuewhen(bought, ATRLong, 0)+ATRLongStop = ta.valuewhen(bought, ATRLong, 0)-ATRShortStop = valuewhen(bought, ATRShort, 0)+ATRShortStop = ta.valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ⋯DayStart = time == timestamp("UTC", year, month, dayofmonth, 0, 0, 0)-plot(DayStart ? 1e9 : na, style=plot.style_columns, color=color.silver, transp=80, title="Trade Day Start")+plot(DayStart ? 1e9 : na, style=plot.style_columns, color=color.new(color.silver, 80), title="Trade Day Start")-float LongStop = valuewhen(DayStart,low,0)*(1-i_PercIncrement)+float LongStop = ta.valuewhen(DayStart,low,0)*(1-i_PercIncrement)-float ShortStop = valuewhen(DayStart,high,0)*(1+i_PercIncrement)+float ShortStop = ta.valuewhen(DayStart,high,0)*(1+i_PercIncrement)float StratTP = strategy.position_avg_price + (strategy.position_avg_price - LongStop)*i_TPRRR⋯/////////////////////// STRATEGY LOGIC /////////////////////////////////////////-MFI=mfi(close,i_MFI)+MFI=ta.mfi(close,i_MFI)barsize=high-low⋯shortwicksbar=barbodysize>barsize*barsizeThreshold-SMA=sma(close, i_MALen)+SMA=ta.sma(close, i_MALen)MAFilter=close > SMA-timesinceentry=(time - valuewhen(bought, time, 0)) / 60000+timesinceentry=(time - ta.valuewhen(bought, time, 0)) / 60000timedexit=timesinceentry == 60⋯//Debugging Plots-plot(timesinceentry, transp=100, title="Time Since Entry")+plot(timesinceentry, title="Time Since Entry")//Trading Inputs⋯//TrailingStop-dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))+dif=(ta.valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_price⋯var Ststop = float(na)-Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 +Sdif=strategy.position_avg_price-(ta.valuewhen(strategy.position_size<0  and strategy.position_size[1]>=0, low,0))⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 24: input() → input.bool()
  • Line 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.int()
  • Line 28: input() → input.float()
  • Line 29: input() → input.bool()
25 more edits
  • Line 30: input() → input.int()
  • Line 31: input() → input.bool()
  • Line 32: input() → input.bool()
  • Line 34: input() → input.bool()
  • Line 36: input() → input.bool()
  • Line 37: input() → input.string()
  • Line 38: input() → input.int()
  • Line 39: input() → input.int()
  • Line 40: input() → input.int()
  • Line 41: input() → input.int()
  • Line 42: input() → input.float()
  • Line 43: input() → input.bool()
  • Line 89: input() → input.bool()
  • Line 90: input() → input.bool()
  • Line 94: when = SELL and strategy.position_size == 0 → if block
  • Line 95: when = BUY and strategy.position_size == 0 → if block
  • Line 97: when = SELL → if block
  • Line 98: when = BUY → if block
  • Line 101: when = BUY and strategy.position_size == 0 → if block
  • Line 102: when = SELL and strategy.position_size == 0 → if block
  • Line 104: when = BUY → if block
  • Line 105: when = SELL → if block
  • Line 107: when = timedexit → if block
  • Line 133: when = i_SL → if block
  • Line 134: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------")  +title1=input.bool(true, "-----------------Strategy Inputs-------------------")  -i_MFI = input(3, title="MFI Length")+i_MFI = input.int(3, title="MFI Length")-OB=input(100, title="Overbought Level")+OB=input.int(100, title="Overbought Level")-OS=input(0, title="Oversold Level")+OS=input.int(0, title="Oversold Level")-barsizeThreshold=input(.5, step=.05, minval=.1, maxval=1, title="Bar Body Size, 1=No Wicks")+barsizeThreshold=input.float(.5, step=.05, minval=.1, maxval=1, title="Bar Body Size, 1=No Wicks")-i_MAFilter = input(true, title="Use MA Trend Filter")+i_MAFilter = input.bool(true, title="Use MA Trend Filter")-i_MALen = input(80, title="MA Length")+i_MALen = input.int(80, title="MA Length")-i_timedexit=input(false, title="Use 60 minutes exit rule")+i_timedexit=input.bool(false, title="Use 60 minutes exit rule")-short=input(true, title="Use Mirrored logic for Shorts")+short=input.bool(true, title="Use Mirrored logic for Shorts")/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------")  +title2=input.bool(true, "-----------------General Inputs-------------------")  // Backtester General Inputs-i_SL=input(true, title="Use Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Stop Loss and Take Profit")-i_SLType=input(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])+i_SLType=input.string(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])-i_SPL=input(defval=10, title="Swing Point Lookback")+i_SPL=input.int(defval=10, title="Swing Point Lookback")-i_PercIncrement=input(defval=3, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=3, step=.1, title="Swing Point SL Perc Increment")*0.01-i_ATR = input(14, title="ATR Length")+i_ATR = input.int(14, title="ATR Length")-i_ATRMult = input(5, step=.1, title="ATR Multiple")+i_ATRMult = input.int(5, step=.1, title="ATR Multiple")-i_TPRRR = input(2.2, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.float(2.2, step=.1, title="Take Profit Risk Reward Ratio")-TS=input(false, title="Trailing Stop")+TS=input.bool(false, title="Trailing Stop")// Bought and Sold Boolean Signal⋯//Trading Inputs-DPR=input(true, "Allow Direct Position Reverse")+DPR=input.bool(true, "Allow Direct Position Reverse")-reverse=input(false, "Reverse Trades")+reverse=input.bool(false, "Reverse Trades")// Entries⋯    if not DPR-        strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)+        if SELL and strategy.position_size == 0+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)+        if BUY and strategy.position_size == 0+            strategy.entry("short", strategy.short)    else     -        strategy.entry("long", strategy.long, when=SELL)+        if SELL+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=BUY)+        if BUY+            strategy.entry("short", strategy.short)else    if not DPR -        strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)+        if BUY and strategy.position_size == 0+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)+        if SELL and strategy.position_size == 0+            strategy.entry("short", strategy.short)    else-        strategy.entry("long", strategy.long, when=BUY)+        if BUY+            strategy.entry("long", strategy.long)-        strategy.entry("short", strategy.short, when=SELL)+        if SELL+            strategy.entry("short", strategy.short)if i_timedexit-    strategy.close_all(when=timedexit)+    if timedexit+        strategy.close_all()SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStop⋯    Ststop := na-strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL)-strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)+if i_SL+    strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL)/////////////////////// PLOTS //////////////////////////////////////////////////⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L83:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © tweakerID-//@version=5+//@version=6strategy("Money Flow Index 5 min Strategy", ⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Direction0int (written input.integer) · min -1 · max 1line 22
-----------------Strategy Inputs-------------------trueboolunused
MFI Length3intMFI
Overbought Level100intBUY
Oversold Level0intSELL
Bar Body Size, 1=No Wicks.5float · min .1 · max 1 · step .05shortwicksbar
Use MA Trend FiltertrueboolBUY SELL
MA Length80intSMA
Use 60 minutes exit rulefalseboolclose_all line 106
Use Mirrored logic for Shortstrueboolline 84
-----------------General Inputs-------------------trueboolunused
Use Stop Loss and Take Profittrueboolexit TP & SL SL SSL TP STP
Type Of StopStrategy Stopstring · options ["Strategy Stop", "Swing Lo/Hi", "ATR Stop"]SL SSL TP STP
Swing Point Lookback10intLL HH
Swing Point SL Perc Increment3int · step .1LL HH LongStop ShortStop
ATR Length14intATR
ATR Multiple5int · step .1ATR
Take Profit Risk Reward Ratio2.2float · step .1tp stp ATRtp ATRstp StratTP StratSTP
Trailing Stopfalseboolexit TP & SL SL SSL
Allow Direct Position Reversetrueboolentry long entry short entry long entry short entry long entry short entry long entry short line 93 line 100
Reverse Tradesfalseboolline 92

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Point Lookback (10)LL · line 48
  • Highest (highest, ta.highest in v5)Swing Point Lookback (10)HH · line 49
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, LL, 0LL_price · line 50
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, HH, 0HH_price · line 51
  • ATR (atr, ta.atr in v5)ATR Length (14)ATR · line 57
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRLong, 0ATRLongStop · line 60
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, ATRShort, 0ATRShortStop · line 61
  • Valuewhen (valuewhen, ta.valuewhen in v5)DayStart, low, 0LongStop · line 69
  • Valuewhen (valuewhen, ta.valuewhen in v5)DayStart, high, 0ShortStop · line 70
  • MFI (mfi, ta.mfi in v5)close, MFI Length (3)MFI · line 74
  • SMA (sma, ta.sma in v5)close, MA Length (80)SMA · line 78
  • Valuewhen (valuewhen, ta.valuewhen in v5)bought, time, 0timesinceentry · line 80

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.

The script has 72 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longSELL and strategy.position_size == 0On94
Open short shortBUY and strategy.position_size == 0On95
Open long longSELLOn97
Open short shortBUYOn98
Open long longBUY and strategy.position_size == 0On101
Open short shortSELL and strategy.position_size == 0On102
Open long longBUYOn104
Open short shortSELLOn105
Close timedexittimesinceentry == 60Off “Use 60 minutes exit rule”107
Exit TP & SL stop and limiti_SLOn133
Exit TP & SL stop and limiti_SLOn134

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.

4/4trades 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−6.8%+102.5%1856%0.8828.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+26.2%+5.5%1560%2.309.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+29.9%+9.8%2259%1.3522.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+37.9%+8.4%1573%3.4610.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.3%+16.7%3148%1.0036.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−15.5%+21.5%1547%0.6736.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−6.7%+148.3%2055%0.9024.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.0%+17.1%1953%1.0824.6%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 market540%−$432.20
Sideways market875%$1,290.75
Falling market540%−$1,537.49

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

How bad could the drawdown be?

35.3%

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, 17.2% to 35.3%; the tick is what actually happened, 27.7%. Order luck alone moves it this much.

0%41%
All 18 trades
SideEntryExitBarsP&L
long23 Apr 2024 66,819.3024 Apr 2024 63,792.801−$460.57
long16 Jul 2024 64,724.1021 Jul 2024 67,140.005$348.16
long30 Oct 2024 72,736.408 Nov 2024 75,857.909$416.08
long11 Nov 2024 80,370.0012 Nov 2024 88,648.001$1,052.17
long22 Nov 2024 98,317.1025 Nov 2024 92,862.703−$638.57
long7 Jan 2025 102,236.008 Jan 2025 93,296.401−$944.91
short27 Feb 2025 84,250.102 Mar 2025 89,154.703−$576.72
short10 Mar 2025 80,734.5019 Mar 2025 86,542.409−$668.88
long23 Apr 2025 93,443.003 May 2025 96,887.1010$307.21
long9 May 2025 103,262.0021 May 2025 108,107.0012$407.12
long10 Jun 2025 110,263.0011 Jul 2025 117,035.0031$559.68
long27 Oct 2025 114,559.003 Nov 2025 106,187.007−$723.52
short15 Nov 2025 94,594.0019 Nov 2025 90,068.404$427.02
short2 Dec 2025 86,286.005 Jan 2026 94,564.3034−$919.44
short21 Jan 2026 88,427.7031 Jan 2026 84,260.5010$397.70
short9 Mar 2026 65,971.2010 Mar 2026 71,602.101−$773.88
short4 Jun 2026 64,142.806 Jun 2026 60,282.702$487.43
long21 Aug 2026 73,027.0022 Aug 2026 78,338.001$624.99

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
Money Flow Index 5 min Strategy this page—v4 strategy−6.8%1828.4%
Trend Bounce [racer8] by racer8highest lowest sma valuewhenv4 strategy+2.4%2232.2%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%
Trend Following with Donchian Channels and MACD by Robrecht99highest lowest sma atrv5 strategy−1.0%122.7%
BuyHigh-SellLow Strategy by Trendoscopesma highest lowest atrv4 strategy+12.4%46.7%
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.3%754.7%

Where it runs

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

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// From "Crypto Day Trading Strategy" PDF file.// * I'm using a SMA filter to avoid buying when the price is declining. Time frame was better at 15 min according to my test.// 1 - Apply the 3 period Money Flow Index indicator to the 5 minute chart, using 0 and 100 as our oversold and overbought boundaries// 2 - Wait for the MFI to reach overbought levels, that indicates the presence of "big sharks" in the market. Price needs to hold up// the first two MFI overbought occurrences of the day to be considered as a bullish entry signal.*// 3 - We buy when the MFI = 100 and the next candle is a bullish candle with short wicks.// 4 - We place our Stop Loss below the low of the trading day and we Take Profit during the first 60 minutes after taking the trade. // The logic above can be used in a mirrored fashion to take short entries, this is a custom parameter that can be modified from// the strategy Inputs panel.// © tweakerID//@version=4strategy("Money Flow Index 5 min Strategy",      overlay=true,      default_qty_type=strategy.percent_of_equity,      default_qty_value=100,      initial_capital=10000,      commission_value=0.04,      calc_on_every_tick=false,      slippage=0)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))/////////////////////// STRATEGY INPUTS ////////////////////////////////////////title1=input(true, "-----------------Strategy Inputs-------------------")  i_MFI = input(3, title="MFI Length")OB=input(100, title="Overbought Level")OS=input(0, title="Oversold Level")barsizeThreshold=input(.5, step=.05, minval=.1, maxval=1, title="Bar Body Size, 1=No Wicks")i_MAFilter = input(true, title="Use MA Trend Filter")i_MALen = input(80, title="MA Length")i_timedexit=input(false, title="Use 60 minutes exit rule")short=input(true, title="Use Mirrored logic for Shorts")/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------")  // Backtester General Inputsi_SL=input(true, title="Use Stop Loss and Take Profit")i_SLType=input(defval="Strategy Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])i_SPL=input(defval=10, title="Swing Point Lookback")i_PercIncrement=input(defval=3, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(5, step=.1, title="ATR Multiple")i_TPRRR = input(2.2, step=.1, title="Take Profit Risk Reward Ratio")TS=input(false, title="Trailing Stop")// Bought and Sold Boolean Signalbought = strategy.position_size > strategy.position_size[1]  or strategy.position_size < strategy.position_size[1]// Price Action Stop and Take ProfitLL=(lowest(i_SPL))*(1-i_PercIncrement)HH=(highest(i_SPL))*(1+i_PercIncrement)LL_price = valuewhen(bought, LL, 0)HH_price = valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na entry_HH_price = strategy.position_size < 0 ? HH_price : na tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRRstp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR// ATR StopATR=atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATRATRLongStop = valuewhen(bought, ATRLong, 0)ATRShortStop = valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRRATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR// Strategy StopDayStart = time == timestamp("UTC", year, month, dayofmonth, 0, 0, 0)plot(DayStart ? 1e9 : na, style=plot.style_columns, color=color.silver, transp=80, title="Trade Day Start")float LongStop = valuewhen(DayStart,low,0)*(1-i_PercIncrement)float ShortStop = valuewhen(DayStart,high,0)*(1+i_PercIncrement)float StratTP = strategy.position_avg_price + (strategy.position_avg_price - LongStop)*i_TPRRRfloat StratSTP = strategy.position_avg_price - (ShortStop - strategy.position_avg_price)*i_TPRRR/////////////////////// STRATEGY LOGIC /////////////////////////////////////////MFI=mfi(close,i_MFI)barsize=high-lowbarbodysize=close>open?(open-close)*-1:(open-close)shortwicksbar=barbodysize>barsize*barsizeThresholdSMA=sma(close, i_MALen)MAFilter=close > SMAtimesinceentry=(time - valuewhen(bought, time, 0)) / 60000timedexit=timesinceentry == 60BUY = MFI[1] == OB and close > open and shortwicksbar and (i_MAFilter ? MAFilter : true)bool SELL = naif short    SELL := MFI[1] == OS and close < open and shortwicksbar and (i_MAFilter ? not MAFilter : true)//Debugging Plotsplot(timesinceentry, transp=100, title="Time Since Entry")//Trading InputsDPR=input(true, "Allow Direct Position Reverse")reverse=input(false, "Reverse Trades")// Entriesif reverse    if not DPR        strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)        strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)    else             strategy.entry("long", strategy.long, when=SELL)        strategy.entry("short", strategy.short, when=BUY)else    if not DPR         strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)        strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)    else        strategy.entry("long", strategy.long, when=BUY)        strategy.entry("short", strategy.short, when=SELL)if i_timedexit    strategy.close_all(when=timedexit)SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStopSSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStopTP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTPSTP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP//TrailingStopdif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0)) -strategy.position_avg_pricetrailOffset     = strategy.position_avg_price - SLvar tstop = float(na)if strategy.position_size > 0    tstop := high- trailOffset - dif    if tstop<tstop[1]        tstop:=tstop[1]else    tstop := naStrailOffset     = SSL - strategy.position_avg_pricevar Ststop = float(na)Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0  and strategy.position_size[1]>=0, low,0))if strategy.position_size < 0    Ststop := low+ StrailOffset + Sdif    if Ststop>Ststop[1]        Ststop:=Ststop[1]else    Ststop := nastrategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(i_SL and strategy.position_size > 0 and not TS ? SL : i_SL and strategy.position_size > 0 and TS ? tstop : na , title='SL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size < 0 and not TS ? SSL : i_SL and strategy.position_size < 0 and TS ? Ststop : na , title='SSL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(i_SL and strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)// Draw price action setup arrowsplotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar,  color=color.green, title="Bullish Setup", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar,  color=color.red, title="Bearish Setup", size=size.auto)