
この戦略は,移動平均と取引量の2つの重要な技術指標を組み合わせて,長ポジションと短いポジションの入場と退出ルールを設計し,完全な量化取引戦略を形成する.
長期投資への入場条件:
ショートポジット入場条件:
平均は移動する速さで,移動する速さで,移動する速さで,移動する速さで
ラングランは,長期投資入場条件を満たす場合
ショートポジションの入場:ショートポジションの入場条件を満たす時に空白
ストップとストップダスト: オーバーストップとストップ・ローズを表示
改善方法:
この戦略は,移動平均指標と取引量指標を統合し,二重確認メカニズムで完全な量化取引戦略を設計した. 入場条件が明確で,止まり損があり,操作が簡単である. 同時に,二重均等戦略の頻繁な取引問題を防止し,取引量データの品質に注意し,パラメータの過度に最適化を防止する.NEXTステップは,多指標最適化,動的止まり損,および多時間枠分析を行う.
/*backtest
start: 2023-01-25 00:00:00
end: 2024-01-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA and Volume Strategy", overlay=true)
// Input parameters
fastLength = input(9, title="Fast MA Length")
slowLength = input(21, title="Slow MA Length")
volumePercentageThreshold = input(50, title="Volume Percentage Threshold")
// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Calculate 24-hour volume and weekly volume average
dailyVolume = request.security(syminfo.tickerid, "D", volume)
weeklyVolumeAvg = ta.sma(request.security(syminfo.tickerid, "W", volume), 7)
// Strategy conditions
longCondition = ta.crossover(fastMA, slowMA) and dailyVolume < (weeklyVolumeAvg * volumePercentageThreshold / 100)
shortCondition = ta.crossunder(fastMA, slowMA)
// Set take profit and stop loss levels
takeProfitLong = close * 1.50
stopLossLong = close * 0.90
// Strategy orders
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// Plot moving averages
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA")
// Plot 24-hour volume and weekly volume average
plot(dailyVolume, color=color.purple, title="24-Hour Volume", transp=0)
plot(weeklyVolumeAvg, color=color.orange, title="Weekly Volume Average")
// Plot entry signals
plotshape(series=longCondition, title="Buy Signal", color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=shortCondition, title="Sell Signal", color=color.red, style=shape.triangledown, size=size.small)
// Plot take profit and stop loss levels only when a valid trade is active
plotshape(series=longCondition, title="Take Profit Long", color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=longCondition, title="Stop Loss Long", color=color.red, style=shape.triangledown, size=size.small)