该策略利用随机振荡指标(Stochastic Oscillator)来识别市场的超买和超卖状态,在预定义的风险和回报参数下触发交易,以期在波动的交易区间内获利。该策略的主要思路是在交易区间的低点买入,在交易区间的高点卖出,同时严格控制风险。
基于随机振荡指标的波动区间交易策略试图在预先确定的交易区间内,利用随机指标的超买和超卖信号来触发交易。该策略通过严格的风险管理和交易间隔来控制风险。尽管该策略有一定的优势,但其成功很大程度上取决于正确识别交易区间。未来的优化方向包括结合其他技术指标、引入动态止损止盈、使用更先进的区间识别技术以及添加趋势过滤器。在实际应用中,务必根据个人偏好和风险承受能力来调整策略参数和风险管理规则。
/*backtest start: 2023-06-11 00:00:00 end: 2024-06-16 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Range Trading with Stochastic", overlay=true) // Input Parameters overboughtLevel = input.int(80, title="Overbought Level", minval=1, maxval=100) oversoldLevel = input.int(20, title="Oversold Level", minval=1, maxval=100) stochLength = input.int(14, title="Stochastic Length", minval=1) riskPerTrade = input.float(0.01, title="Risk per Trade (%)", minval=0.01, maxval=100, step=0.01) barsBetweenTrades = input.int(20, title="Bars Between Trades", minval=1) // Calculate Stochastic Oscillator k = ta.sma(ta.stoch(close, high, low, stochLength), 3) d = ta.sma(k, 3) // Variables to Track Time Since Last Trade var lastTradeBar = 0 barsSinceLastTrade = bar_index - lastTradeBar // Risk Management atr = ta.atr(14) stopLoss = 2 * atr takeProfit = 2 * atr riskAmount = strategy.equity * riskPerTrade / 100 positionSize = 1 // Entry Conditions longCondition = k < oversoldLevel and strategy.position_size == 0 and barsSinceLastTrade >= barsBetweenTrades shortCondition = k > overboughtLevel and strategy.position_size == 0 and barsSinceLastTrade >= barsBetweenTrades // Entry/Exit Orders if longCondition strategy.entry("Long", strategy.long, qty=positionSize) strategy.exit("Long Exit", "Long", stop=close - stopLoss, limit=close + takeProfit) lastTradeBar := bar_index // Update last trade bar if shortCondition strategy.entry("Short", strategy.short, qty=positionSize) strategy.exit("Short Exit", "Short", stop=close + stopLoss, limit=close - takeProfit) lastTradeBar := bar_index // Update last trade bar // Plot Stochastic plot(k, color=color.blue, title="%K") plot(d, color=color.orange, title="%D") hline(overboughtLevel, color=color.red, title="Overbought") hline(oversoldLevel, color=color.green, title="Oversold")