Strategy · Pine Script v5 · On the chart

Thermodynamic Volume-Price Resonance (TVPR)

by caizongxun

A long and short strategy built on a custom momentum index that combines price velocity, log volume and a standardised Bollinger Band width.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code116
Settings5inputs
LicenceMIT
Last update8 months ago21 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

116 lines of Pine Script v5 from pine scripts/TVPR_Strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

TVPR_Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © caizongxun

//@version=5
strategy("Thermodynamic Volume-Price Resonance (TVPR)", overlay=true, initial_capital=10, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// --- Parameters ---
int velocity_period = input.int(5, title="Velocity Period (N)", minval=1)
int bbw_period = input.int(20, title="BBW Period (M)", minval=1)
float epsilon = input.float(0.0001, title="Epsilon")
string htf = input.timeframe("15", title="Higher Timeframe for VWAP")
int energy_exit_bars = input.int(5, title="Energy Exhaustion Bars")

// --- 1. Price Velocity (vp) ---
float vp = (close - close[velocity_period]) / velocity_period

// --- 2. Volume-Price Momentum (KE) ---
// Logarithmic smoothing of volume, avoiding 0 or negative volume issues
float vol = volume > 0 ? volume : 1
float ke = math.log(vol) * math.pow(math.abs(vp), 2) * math.sign(vp)

// --- 3. System Entropy / Volatility (SE) ---
// Using standardized Bollinger Band Width
float basis = ta.sma(close, bbw_period)
float dev = 2 * ta.stdev(close, bbw_period)
float upper = basis + dev
float lower = basis - dev
float bbw = basis != 0 ? (upper - lower) / basis : 0

float bbw_mean = ta.sma(bbw, bbw_period)
float bbw_std = ta.stdev(bbw, bbw_period)
float se = bbw_std != 0 ? (bbw - bbw_mean) / bbw_std : 0

// --- 4. Thermodynamic Momentum Index (TMI) ---
float tmi = ke / (se + epsilon)

// --- Entry Conditions Logic ---

// Condition A: Energy Compression (SE < -1 in last 10 periods)
bool cond_a = ta.lowest(se, 10) < -1

// Condition B: Momentum Explosion
float tmi_mean = ta.sma(tmi, 20)
float tmi_std = ta.stdev(tmi, 20)
float tmi_upper = tmi_mean + 2 * tmi_std
float tmi_lower = tmi_mean - 2 * tmi_std

bool cond_b_long = ta.crossover(tmi, tmi_upper)
bool cond_b_short = ta.crossunder(tmi, tmi_lower)

// Condition C: Trend Filter (HTF VWAP)
float htf_vwap = request.security(syminfo.tickerid, htf, ta.vwap)
bool cond_c_long = close > htf_vwap
bool cond_c_short = close < htf_vwap

// Combine Conditions
bool enter_long = cond_a and cond_b_long and cond_c_long
bool enter_short = cond_a and cond_b_short and cond_c_short

// --- Execution & Risk Management Variables ---
var float entry_price = na
var float sl = na
var float initial_risk = na
var float entry_tmi = na
var int entry_bar = na

// State tracker to handle single entry operations
bool in_long = strategy.position_size > 0
bool in_short = strategy.position_size < 0

// --- Trade Entry Logic ---
if enter_long and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    entry_price := close
    sl := low
    initial_risk := close - low
    entry_tmi := math.abs(tmi)
    entry_bar := bar_index

if enter_short and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    entry_price := close
    sl := high
    initial_risk := high - close
    entry_tmi := math.abs(tmi)
    entry_bar := bar_index

// --- Exit & Management Logic ---
if in_long
    // 1. Dynamic Trailing Stop (Move to breakeven if profit > 1.5 * risk)
    if high > entry_price + 1.5 * initial_risk
        sl := math.max(sl, entry_price)
    
    // Check traditional stop loss
    strategy.exit("Exit Long", "Long", stop=sl)
    
    // 2. Time/Energy Exit
    if (bar_index - entry_bar) >= energy_exit_bars and math.abs(tmi) < 0.3 * entry_tmi
        strategy.close("Long", comment="Energy Exhaustion")

if in_short
    // 1. Dynamic Trailing Stop (Move to breakeven if profit > 1.5 * risk)
    if low < entry_price - 1.5 * initial_risk
        sl := math.min(sl, entry_price)
    
    // Check traditional stop loss
    strategy.exit("Exit Short", "Short", stop=sl)
    
    // 2. Time/Energy Exit
    if (bar_index - entry_bar) >= energy_exit_bars and math.abs(tmi) < 0.3 * entry_tmi
        strategy.close("Short", comment="Energy Exhaustion")

// --- Chart Visuals ---
plot(htf_vwap, color=color.new(color.blue, 0), title="HTF VWAP", linewidth=2)
plotshape(enter_long, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Long Signal")
plotshape(enter_short, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Short Signal")

Overview

A trade needs a recent squeeze in band width, the index breaking beyond its own two-deviation band, and price on the correct side of a higher timeframe VWAP. The stop sits at the entry bar extreme and moves to breakeven after a gain of a set multiple of initial risk. A time-based exit closes fading trades. Default sizing is the full equity.

Details

Published by

caizongxun on GitHub

Draws

On the price chart

Markets

Crypto

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Velocity Period (N)int5velocity_period
BBW Period (M)int20bbw_period
Epsilonfloat0.0001epsilon
Higher Timeframe for VWAPtimeframe15htf
Energy Exhaustion Barsint5energy_exit_bars
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

106 stars

Calculates a momentum squeeze using Bollinger Bands and Keltner Channels alongside a trend-filtering moving average. It generates long and short entries based on squeeze momentum bar conditions and an optional pre-squeeze dot count filter. Exits can trigger on

Strategy v5 Oscillators & momentumVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of Athena Momentum Squeeze - Autoview

Bollinger bands examples

by tradingstrategy-ai
53 stars

This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open

Strategy v5 Volatility & bandsOscillators & momentum
Updated 3 years ago · None stated GitHub repository of Bollinger bands examples

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter
16 stars

This strategy trades Donchian channel breakouts on the price chart and exits on a shorter Donchian channel. It sizes each unit from a percentage of equity and an ATR-based initial stop, then adds units as price moves a set ATR distance, up to a maximum unit co

Strategy v6 TrendBreakout
Updated 12 months ago · None stated GitHub repository of Seykota Alt 16: Anti-Chop Filters

Breakout AVAAI (TV mirror)

by tarasprystavskyj
5 stars

Breakout AVAAI is a crypto breakout strategy mirrored from a Python trading platform. It filters potential trades by evaluating ATR relative to close price and measuring momentum over 6-hour and 12-hour lookbacks. Positions are taken when volatility meets user

Strategy v5 BreakoutOscillators & momentum Repaints
Updated 3 months ago · None stated GitHub repository of Breakout AVAAI (TV mirror)

More Breakout scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers