This is an adaptive trend-following strategy that combines volatility and Williams Percent Range indicators. The strategy adjusts trend determination sensitivity by calculating price range and custom counters, achieving better adaptability in different market conditions. The core mechanism involves dynamically adjusting Williams indicator parameters based on price volatility to more accurately capture market trend transition points.
The strategy begins by calculating price range and its moving average (AvgRange) within a period. By comparing real-time price changes with average volatility range, it establishes two counters (TrueCount and TrueCount2) to record significant volatility frequency. These counters are used to dynamically adjust Williams indicator calculation parameters, allowing the strategy to automatically adapt its sensitivity based on market volatility conditions. Buy or sell signals are generated when the adjusted Williams indicator values break through preset thresholds.
This innovative strategy combines volatility analysis and trend following, improving strategy stability and reliability through adaptive mechanisms. While inherent risks exist, the strategy can maintain stable performance across various market conditions through proper parameter settings and optimization implementation. The strategy framework allows for further expansion and optimization, showing good development potential.
/*backtest start: 2024-10-28 00:00:00 end: 2024-11-27 00:00:00 period: 1h basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("ASCTrend", shorttitle="ASCTrend", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100) eternalfg = input(false, title="eternal 確定") eternal = eternalfg ? 1 : 0 ASClength = input.int(title="ASC Length", minval=4, defval=10) RISK = input.int(title="RISK", minval=0, defval=3) // Custom sum function customSum(source, length) => sum = 0.0 for i = 0 to length - 1 sum := sum + source[i] sum x1 = 67 + RISK x2 = 33 - RISK Range = ta.highest(ASClength) - ta.lowest(ASClength) AvgRange = ta.sma(Range, ASClength) CountFg = math.abs(open - close) >= AvgRange * 2.0 ? 1 : 0 TrueCount = customSum(CountFg, ASClength) CountFg2 = math.abs(close[3] - close) >= AvgRange * 4.6 ? 1 : 0 TrueCount2 = customSum(CountFg2, ASClength - 3) wpr3RR = ta.wpr(3 + RISK + RISK) wpr3 = ta.wpr(3) wpr4 = ta.wpr(4) WprAbs = 100 + (TrueCount2 > 0 ? wpr4 : TrueCount > 0 ? wpr3 : wpr3RR) ASC_Trend = 0 ASC_Trend := WprAbs[eternal] < x2[eternal] ? -1 : WprAbs[eternal] > x1[eternal] ? 1 : ASC_Trend[1] if (ta.crossover(ASC_Trend, 0)) strategy.entry("Long", strategy.long) if (ta.crossunder(ASC_Trend, 0)) strategy.entry("Short", strategy.short) plotshape(ta.crossover(ASC_Trend, 0), location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, text="B", textcolor=color.white) plotshape(ta.crossunder(ASC_Trend, 0), location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, text="S", textcolor=color.white) alertcondition(ta.crossover(ASC_Trend, 0), title="ASC_Trend UP", message="ASC_Trend UP") alertcondition(ta.crossunder(ASC_Trend, 0), title="ASC_Trend Down", message="ASC_Trend Down")