This strategy is a dynamic timing trading system based on volatility, combining trend following and risk management features. The core of the strategy uses a volatility channel to identify market trend changes while incorporating an ATR-based dynamic position management mechanism to achieve precise control of trading risks. This strategy is particularly suitable for operating in highly volatile market environments and can adapt holdings to market volatility.
The core logic of the strategy is based on the following key components:
This is a complete trading system combining volatility, trend following, and risk management. The strategy captures trend changes through volatility channels while employing scientific capital management methods to control risk. Although performance may be suboptimal in ranging markets, through proper parameter optimization and additional filtering mechanisms, it can operate stably in most market environments. The strategy’s core advantages lie in its adaptability and risk control capabilities, making it suitable as a foundation framework for medium to long-term strategy expansion and optimization.
/*backtest start: 2019-12-23 08:00:00 end: 2024-12-10 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("BNF FUT 5 min Volatility Strategy", overlay=true) // Inputs length = input.int(20, "Length", minval=2) src = input.source(close, "Source") factor = input.float(2.0, "Multiplier", minval=0.25, step=0.25) initial_capital = input.float(100000, "Initial Capital ($)") risk_per_trade = input.float(1.0, "Risk per Trade (%)", minval=0.1, maxval=10.0) // Volatility Stop Function volStop(src, atrlen, atrfactor) => if not na(src) var max = src var min = src var uptrend = true var float stop = na atrM = nz(ta.atr(atrlen) * atrfactor, ta.tr) max := math.max(max, src) min := math.min(min, src) stop := nz(uptrend ? math.max(stop, max - atrM) : math.min(stop, min + atrM), src) uptrend := src - stop >= 0.0 if uptrend != nz(uptrend[1], true) max := src min := src stop := uptrend ? max - atrM : min + atrM [stop, uptrend] // Calculate Volatility Stop [vStop, uptrend] = volStop(src, length, factor) // Plot Volatility Stop plot(vStop, "Volatility Stop", style=plot.style_cross, color=uptrend ? #009688 : #F44336) // Risk Management and Position Sizing atr = ta.atr(length) stop_distance = math.abs(close - vStop) // Distance to stop level position_size = (initial_capital * (risk_per_trade / 100)) / stop_distance // Position size based on risk per trade position_size := math.max(position_size, 1) // Ensure minimum size of 1 // Strategy Logic if not na(vStop) if uptrend and not uptrend[1] // Transition to uptrend strategy.close("Short") strategy.entry("Long", strategy.long, qty=position_size) if not uptrend and uptrend[1] // Transition to downtrend strategy.close("Long") strategy.entry("Short", strategy.short, qty=position_size) // Exit on Stop Hit if strategy.position_size > 0 and low < vStop // Exit long if stop hit strategy.close("Long", comment="Stop Hit") if strategy.position_size < 0 and high > vStop // Exit short if stop hit strategy.close("Short", comment="Stop Hit") if (hour == 15 and minute == 15) strategy.close_all()