OPEN-SOURCE SCRIPT
nOI + Funding + CVD • strategy

nOI + Funding + CVD Strategy
Overview
This strategy is designed for cryptocurrency trading on platforms like TradingView, focusing on perpetual futures markets. It combines three key indicators—Normalized Open Interest (nOI), Funding Rate, and Cumulative Volume Delta (CVD)—to generate buy and sell signals for long and short positions. The strategy aims to capitalize on market imbalances, such as overextended open interest, funding rate extremes, and volume deltas, which often signal potential reversals or continuations in trending markets.
The script supports pyramiding (up to 10 positions), uses percentage-based position sizing (default 10% of equity per trade), and allows customization of trade directions (longs and shorts can be enabled/disabled independently). It includes multiple signal systems for entries, various exit mechanisms (including stop-loss, take-profit, time-based exits, and conditional closes based on indicators), a Martingale add-on system for averaging positions during drawdowns, and handling of opposite signals (ignore, close, or reverse).
This strategy is not financial advice; backtest thoroughly and use at your own risk. It requires data sources for Open Interest (OI) and Funding Rates, which are fetched via TradingView's security functions (e.g., from Binance for funding premiums).
Key Indicators
1. Normalized Open Interest (nOI)
Group: Open Interest
Purpose: Measures the relative level of open interest over a lookback window to identify overbought (high OI) or oversold (low OI) conditions, which can indicate potential exhaustion in trends.
Calculation:
Fetches OI data (close) from the symbol's standard ticker (e.g., "{symbol}_OI").
Normalizes OI within a user-defined window (default: 500 bars) using min-max scaling: (OI - min_OI) / (max_OI - min_OI) * 100.
Upper threshold (default: 70%): Signals potential short opportunities when crossed from above.
Lower threshold (default: 30%): Signals potential long opportunities when crossed from below.
Visualization: Plotted as a line (teal above upper, red below lower, gray in between). Horizontal lines at upper, mid (50%), lower, and a separator at 102%.
Notes: Handles non-crypto symbols by adjusting timeframe to daily if intraday. Errors if no OI data available.
2. Funding Rate
Group: Funding Rate
Purpose: Tracks the average funding rate (premium index) to detect market sentiment extremes. Positive funding suggests bull bias (longs pay shorts), negative suggests bear bias.
Calculation:
Fetches premium index data from Binance (e.g., "binance:{base}usdt_premium").
Supports lower timeframe aggregation (default: enabled, using 1-min TF) for smoother data.
Averages open and close premiums, clamps values, and scales/shifts for plotting (base: 150, scale: 1000x).
Upper threshold (default: 1.0%): Overheat for shorts.
Lower threshold (default: 1.0%): Overcool for longs.
Ultra level (default: 1.8%): Extreme for additional short signals.
Smoothing: Uses inverse weighted moving average (IWMA) or lower-TF aggregation to reduce noise.
Visualization: Shifted plot (green positive, red negative) with filled areas. Horizontal lines for overheat, overcool, base (0%), and ultra.
Notes: Custom ticker option for non-standard symbols.
3. Cumulative Volume Delta (CVD)
Group: CVD (Cumulative Volume Delta)
Purpose: Measures net buying/selling pressure via volume delta, normalized to identify divergences or confirmations with price.
Calculation:
Delta: +volume if close > open, -volume if close < open.
Cumulative: Rolling cumsum over a window (default: 500 bars), smoothed with EMA (default: 20).
Normalized: Scaled by absolute max in window (-1 to 1 range).
Scaled/shifted for plotting (base: 300 or 0 if anchored, scale: 120x).
Upper threshold (default: 1.0%): Over for shorts.
Lower threshold (default: 1.0%): Under for longs.
Visualization: Shifted plot (aqua positive, purple negative) with filled areas. Horizontal lines for over, under, and separator (default: 252).
Filter Options (for Signal A):
Enable filter (default: false).
Require sign match (Long ≥0, Short ≤0).
Require extreme zones.
Require momentum (rising/falling over N bars, default: 3).
Signal Logics for Entries
Entries are triggered by buy/sell signals from multiple systems (A, B, C, D), filtered by direction toggles and entry conditions.
Signal System A: OI + Funding (with optional CVD filter)
Enabled: Default true.
Sell (Short): nOI > upper threshold, falling over N bars (default: 3), delta ≥ threshold (default: 3%), funding > overheat, and CVD filter OK.
Buy (Long): nOI < lower threshold, rising over N bars (default: 3), delta ≥ threshold (default: 3%), funding < overcool, and CVD filter OK.
Signal System B: Short - Funding Crossunder + Filters
Enabled: Default true.
Sell (Short): Funding crosses under overheat level, optional: CVD > over, nOI < upper.
Signal System C: Short - Ultra Funding
Enabled: Default false.
Sell (Short): Funding crosses ultra level (up or down, both default true).
Signal System D: Long - Funding Crossover + Filters
Enabled: Default true.
Buy (Long): Funding crosses over overcool level, optional: CVD < under, nOI > lower.
Combined: Sell if A/B/C active; Buy if A/D active.
Entry Filters
Cooldown: Optional pause between entries (default: false, 3 bars).
Max Entries: Limit pyramiding (default: true, 6 max).
Entries only if both filters pass and direction allowed.
Opposite Signal Handling
Mode: Ignore (default), Reverse (close and enter opposite), or Close (exit only).
Processed before regular entries.
Position Management
Martingale (3 Steps):
Enabled per step (default: all true).
Triggers add-ons at loss levels (defaults: 5%, 8%, 11%) by adding % to position (default: 100% each).
Resets on position close.
Break Even:
Enabled (default: true).
Activates at profit threshold (default: 5%), sets SL better by offset (default: 0.1%).
Exit Systems
Multiple exits checked in sequence.
Exit 1: SL/TP
Enabled: Separate for long/short (default: true).
SL: % from avg price (defaults: 1% long/short).
TP: % from avg price (defaults: 2% long/short).
Exit 2: Funding
Enabled: Separate for long (up) / short (down) (default: true).
Long Exit: Funding > upper exit threshold (default: 0.8%).
Short Exit: Funding < lower exit threshold (default: 0.8%).
Exit 3: nOI
Enabled: Separate for long (up) / short (down) (default: true).
Long Exit: nOI > upper exit (default: 85%).
Short Exit: nOI < lower exit (default: 15%).
Exit 4: Global SL
Enabled: Default true.
Exit: If position loss ≥ % (default: 7%).
Exit 5: Break Even (integrated in position block)
Exit 6: Time Limit
Enabled: Separate for long/short (default: true).
Exit: After N bars in trade (defaults: 30 each).
Timer updates on add-ons if enabled (default: true).
Visual Elements
Buy/Sell Labels: Small labels ("BUY"/"SELL") on bars with signals, limited to last 30.
All indicators plotted on a separate pane (overlay=false).
Usage Notes
Backtesting: Adjust parameters based on asset/timeframe. Test on historical data.
Data Requirements: Works best on crypto perps with OI and funding data.
Risk Management: Incorporates SL/TP and global SL; monitor drawdowns with Martingale.
Customization: All thresholds, enables, and scales are inputs for fine-tuning.
Version: Pine Script v6.
For questions or improvements, contact the author. Happy trading!
Overview
This strategy is designed for cryptocurrency trading on platforms like TradingView, focusing on perpetual futures markets. It combines three key indicators—Normalized Open Interest (nOI), Funding Rate, and Cumulative Volume Delta (CVD)—to generate buy and sell signals for long and short positions. The strategy aims to capitalize on market imbalances, such as overextended open interest, funding rate extremes, and volume deltas, which often signal potential reversals or continuations in trending markets.
The script supports pyramiding (up to 10 positions), uses percentage-based position sizing (default 10% of equity per trade), and allows customization of trade directions (longs and shorts can be enabled/disabled independently). It includes multiple signal systems for entries, various exit mechanisms (including stop-loss, take-profit, time-based exits, and conditional closes based on indicators), a Martingale add-on system for averaging positions during drawdowns, and handling of opposite signals (ignore, close, or reverse).
This strategy is not financial advice; backtest thoroughly and use at your own risk. It requires data sources for Open Interest (OI) and Funding Rates, which are fetched via TradingView's security functions (e.g., from Binance for funding premiums).
Key Indicators
1. Normalized Open Interest (nOI)
Group: Open Interest
Purpose: Measures the relative level of open interest over a lookback window to identify overbought (high OI) or oversold (low OI) conditions, which can indicate potential exhaustion in trends.
Calculation:
Fetches OI data (close) from the symbol's standard ticker (e.g., "{symbol}_OI").
Normalizes OI within a user-defined window (default: 500 bars) using min-max scaling: (OI - min_OI) / (max_OI - min_OI) * 100.
Upper threshold (default: 70%): Signals potential short opportunities when crossed from above.
Lower threshold (default: 30%): Signals potential long opportunities when crossed from below.
Visualization: Plotted as a line (teal above upper, red below lower, gray in between). Horizontal lines at upper, mid (50%), lower, and a separator at 102%.
Notes: Handles non-crypto symbols by adjusting timeframe to daily if intraday. Errors if no OI data available.
2. Funding Rate
Group: Funding Rate
Purpose: Tracks the average funding rate (premium index) to detect market sentiment extremes. Positive funding suggests bull bias (longs pay shorts), negative suggests bear bias.
Calculation:
Fetches premium index data from Binance (e.g., "binance:{base}usdt_premium").
Supports lower timeframe aggregation (default: enabled, using 1-min TF) for smoother data.
Averages open and close premiums, clamps values, and scales/shifts for plotting (base: 150, scale: 1000x).
Upper threshold (default: 1.0%): Overheat for shorts.
Lower threshold (default: 1.0%): Overcool for longs.
Ultra level (default: 1.8%): Extreme for additional short signals.
Smoothing: Uses inverse weighted moving average (IWMA) or lower-TF aggregation to reduce noise.
Visualization: Shifted plot (green positive, red negative) with filled areas. Horizontal lines for overheat, overcool, base (0%), and ultra.
Notes: Custom ticker option for non-standard symbols.
3. Cumulative Volume Delta (CVD)
Group: CVD (Cumulative Volume Delta)
Purpose: Measures net buying/selling pressure via volume delta, normalized to identify divergences or confirmations with price.
Calculation:
Delta: +volume if close > open, -volume if close < open.
Cumulative: Rolling cumsum over a window (default: 500 bars), smoothed with EMA (default: 20).
Normalized: Scaled by absolute max in window (-1 to 1 range).
Scaled/shifted for plotting (base: 300 or 0 if anchored, scale: 120x).
Upper threshold (default: 1.0%): Over for shorts.
Lower threshold (default: 1.0%): Under for longs.
Visualization: Shifted plot (aqua positive, purple negative) with filled areas. Horizontal lines for over, under, and separator (default: 252).
Filter Options (for Signal A):
Enable filter (default: false).
Require sign match (Long ≥0, Short ≤0).
Require extreme zones.
Require momentum (rising/falling over N bars, default: 3).
Signal Logics for Entries
Entries are triggered by buy/sell signals from multiple systems (A, B, C, D), filtered by direction toggles and entry conditions.
Signal System A: OI + Funding (with optional CVD filter)
Enabled: Default true.
Sell (Short): nOI > upper threshold, falling over N bars (default: 3), delta ≥ threshold (default: 3%), funding > overheat, and CVD filter OK.
Buy (Long): nOI < lower threshold, rising over N bars (default: 3), delta ≥ threshold (default: 3%), funding < overcool, and CVD filter OK.
Signal System B: Short - Funding Crossunder + Filters
Enabled: Default true.
Sell (Short): Funding crosses under overheat level, optional: CVD > over, nOI < upper.
Signal System C: Short - Ultra Funding
Enabled: Default false.
Sell (Short): Funding crosses ultra level (up or down, both default true).
Signal System D: Long - Funding Crossover + Filters
Enabled: Default true.
Buy (Long): Funding crosses over overcool level, optional: CVD < under, nOI > lower.
Combined: Sell if A/B/C active; Buy if A/D active.
Entry Filters
Cooldown: Optional pause between entries (default: false, 3 bars).
Max Entries: Limit pyramiding (default: true, 6 max).
Entries only if both filters pass and direction allowed.
Opposite Signal Handling
Mode: Ignore (default), Reverse (close and enter opposite), or Close (exit only).
Processed before regular entries.
Position Management
Martingale (3 Steps):
Enabled per step (default: all true).
Triggers add-ons at loss levels (defaults: 5%, 8%, 11%) by adding % to position (default: 100% each).
Resets on position close.
Break Even:
Enabled (default: true).
Activates at profit threshold (default: 5%), sets SL better by offset (default: 0.1%).
Exit Systems
Multiple exits checked in sequence.
Exit 1: SL/TP
Enabled: Separate for long/short (default: true).
SL: % from avg price (defaults: 1% long/short).
TP: % from avg price (defaults: 2% long/short).
Exit 2: Funding
Enabled: Separate for long (up) / short (down) (default: true).
Long Exit: Funding > upper exit threshold (default: 0.8%).
Short Exit: Funding < lower exit threshold (default: 0.8%).
Exit 3: nOI
Enabled: Separate for long (up) / short (down) (default: true).
Long Exit: nOI > upper exit (default: 85%).
Short Exit: nOI < lower exit (default: 15%).
Exit 4: Global SL
Enabled: Default true.
Exit: If position loss ≥ % (default: 7%).
Exit 5: Break Even (integrated in position block)
Exit 6: Time Limit
Enabled: Separate for long/short (default: true).
Exit: After N bars in trade (defaults: 30 each).
Timer updates on add-ons if enabled (default: true).
Visual Elements
Buy/Sell Labels: Small labels ("BUY"/"SELL") on bars with signals, limited to last 30.
All indicators plotted on a separate pane (overlay=false).
Usage Notes
Backtesting: Adjust parameters based on asset/timeframe. Test on historical data.
Data Requirements: Works best on crypto perps with OI and funding data.
Risk Management: Incorporates SL/TP and global SL; monitor drawdowns with Martingale.
Customization: All thresholds, enables, and scales are inputs for fine-tuning.
Version: Pine Script v6.
For questions or improvements, contact the author. Happy trading!
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.