Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Kifier's MFI-STOCH Hidden Divergence-Trend Beater

A Pine Script v4 strategy built on Crossover (_source, _center), Crossunder (_source, _center) and Change (_source). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 95% of equity and pays no commission. 25 settings; defaults include VWMA Length 50, SMA Length 50 and Stoch Length 28.

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 Kifier's MFI-STOCH Hidden Divergence-Trend Beater repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Kifier's MFI-STOCH Hidden Divergence-Trend Beater do on BTCUSDT 1D with default settings?
−2.73%
From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Kifier's MFI-STOCH Hidden Divergence-Trend Beater be converted to Pine Script v5?
No
The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L138:C12: 'obv' was renamed to 'ta.obv' in Pine Script v5), so no v5 download is offered; the edits are shown below.
Does Kifier's MFI-STOCH Hidden Divergence-Trend Beater use a stop loss?
Yes
strategy.exit sets a stop on line 170.
Does Kifier's MFI-STOCH Hidden Divergence-Trend Beater run in Zeal Terminal?
Yes
It compiles in 60 ms and runs 1,000 bars in 156 ms, in the browser.

BTCUSDT · 1D · default settings

  • Base
  • Max
  • Plot
  • Plot
  • Top Line
  • Mid Line
  • Bot Line
  • 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 (19)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctBase$97,268$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. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep. Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 159, 162) so the engine trades the way the script says.
Net profit
−2.73%
−$2,731.74
Buy and hold
+102.5%
same period
Closed trades
2
1 won · 1 lost
Profitable
50.0%
of closed trades
Profit factor
0.78
gross profit ÷ gross loss
Max drawdown
13.66%
−$14,953.50

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.

  • Likely bug

    pivothigh(high, 20, 20) ignores the settings line 54

    Line 54 hard-codes 20 where line 81 uses “Price Divergant Pivots” and 20 where line 81 uses “Price Divergant Pivots”. Changing those settings moves one band but not this one.

    pivothigh(high,20,20)pivothigh(high, i_div_price, i_div_price)
  • Likely bug

    pivotlow(low, 20, 20) ignores the settings line 55

    Line 55 hard-codes 20 where line 82 uses “Price Divergant Pivots” and 20 where line 82 uses “Price Divergant Pivots”. Changing those settings moves one band but not this one.

    pivotlow(low,20,20)pivotlow(low, i_div_price, i_div_price)
  • Likely bug

    ema(obv, 100) ignores the settings line 138

    Line 138 hard-codes 100 where line 75 uses “ATR Ranging-trend len”. Changing those settings moves one band but not this one.

    ema(obv,100)ema(obv, i_atr_len)
  • Check

    2 settings do nothing

    “OBV Length”, “Divergance Valid Period” are declared but never read.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    1 setting has no label

    In the settings dialog i_mfi_right (line 21) 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 iff(), which v5 removed line 10

    iff() on line 10, 68, 76, 78, 79, 128, 145, 145, 148, 148, 152. v5 writes it as the ternary c ? a : b.

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 crossover → ta.crossover, crossunder → ta.crossunder, change → ta.change, max → math.max, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, stoch → ta.stoch, vwma → ta.vwma, sma → ta.sma, ema → ta.ema, atr → ta.atr, mfi → ta.mfi, highest → ta.highest, stdev → ta.stdev.

v4 → v5

Differs

The v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L138:C12: 'obv' was renamed to 'ta.obv' in Pine Script v5.

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.bool) → input.bool()
  • Line 7: input(type = input.bool) → input.bool()
  • Line 8: input(type = input.time) → input.time()
  • Line 9: input(type = input.time) → input.time()
  • Line 10: iff(c, a, b) → (c ? a : b)
62 more edits
  • Line 11: input(type = input.integer) → input.int()
  • Line 12: input(type = input.integer) → input.int()
  • Line 13: input(type = input.integer) → input.int()
  • Line 14: input(type = input.integer) → input.int()
  • Line 15: input(type = input.integer) → input.int()
  • Line 16: input(type = input.integer) → input.int()
  • Line 17: input(type = input.integer) → input.int()
  • Line 18: input(type = input.float) → input.float()
  • Line 19: input(type = input.integer) → input.int()
  • Line 20: input(type = input.integer) → input.int()
  • Line 21: input(type = input.integer) → input.int()
  • Line 22: input(type = input.float) → input.float()
  • Line 23: input(type = input.float) → input.float()
  • Line 24: input(type = input.bool) → input.bool()
  • Line 25: input(type = input.bool) → input.bool()
  • Line 26: input(type = input.color) → input.color()
  • Line 27: input(type = input.color) → input.color()
  • Line 28: input(type = input.color) → input.color()
  • Line 29: input(type = input.color) → input.color()
  • Line 30: input(type = input.color) → input.color()
  • Line 31: input(type = input.color) → input.color()
  • Line 37: crossover → ta.crossover
  • Line 38: crossunder → ta.crossunder
  • Line 39: change → ta.change
  • Line 45: max → math.max
  • Line 46: max → math.max
  • Line 47: max → math.max
  • Line 54: pivothigh → ta.pivothigh
  • Line 55: pivotlow → ta.pivotlow
  • Line 68: iff(c, a, b) → (c ? a : b)
  • Line 68: crossover → ta.crossover
  • Line 70: stoch → ta.stoch
  • Line 71: vwma → ta.vwma
  • Line 72: sma → ta.sma
  • Line 74: ema → ta.ema
  • Line 74: atr → ta.atr
  • Line 75: ema → ta.ema
  • Line 75: atr → ta.atr
  • Line 76: iff(c, a, b) → (c ? a : b)
  • Line 77: mfi → ta.mfi
  • Line 78: iff(c, a, b) → (c ? a : b)
  • Line 79: iff(c, a, b) → (c ? a : b)
  • Line 81: pivothigh → ta.pivothigh
  • Line 82: pivotlow → ta.pivotlow
  • Line 103: pivothigh → ta.pivothigh
  • Line 104: pivotlow → ta.pivotlow
  • Line 110: highest → ta.highest
  • Line 128: iff(c, a, b) → (c ? a : b)
  • Line 134: stdev → ta.stdev
  • Line 136: stdev → ta.stdev
  • Line 137: stdev → ta.stdev
  • Line 138: ema → ta.ema
  • Line 139: crossover → ta.crossover
  • Line 141: crossunder → ta.crossunder
  • Line 145: iff(c, a, b) → (c ? a : b)
  • Line 145: iff(c, a, b) → (c ? a : b)
  • Line 145: crossover → ta.crossover
  • Line 148: iff(c, a, b) → (c ? a : b)
  • Line 148: iff(c, a, b) → (c ? a : b)
  • Line 152: iff(c, a, b) → (c ? a : b)
  • Line 159: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 162: strategy.entry(…, true) → strategy.entry(…, strategy.long)
⋯// © kifier-//@version=4+//@version=5strategy("Kifier's MFI/STOCH Hidden Divergence/Trend Beater", shorttitle = "Kifier's MFI/STOCH", overlay=false, margin_long=100, margin_short=100, default_qty_type  = strategy.percent_of_equity, default_qty_value = 95, max_boxes_count = 500)//Values-enb_date     = input(false                                  ,"Enable Date Range?",      type = input.bool, inline = "1")+enb_date     = input.bool(false                                  ,"Enable Date Range?", inline = "1")-enb_current  = input(true                                   ,"Today as End Date" ,      type = input.bool, inline = "1")+enb_current  = input.bool(true                                   ,"Today as End Date" , inline = "1")-i_start_date = input(timestamp("01 Jan 2021 00:00 +0300")   ,"Start Date"        ,      type=input.time)+i_start_date = input.time(timestamp("01 Jan 2021 00:00 +0300")   ,"Start Date"        )-i_end_date   = input(timestamp("16 July 2021 00:00 +0300")  ,"End Date"          ,      type=input.time)+i_end_date   = input.time(timestamp("16 July 2021 00:00 +0300")  ,"End Date"          )-time_check   = iff(enb_date ? (time >= i_start_date) and (enb_current ? true : time <= i_end_date) : true, true, false)+time_check   = (enb_date ? (time >= i_start_date) and (enb_current ? true : time <= i_end_date) : true ? true : false)-i_vwma_length   = input(50,     "VWMA Length"               ,type = input.integer,   group = "Indicator Settings", inline = "2")+i_vwma_length   = input.int(50,     "VWMA Length"               ,   group = "Indicator Settings", inline = "2")-i_sma_length    = input(50,     "SMA Length"                ,type = input.integer,   group = "Indicator Settings", inline = "2")+i_sma_length    = input.int(50,     "SMA Length"                ,   group = "Indicator Settings", inline = "2")-i_stoch_length  = input(28,     "Stoch Length"              ,type = input.integer,   group = "Indicator Settings", inline = "3")+i_stoch_length  = input.int(28,     "Stoch Length"              ,   group = "Indicator Settings", inline = "3")-i_mfi_length    = input(7 ,     "MFI Length"                ,type = input.integer,   group = "Indicator Settings", inline = "3")+i_mfi_length    = input.int(7 ,     "MFI Length"                ,   group = "Indicator Settings", inline = "3")-i_obv_length    = input(100,    "OBV Length"                ,type = input.integer,   group = "Indicator Settings")+i_obv_length    = input.int(100,    "OBV Length"                ,   group = "Indicator Settings")-i_atr_len       = input(100,    "ATR Ranging-trend len"     ,type = input.integer,   group = "Indicator Settings", tooltip = "This is the length of the ATR Emas that check when the market in a general trend or is just ranging")+i_atr_len       = input.int(100,    "ATR Ranging-trend len"     ,   group = "Indicator Settings", tooltip = "This is the length of the ATR Emas that check when the market in a general trend or is just ranging")-i_div_price     = input(5       ,"Price Divergant Pivots"   ,type = input.integer, group = "Divergance Settings")+i_div_price     = input.int(5       ,"Price Divergant Pivots"   , group = "Divergance Settings")-i_inacc         = input(0.05    ,"Price Inaccuracy"         ,type = input.float  , group = "Divergance Settings")+i_inacc         = input.float(0.05    ,"Price Inaccuracy"           , group = "Divergance Settings")-i_div_length    = input(3       ,"Divergance Valid Period"  ,type = input.integer, group = "Divergance Settings")+i_div_length    = input.int(3       ,"Divergance Valid Period"  , group = "Divergance Settings")-i_mfi_left      = input(5       ,"MFI Left/Right Pivots"    ,type = input.integer, group = "Divergance Settings", inline = "4")+i_mfi_left      = input.int(5       ,"MFI Left/Right Pivots"    , group = "Divergance Settings", inline = "4")-i_mfi_right     = input(2       ,""                         ,type = input.integer, group = "Divergance Settings", inline = "4")+i_mfi_right     = input.int(2       ,""                         , group = "Divergance Settings", inline = "4")-tp_percentage   = input(10  ,   "TP Percentage"         ,type = input.float             , group = "Exit Settings")/100+tp_percentage   = input.float(10  ,   "TP Percentage"                      , group = "Exit Settings")/100-_inacc          = input(0.03,   "Support Inaccuracy"    ,type = input.float, step = 0.01, group = "Exit Settings")+_inacc          = input.float(0.03,   "Support Inaccuracy"    , step = 0.01, group = "Exit Settings")-enb_stoch_mfi     = input(true, "Use Stoch/MFI Trend"      , type = input.bool, group = "Individual Entries")+enb_stoch_mfi     = input.bool(true, "Use Stoch/MFI Trend"      , group = "Individual Entries")-enb_stoch_mfi_div = input(true, "Use Stoch/MFI Divergance ", type = input.bool, group = "Individual Entries")+enb_stoch_mfi_div = input.bool(true, "Use Stoch/MFI Divergance ", group = "Individual Entries")-c_mfi           = input(color.yellow    ,"MFI/STOCH Colour     "        , type = input.color, group = "Indicator Colours", inline = "os")+c_mfi           = input.color(color.yellow    ,"MFI/STOCH Colour     "        , group = "Indicator Colours", inline = "os")-c_stoch         = input(color.silver    ,""                             , type = input.color, group = "Indicator Colours", inline = "os")+c_stoch         = input.color(color.silver    ,""                             , group = "Indicator Colours", inline = "os")-c_buy           = input(color.green     ,"Buy/Sell Colour      "        , type = input.color, group = "Indicator Colours", inline = "pos")+c_buy           = input.color(color.green     ,"Buy/Sell Colour      "        , group = "Indicator Colours", inline = "pos")-c_sell          = input(color.red       ,""                             , type = input.color, group = "Indicator Colours", inline = "pos")+c_sell          = input.color(color.red       ,""                             , group = "Indicator Colours", inline = "pos")-c_flat          = input(color.blue      ,"Flat/Trending Colours"        , type = input.color, group = "Indicator Colours", inline = "trend")+c_flat          = input.color(color.blue      ,"Flat/Trending Colours"        , group = "Indicator Colours", inline = "trend")-c_longtrend     = input(color.green     ,""                             , type = input.color, group = "Indicator Colours", inline = "trend")+c_longtrend     = input.color(color.green     ,""                             , group = "Indicator Colours", inline = "trend")//Global Variables⋯    var float _qtyAdvDec = 0.-    bool  _xUp     = crossover(_source, _center)+    bool  _xUp     = ta.crossover(_source, _center)-    bool  _xDn     = crossunder(_source, _center)+    bool  _xDn     = ta.crossunder(_source, _center)-    float _chg     = change(_source)+    float _chg     = ta.change(_source)    bool  _up      = _chg > 0⋯    _qtyAdvDec := -      _srcBull ? _xUp ? 1 : _up ? _qtyAdvDec + 1 : _dn ? max(1, _qtyAdvDec - 1) : _qtyAdvDec :+      _srcBull ? _xUp ? 1 : _up ? _qtyAdvDec + 1 : _dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec :-      _srcBear ? _xDn ? 1 : _dn ? _qtyAdvDec + 1 : _up ? max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec+      _srcBear ? _xDn ? 1 : _dn ? _qtyAdvDec + 1 : _up ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec-    _maxAdvDec := max(_maxAdvDec, _qtyAdvDec)+    _maxAdvDec := math.max(_maxAdvDec, _qtyAdvDec)    float _transp = 100 - (_qtyAdvDec * 100 / _maxAdvDec)⋯var float _pL = na-_ph = pivothigh(high,20,20)+_ph = ta.pivothigh(high,20,20)-_pl = pivotlow(low,20,20)+_pl = ta.pivotlow(low,20,20)_high_inacc = _inacc * high⋯    _pL := nz(_pL)  -broke_res = iff(crossover(close, _pH), true, false)+broke_res = (ta.crossover(close, _pH) ? true : false)//Indicator Initialisation-s_stoch = stoch(close, high, low, i_stoch_length) +s_stoch = ta.stoch(close, high, low, i_stoch_length) -s_vwma = vwma(close,i_vwma_length)+s_vwma = ta.vwma(close,i_vwma_length)-s_sma = sma(close,i_sma_length)+s_sma = ta.sma(close,i_sma_length)//MONEY FLOW + BBW-atr1 =ema((atr(14)/close),i_atr_len/2)+atr1 =ta.ema((ta.atr(14)/close),i_atr_len/2)-atr2 =ema((atr(14)/close), i_atr_len)+atr2 =ta.ema((ta.atr(14)/close), i_atr_len)-is_ranging = iff(atr1 < atr2, true, false)+is_ranging = (atr1 < atr2 ? true : false)-s_mfi = mfi(close,i_mfi_length)+s_mfi = ta.mfi(close,i_mfi_length)-overTop = iff(s_mfi >= 90, true, false)+overTop = (s_mfi >= 90 ? true : false)-underBot = iff(s_mfi <= 10, true, false)+underBot = (s_mfi <= 10 ? true : false)//Price Divergance-ph = pivothigh(high, i_div_price,i_div_price)+ph = ta.pivothigh(high, i_div_price,i_div_price)-pl = pivotlow(low,i_div_price,i_div_price)+pl = ta.pivotlow(low,i_div_price,i_div_price)var float pH = 0.0⋯//MFI Divergance-mh = pivothigh(s_mfi, i_mfi_left,i_mfi_right)+mh = ta.pivothigh(s_mfi, i_mfi_left,i_mfi_right)-ml = pivotlow(s_mfi, i_mfi_left,i_mfi_right)+ml = ta.pivotlow(s_mfi, i_mfi_left,i_mfi_right)bl = bar_index⋯if mh-    mH := highest(nz(mh),i_mfi_left)+    mH := ta.highest(nz(mh),i_mfi_left)    mH := nz(mH)⋯//Higher low on price, lower low on rsi, then check with stoch-mfi_div_bullish = iff(higher_low and higher_low_m, true, false)+mfi_div_bullish = (higher_low and higher_low_m ? true : false)if mfi_div_bullish⋯_src = s_vwma-s_sma-sd_src = stdev(_src,14)+sd_src = ta.stdev(_src,14)pooled_src = (_src/sd_src)*2-sd_s_vwma = stdev(s_vwma,14)+sd_s_vwma = ta.stdev(s_vwma,14)-sd_s_sma = stdev(s_sma,14)+sd_s_sma = ta.stdev(s_sma,14)-longTrend = obv > ema(obv,100) and is_ranging == false+longTrend = obv > ta.ema(obv,100) and is_ranging == false-crossOver = crossover(s_vwma , s_sma)+crossOver = ta.crossover(s_vwma , s_sma)crossingOver = (s_vwma > s_sma) and (close >= s_vwma) -crossUnder = crossunder(s_vwma, s_sma)+crossUnder = ta.crossunder(s_vwma, s_sma)crossingUnder = (s_vwma < s_sma) and (close <= s_vwma)⋯//Strategy Entries-mfi_stoch_trend = iff(enb_stoch_mfi, iff(s_stoch >= 50 and crossover(s_mfi, 50) and crossingOver and longTrend and is_ranging == false, true, false), false)+mfi_stoch_trend = (enb_stoch_mfi ? (s_stoch >= 50 and ta.crossover(s_mfi, 50) and crossingOver and longTrend and is_ranging == false ? true : false) : false)var buy_counter_rsi = 0var buy_counter_mfi = 0-mfi_div = iff(enb_stoch_mfi_div, iff(mfi_div_bullish and crossingOver and s_stoch >= 50 and is_ranging, true, false), false)+mfi_div = (enb_stoch_mfi_div ? (mfi_div_bullish and crossingOver and s_stoch >= 50 and is_ranging ? true : false) : false)if mfi_div⋯    -mfi_divergent_buy = iff(bar_index <= buy_counter_mfi and strategy.position_size == 0, true, false)+mfi_divergent_buy = (bar_index <= buy_counter_mfi and strategy.position_size == 0 ? true : false)//Strategy Entries⋯    if mfi_stoch_trend-        strategy.entry("Buy", true, comment = "[B] STOCH/MFI")+        strategy.entry("Buy", strategy.long, comment = "[B] STOCH/MFI")        order_fired := true    if mfi_divergent_buy-        strategy.entry("Buy", true, comment = "[B] MFI Hidden Divergance")+        strategy.entry("Buy", strategy.long, comment = "[B] MFI Hidden Divergance")        order_fired := true⋯

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L138:C12: 'obv' was renamed to 'ta.obv' in Pine Script v5.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © kifier-//@version=5+//@version=6strategy("Kifier's MFI/STOCH Hidden Divergence/Trend Beater", shorttitle = "Kifier's MFI/STOCH", overlay=false, margin_long=100, margin_short=100, default_qty_type  = strategy.percent_of_equity, default_qty_value = 95, max_boxes_count = 500)⋯

Settings

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

SettingDefaultType and rangeFeeds
Enable Date Range?falsebooltime_check
Today as End Datetruebooltime_check
Start Datetimestamp("01 Jan 2021 00:00 +0300")timetime_check
End Datetimestamp("16 July 2021 00:00 +0300")timetime_check
Indicator Settings
VWMA Length50int (written input.integer)s_vwma
SMA Length50int (written input.integer)s_sma
Stoch Length28int (written input.integer)s_stoch
MFI Length7int (written input.integer)s_mfi
OBV Length100int (written input.integer)unused
ATR Ranging-trend lenThis is the length of the ATR Emas that check when the market in a general trend or is just ranging100int (written input.integer)atr1 atr2
Divergance Settings
Price Divergant Pivots5int (written input.integer)ph pl
Price Inaccuracy0.05floathigh_acc low_acc
Divergance Valid Period3int (written input.integer)unused
MFI Left/Right Pivots5int (written input.integer)mh ml mH
I mfi right (no label in the script)2int (written input.integer)mh ml
Exit Settings
TP Percentage10floattpprice
Support Inaccuracy0.03float · step 0.01_high_inacc _low_inacc
Individual Entries
Use Stoch/MFI Trendtrueboolmfi_stoch_trend
Use Stoch/MFI Divergance trueboolmfi_div
Indicator Colours
MFI/STOCH Colour color.yellowcolorp_mfi plot
C stoch (no label in the script)color.silvercolorp_stoch plot fill
Buy/Sell Colour color.greencolorhist_color plotshape
C sell (no label in the script)color.redcolorhist_color plotshape
Flat/Trending Colourscolor.bluecolor_box
C longtrend (no label in the script)color.greencolor_box

What it calculates

  • Crossover (crossover, ta.crossover in v5)_source, _center_xUp · line 37
  • Crossunder (crossunder, ta.crossunder in v5)_source, _center_xDn · line 38
  • Change (change, ta.change in v5)_source_chg · line 39
  • Pivothigh (pivothigh, ta.pivothigh in v5)high, 20, 20_ph · line 54
  • Pivotlow (pivotlow, ta.pivotlow in v5)low, 20, 20_pl · line 55
  • Crossover (crossover, ta.crossover in v5)close, _pHbroke_res · line 68
  • Stoch (stoch, ta.stoch in v5)close, high, low, Stoch Length (28)s_stoch · line 70
  • VWMA (vwma, ta.vwma in v5)close, VWMA Length (50)s_vwma · line 71
  • SMA (sma, ta.sma in v5)close, SMA Length (50)s_sma · line 72
  • EMA / ATR (ema, ta.ema in v5)(atr(14)/close), i_atr_len/2atr1 · line 74
  • EMA / ATR (ema, ta.ema in v5)(atr(14)/close), ATR Ranging-trend len (100)atr2 · line 75
  • MFI (mfi, ta.mfi in v5)close, MFI Length (7)s_mfi · line 77
  • Pivothigh (pivothigh, ta.pivothigh in v5)high, Price Divergant Pivots (5), Price Divergant Pivots (5)ph · line 81
  • Pivotlow (pivotlow, ta.pivotlow in v5)low, Price Divergant Pivots (5), Price Divergant Pivots (5)pl · line 82
  • Pivothigh (pivothigh, ta.pivothigh in v5)s_mfi, MFI Left/Right Pivots (5), I mfi right (2)mh · line 103
  • Pivotlow (pivotlow, ta.pivotlow in v5)s_mfi, MFI Left/Right Pivots (5), I mfi right (2)ml · line 104
  • Highest (highest, ta.highest in v5)nz(mh), MFI Left/Right Pivots (5)mH · line 110
  • Stdev (stdev, ta.stdev in v5)_src, 14sd_src · line 134
  • Stdev (stdev, ta.stdev in v5)s_vwma, 14sd_s_vwma · line 136
  • Stdev (stdev, ta.stdev in v5)s_sma, 14sd_s_sma · line 137
  • Crossover (crossover, ta.crossover in v5)s_vwma, s_smacrossOver · line 139
  • Crossunder (crossunder, ta.crossunder in v5)s_vwma, s_smacrossUnder · line 141

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 79 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Buy longmfi_stoch_trendOn159
Open Buy longmfi_divergent_buyOn162
Exit Buy limitstrategy.position_size > 0On168
Exit Buy stopclose <= previousResOn170

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−2.7%+102.5%250%0.7813.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.8%+5.5%10%0.0026.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−14.4%+9.8%333%0.4024.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+14.9%+8.4%367%3.9932.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−26.6%+16.7%250%0.2635.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+19.0%+21.5%475%2.5513.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+11.5%+148.3%367%2.5013.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+18.6%+17.1%650%2.479.8%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Stoch Length 14, MFI Length 8) made +19.9% before 26 Dec 2025 and −12.9% after it, worse than the defaults' 0.0% after. Tuning on the past did not carry forward. 29% of the 56 combinations made money in-sample and 0% out-of-sample.

Before 26 Dec 2025 · in-sample
MFI Length ↓ · Stoch Length →1417202428343948
4−4%−4%−4%−4%−4%−4%−4%−4%
5−6%−6%−6%−6%−6%−6%−6%−6%
6−3%−3%−3%−3%−3%−3%−3%−3%
7−3%−3%−3%−3%−3%−3%−3%−3%
8+20%+20%+20%+20%+20%+20%+20%+20%
10+20%+20%+20%+20%+20%+20%+20%+20%
12−4%−4%−4%−4%−4%−4%−4%−4%
From 26 Dec 2025 · out-of-sample
MFI Length ↓ · Stoch Length →1417202428343948
40%0%0%0%0%0%0%0%
50%0%0%0%0%0%0%0%
60%0%0%0%0%0%0%0%
70%0%0%0%0%0%0%0%
8−13%−13%−13%−13%−13%−13%−13%−13%
100%0%0%0%0%0%0%0%
120%0%0%0%0%0%0%0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market10%−$12,231.80
Sideways market1100%$9,500.02
Falling market0—$0.00

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

How bad could the drawdown be?

11.2%

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

0%13%
All 2 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.509 Feb 2024 46,005.9013$9,500.02
long16 Jan 2025 100,497.0026 Feb 2025 88,680.4041−$12,231.80

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
Kifier's MFI-STOCH Hidden Divergence-Trend Beater this page—v4 strategy−2.7%213.7%
Villa Dinamic Pivot Supertrend Strategy by VILIO_Tradingpivothigh pivotlow atr ema smav5 strategyNo trades on this market
supertrend with multiple filter strategy by mathlabelsma highest ema mfi atr stdev stoch pivothigh pivotlowv5 strategydoes not run in Zeal Terminal
WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020ema sma stdev stoch highestv4 strategy−0.5%62.2%
X48 - Strategy - BreakOut & Consecutive (11in1) + Alert - V.1.2 by X4815162342sma ema highest stdev pivothigh pivotlow atrv5 strategydoes not run in Zeal Terminal
Divergence for Many [Dimkud - v5] by dimkudsma mfi highest vwma ema stdev pivothigh pivotlow atrv5 strategy−0.0%240.4%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 159, 162) 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.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © kifier//@version=4strategy("Kifier's MFI/STOCH Hidden Divergence/Trend Beater", shorttitle = "Kifier's MFI/STOCH", overlay=false, margin_long=100, margin_short=100, default_qty_type  = strategy.percent_of_equity, default_qty_value = 95, max_boxes_count = 500)//Valuesenb_date     = input(false                                  ,"Enable Date Range?",      type = input.bool, inline = "1")enb_current  = input(true                                   ,"Today as End Date" ,      type = input.bool, inline = "1")i_start_date = input(timestamp("01 Jan 2021 00:00 +0300")   ,"Start Date"        ,      type=input.time)i_end_date   = input(timestamp("16 July 2021 00:00 +0300")  ,"End Date"          ,      type=input.time)time_check   = iff(enb_date ? (time >= i_start_date) and (enb_current ? true : time <= i_end_date) : true, true, false)i_vwma_length   = input(50,     "VWMA Length"               ,type = input.integer,   group = "Indicator Settings", inline = "2")i_sma_length    = input(50,     "SMA Length"                ,type = input.integer,   group = "Indicator Settings", inline = "2")i_stoch_length  = input(28,     "Stoch Length"              ,type = input.integer,   group = "Indicator Settings", inline = "3")i_mfi_length    = input(7 ,     "MFI Length"                ,type = input.integer,   group = "Indicator Settings", inline = "3")i_obv_length    = input(100,    "OBV Length"                ,type = input.integer,   group = "Indicator Settings")i_atr_len       = input(100,    "ATR Ranging-trend len"     ,type = input.integer,   group = "Indicator Settings", tooltip = "This is the length of the ATR Emas that check when the market in a general trend or is just ranging")i_div_price     = input(5       ,"Price Divergant Pivots"   ,type = input.integer, group = "Divergance Settings")i_inacc         = input(0.05    ,"Price Inaccuracy"         ,type = input.float  , group = "Divergance Settings")i_div_length    = input(3       ,"Divergance Valid Period"  ,type = input.integer, group = "Divergance Settings")i_mfi_left      = input(5       ,"MFI Left/Right Pivots"    ,type = input.integer, group = "Divergance Settings", inline = "4")i_mfi_right     = input(2       ,""                         ,type = input.integer, group = "Divergance Settings", inline = "4")tp_percentage   = input(10  ,   "TP Percentage"         ,type = input.float             , group = "Exit Settings")/100_inacc          = input(0.03,   "Support Inaccuracy"    ,type = input.float, step = 0.01, group = "Exit Settings")enb_stoch_mfi     = input(true, "Use Stoch/MFI Trend"      , type = input.bool, group = "Individual Entries")enb_stoch_mfi_div = input(true, "Use Stoch/MFI Divergance ", type = input.bool, group = "Individual Entries")c_mfi           = input(color.yellow    ,"MFI/STOCH Colour     "        , type = input.color, group = "Indicator Colours", inline = "os")c_stoch         = input(color.silver    ,""                             , type = input.color, group = "Indicator Colours", inline = "os")c_buy           = input(color.green     ,"Buy/Sell Colour      "        , type = input.color, group = "Indicator Colours", inline = "pos")c_sell          = input(color.red       ,""                             , type = input.color, group = "Indicator Colours", inline = "pos")c_flat          = input(color.blue      ,"Flat/Trending Colours"        , type = input.color, group = "Indicator Colours", inline = "trend")c_longtrend     = input(color.green     ,""                             , type = input.color, group = "Indicator Colours", inline = "trend")//Global Variablesvar float tpprice = na f_c_gradientAdvDec(_source, _center, _c_bear, _c_bull) =>    var float _maxAdvDec = 0.    var float _qtyAdvDec = 0.    bool  _xUp     = crossover(_source, _center)    bool  _xDn     = crossunder(_source, _center)    float _chg     = change(_source)    bool  _up      = _chg > 0    bool  _dn      = _chg < 0    bool  _srcBull = _source > _center    bool  _srcBear = _source < _center    _qtyAdvDec :=       _srcBull ? _xUp ? 1 : _up ? _qtyAdvDec + 1 : _dn ? max(1, _qtyAdvDec - 1) : _qtyAdvDec :      _srcBear ? _xDn ? 1 : _dn ? _qtyAdvDec + 1 : _up ? max(1, _qtyAdvDec - 1) : _qtyAdvDec : _qtyAdvDec    _maxAdvDec := max(_maxAdvDec, _qtyAdvDec)    float _transp = 100 - (_qtyAdvDec * 100 / _maxAdvDec)    var color _return = na    _return := _srcBull ? color.new(_c_bull, _transp) : _srcBear ? color.new(_c_bear, _transp) : _return//Simple Sup/Resvar float _pH = navar float _pL = na_ph = pivothigh(high,20,20)_pl = pivotlow(low,20,20)_high_inacc = _inacc * high_low_inacc = _inacc * lowif _ph    _pH := highif (high-_high_inacc) > _pH and _ph    _pH := high    _pH := nz(_pH)if _pl    _pL := lowif (low+_low_inacc) < _pL[1]     _pL := low    _pL := nz(_pL)  broke_res = iff(crossover(close, _pH), true, false)//Indicator Initialisations_stoch = stoch(close, high, low, i_stoch_length) s_vwma = vwma(close,i_vwma_length)s_sma = sma(close,i_sma_length)//MONEY FLOW + BBWatr1 =ema((atr(14)/close),i_atr_len/2)atr2 =ema((atr(14)/close), i_atr_len)is_ranging = iff(atr1 < atr2, true, false)s_mfi = mfi(close,i_mfi_length)overTop = iff(s_mfi >= 90, true, false)underBot = iff(s_mfi <= 10, true, false)//Price Diverganceph = pivothigh(high, i_div_price,i_div_price)pl = pivotlow(low,i_div_price,i_div_price)var float pH = 0.0var float pL = 0.0high_acc = high * (i_inacc)low_acc = low * i_inaccif (high-high_acc) > pH or (high+high_acc < pH) and ph    pH := high    pH := nz(pH)if (low+low_acc) < pL or (low-low_acc > pL) and pl    pL := low    pL := nz(pL)higher_low = falselower_low = false//Filter out innacurateif ph or pl    if pL < pL[1]        lower_low := true    if pL > pL[1]        higher_low := true        //MFI Divergancemh = pivothigh(s_mfi, i_mfi_left,i_mfi_right)ml = pivotlow(s_mfi, i_mfi_left,i_mfi_right)bl = bar_indexvar float mH = 0.0var float mL = 0.0var int bL = 0if mh    mH := highest(nz(mh),i_mfi_left)    mH := nz(mH)if ml    bL := bar_index    mL := ml    mL := nz(mL)higher_low_m = falselower_low_m = falseif ml     if mL < mL[1]        lower_low_m := true    if mL > mL[1]        higher_low_m := true//Combintionvar int price_range = navar int rsi_range = navar int mfi_range = na//Higher low on price, lower low on rsi, then check with stochmfi_div_bullish = iff(higher_low and higher_low_m, true, false)if mfi_div_bullish    price_range := 0    rsi_range := 0//VWMA/SMA/OBV_src = s_vwma-s_smasd_src = stdev(_src,14)pooled_src = (_src/sd_src)*2sd_s_vwma = stdev(s_vwma,14)sd_s_sma = stdev(s_sma,14)longTrend = obv > ema(obv,100) and is_ranging == falsecrossOver = crossover(s_vwma , s_sma)crossingOver = (s_vwma > s_sma) and (close >= s_vwma) crossUnder = crossunder(s_vwma, s_sma)crossingUnder = (s_vwma < s_sma) and (close <= s_vwma)hist_color = f_c_gradientAdvDec(s_vwma-s_sma, (s_vwma-s_sma)/2, color.new(c_sell,90), color.new(c_buy,80))//Strategy Entriesmfi_stoch_trend = iff(enb_stoch_mfi, iff(s_stoch >= 50 and crossover(s_mfi, 50) and crossingOver and longTrend and is_ranging == false, true, false), false)var buy_counter_rsi = 0var buy_counter_mfi = 0mfi_div = iff(enb_stoch_mfi_div, iff(mfi_div_bullish and crossingOver and s_stoch >= 50 and is_ranging, true, false), false)if mfi_div    buy_counter_mfi := bar_index + 5    mfi_divergent_buy = iff(bar_index <= buy_counter_mfi and strategy.position_size == 0, true, false)//Strategy Entriesorder_fired = falsevar float previousRes = 0.0tpprice := strategy.position_avg_price * (1+tp_percentage)if time_check    if mfi_stoch_trend        strategy.entry("Buy", true, comment = "[B] STOCH/MFI")        order_fired := true    if mfi_divergent_buy        strategy.entry("Buy", true, comment = "[B] MFI Hidden Divergance")        order_fired := true            if order_fired         previousRes := _pL    if strategy.position_size > 0        strategy.exit("Buy", limit = tpprice, comment = "TP")    if close <= previousRes         strategy.exit("Buy", stop = previousRes, comment = "SL")        //Drawingshline(0, "Base", color.white)hline(100, "Max", color.white)p_stoch = plot(s_stoch, color = c_stoch)p_mfi = plot(s_mfi, color = c_mfi)hline(70, "Top Line")p_mid = plot(50, "Mid Line", color.new(color.white,100))hline(50, "Mid Line")hline(30, "Bot Line")fill(p_stoch, p_mid, color.new(c_stoch, 60))plotshape(crossOver ? 5 : crossUnder ? -5 : na, style = shape.square, color = crossOver ? c_buy : crossUnder ? c_sell : na, size = size.tiny, location = location.absolute)plot((_src/sd_src)*2, color = hist_color, style = plot.style_histogram)//Boxesvar string same = ""var box _box = naif longTrend and is_ranging == false and same != "longtrend"    same := "longtrend"    _box := box.new(bar_index, 105, bar_index, 100, bgcolor = c_longtrend,border_color = color.new(color.white, 100))else if is_ranging and same != "isranging"    same := "isranging"    _box := box.new(bar_index, 105, bar_index, 100, bgcolor = c_flat,border_color = color.new(color.white, 100))if not na(_box)    box.set_right(_box,bar_index)//Div Linesvar line _line = naif mfi_divergent_buy    _line = line.new(bL[1] -6, s_mfi[bar_index-bL[1]], bar_index + 6, s_mfi, color = color.green, width = 3)