MM Flow
FlowScripts

Perfected FlowScript

OI Z-Score Per Exchange

OI Z-Score Per Exchange is indexed as 354_oi_z_score_per_exchange.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.

This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.

Dialect

flowscript-v2

Compatibility

flowscript-v2-needs-transpile

Position

offchart

Axis

true

Size

3.3 KB

Lines

75

Native Signal Candidates

10 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.

0/10 guarded

Binance Z overbought sell

line 52:1

Trigger

bZ > zLevel && bZ[1] <= zLevel

Value

bZ

Deps

bZ:timeseries, zLevel:input

Binance Z oversold buy

line 52:1

Trigger

bZ < (0 - zLevel) && bZ[1] >= (0 - zLevel)

Value

bZ

Deps

bZ:timeseries, zLevel:input

Bybit Z overbought sell

line 53:1

Trigger

yZ > zLevel && yZ[1] <= zLevel

Value

yZ

Deps

yZ:timeseries, zLevel:input

Bybit Z oversold buy

line 53:1

Trigger

yZ < (0 - zLevel) && yZ[1] >= (0 - zLevel)

Value

yZ

Deps

yZ:timeseries, zLevel:input

OKX Z overbought sell

line 54:1

Trigger

oZ > zLevel && oZ[1] <= zLevel

Value

oZ

Deps

oZ:timeseries, zLevel:input

OKX Z oversold buy

line 54:1

Trigger

oZ < (0 - zLevel) && oZ[1] >= (0 - zLevel)

Value

oZ

Deps

oZ:timeseries, zLevel:input

Deribit Z overbought sell

line 55:1

Trigger

dZ > zLevel && dZ[1] <= zLevel

Value

dZ

Deps

dZ:timeseries, zLevel:input

Deribit Z oversold buy

line 55:1

Trigger

dZ < (0 - zLevel) && dZ[1] >= (0 - zLevel)

Value

dZ

Deps

dZ:timeseries, zLevel:input

HL Z overbought sell

line 56:1

Trigger

hZ > zLevel && hZ[1] <= zLevel

Value

hZ

Deps

hZ:timeseries, zLevel:input

HL Z oversold buy

line 56:1

Trigger

hZ < (0 - zLevel) && hZ[1] >= (0 - zLevel)

Value

hZ

Deps

hZ:timeseries, zLevel:input

354_oi_z_score_per_exchange.flowscript

source path: kscripts/perfected/354_oi_z_score_per_exchange.flowscript · sha256:79f0fdd5743b7ea7c1ebb8eab35162b7991f3c34c70485c267e67838326a4724

hash verified
//@version=2
// Source: kiyotaka.ai/hub/kscript (original)
// Original title: OI Z-Score Per Exchange

define(title="OI Z-Score Per Exchange", position="offchart", axis=true)

var lookback = input(name="lookback", type="number", defaultValue=30, label="Z-Score Lookback")
var zLevel   = input(name="zLevel",   type="number", defaultValue=2.0, label="Guide Level (±)")

// ===== OI SOURCES =====
timeseries oiBinance = open_interest(symbol="BTCUSDT",       exchange="BINANCE_FUTURES")
timeseries oiBybit   = open_interest(symbol="BTCUSDT",       exchange="BYBIT")
timeseries oiOkex    = open_interest(symbol="BTC-USDT",      exchange="OKEX")
timeseries oiDeribit = open_interest(symbol="BTC-PERPETUAL", exchange="DERIBIT")
timeseries oiHL      = open_interest(symbol="BTC",           exchange="HYPERLIQUID_FUTURES")

// ===== ISNAN GUARD =====
if (isnan(oiBinance.close[0])) {
    return
}

// ===== STATIC STATE TRACKING =====
static barCount = 0
static lastBarIndex = 0
if (!isnan(bar_index[0]) && bar_index[0] != lastBarIndex) {
    lastBarIndex = bar_index[0]
    barCount = barCount + 1
}

// ===== Z-SCORE PER EXCHANGE =====
timeseries bMean = sma(source=oiBinance.close,  period=lookback)
timeseries bStd  = stddev(source=oiBinance.close, period=lookback)
timeseries bZ    = (oiBinance.close - bMean) / bStd

timeseries yMean = sma(source=oiBybit.close,    period=lookback)
timeseries yStd  = stddev(source=oiBybit.close,  period=lookback)
timeseries yZ    = (oiBybit.close - yMean) / yStd

timeseries oMean = sma(source=oiOkex.close,     period=lookback)
timeseries oStd  = stddev(source=oiOkex.close,   period=lookback)
timeseries oZ    = (oiOkex.close - oMean) / oStd

timeseries dMean = sma(source=oiDeribit.close,  period=lookback)
timeseries dStd  = stddev(source=oiDeribit.close, period=lookback)
timeseries dZ    = (oiDeribit.close - dMean) / dStd

timeseries hMean = sma(source=oiHL.close,       period=lookback)
timeseries hStd  = stddev(source=oiHL.close,     period=lookback)
timeseries hZ    = (oiHL.close - hMean) / hStd

// ===== PLOTS =====
plotLine(value=bZ, colors=["#ff5252"], width=1, label=["Binance Z"], desc=["Binance OI Z-Score"])
plotLine(value=yZ, colors=["#00e676"], width=1, label=["Bybit Z"],   desc=["Bybit OI Z-Score"])
plotLine(value=oZ, colors=["#448aff"], width=1, label=["OKX Z"],     desc=["OKX OI Z-Score"])
plotLine(value=dZ, colors=["#ffeb3b"], width=1, label=["Deribit Z"], desc=["Deribit OI Z-Score"])
plotLine(value=hZ, colors=["#e040fb"], width=1, label=["HL Z"],      desc=["Hyperliquid OI Z-Score"])

hline(value=2,  color="#ffffff40", width=1)
hline(value=-2, color="#ffffff40", width=1)
hline(value=0,  color="#ffffff20", width=1)

// ===== SUMMARY TABLE =====
if (isLastBar) {
    var table = plotTable(position="bottom_right", rows=4, cols=2)
    table.cell(0, 0, "Bars Processed", textColor="#ffffff", bgColor="#1a1a2e")
    table.cell(1, 0, toString(barCount), textColor="#ffffff", bgColor="#1a1a2e")

    var maxZ = max(max(max(max(bZ, yZ), oZ), dZ), hZ)
    var minZ = min(min(min(min(bZ, yZ), oZ), dZ), hZ)

    table.cell(0, 1, "Max Z", textColor="#ffffff", bgColor="#1a1a2e")
    table.cell(1, 1, toString(maxZ), textColor="#ff5252", bgColor="#1a1a2e")
    table.cell(0, 2, "Min Z", textColor="#ffffff", bgColor="#1a1a2e")
    table.cell(1, 2, toString(minZ), textColor="#00e676", bgColor="#1a1a2e")
}