
双移動均線金叉死叉反転戦略は,典型的なトレンドを追跡する量化取引戦略である.この戦略は,双移動均線指標の9日線と14日線を用い,買入と売却のシグナルを構築する. 9日線が下から14日線を突破して金叉を形成するときに買入し,9日線が上から14日線を突破して死叉を形成するときに売る.偽のシグナルをフィルターするために,戦略は50日線指標にも導入され,価格が突破するかどうかを判断する.
この戦略は主に2つの移動平均線指標の金叉と死叉の信号に基づいて取引する. 2つの移動平均線のうち,9日線は短期トレンドを代表し,14日線は中期トレンドを代表し,それらの交差は市場トレンドの転換を判断する有効な技術指標である. 短期トレンドラインが下部から中期トレンドラインを突破して金叉を形成すると,短期トレンドラインが強くなると,買入シグナルに属し,上部から突破して死叉を形成すると,短期トレンドラインが弱くなると,売出シグナルに属する.
さらに,戦略は50日線を導入し,誤導信号をフィルターする.50日線が50日線より高い時のみ,買いが生じ,50日線より低い時のみ,売りが生じます.50日線は中長期のトレンドを代表し,中長期のトレンドが同意する時のみ,短期操作を行います.
コードの中核の論理は次のとおりです.
// 买入条件:9日线上穿14日线 且 当前价格高于50日线
buyCondition = ta.crossover(sma9, sma14) and close > sma50
// 卖出条件:9日线下穿14日线 且 当前价格低于50日线
sellCondition = ta.crossunder(sma9, sma14) and close < sma50
移動均線戦略の利点は明らかです.
双動均線戦略にはリスクもあります.
リスクの最適化には,以下の方法があります.
双移動均線戦略は以下の点で最適化できます.
双移動均線戦略は,全体的に見ると,効率的に利益をもたらす戦略である.それは順番に,継続的に利益をもたらすことができる;同時に,一定のリスクがあり,さらなる改善が必要である.パラメータ最適化,止損方法,および戦略の組み合わせによって,この戦略の効果をさらに強化することができる.
/*backtest
start: 2022-11-24 00:00:00
end: 2023-11-30 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("smaCrossReverse", shorttitle="smaCrossReverse", overlay=true)
// Define the length for the SMAs
sma9Length = input(9, title="SMA 9 Length")
sma14Length = input(14, title="SMA 14 Length")
sma50Length = input(50, title="SMA 50 Length") // Add input for SMA 50
// Calculate SMAs
sma9 = ta.sma(close, sma9Length)
sma14 = ta.sma(close, sma14Length)
sma50 = ta.sma(close, sma50Length) // Calculate SMA 50
// Buy condition: SMA 9 crosses above SMA 14 and current price is above SMA 50
buyCondition = ta.crossover(sma9, sma14) and close > sma50
// Sell condition: SMA 9 crosses below SMA 14 and current price is below SMA 50
sellCondition = ta.crossunder(sma9, sma14) and close < sma50
// Track the time since position was opened
var float timeElapsed = na
if (buyCondition)
timeElapsed := 0
else
timeElapsed := na(timeElapsed[1]) ? timeElapsed[1] : timeElapsed[1] + 1
// Close the buy position after 5 minutes
if (timeElapsed >= 5)
strategy.close("Buy")
// Track the time since position was opened
var float timeElapsedSell = na
if (sellCondition)
timeElapsedSell := 0
else
timeElapsedSell := na(timeElapsedSell[1]) ? timeElapsedSell[1] : timeElapsedSell[1] + 1
// Close the sell position after 5 minutes
if (timeElapsedSell >= 5)
strategy.close("Sell")
// Plot the SMAs on the chart
plot(sma9, title="SMA 9", color=color.blue)
plot(sma14, title="SMA 14", color=color.red)
plot(sma50, title="SMA 50", color=color.green) // Plot SMA 50 on the chart
// Strategy entry and exit conditions using if statements
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.entry("Sell", strategy.short)