
この戦略は,異なる周期の移動平均を計算し,ストップとストップポイントを設定し,自動取引を実現する. 短期移動平均の上を長周期移動平均を横切るときは多行し,短期移動平均の下を長周期移動平均を横切るときは空きをする. 同時に,リスクを管理するために,ストップとストップポイントを設定する.
この戦略は均線交差の原理に基づいている。それは9日間の簡易移動平均と55日間の簡易移動平均を同時に計算する。9日間の平均線上を55日間の平均線を越えると,短期トレンドが反転して上昇する,このとき多めにする;9日間の平均線下を55日間の平均線を越えると,短期トレンドが反転して低下する,このとき空っぽにする。
同時に,この戦略はATR指数を使用してストップとストップポイントを設定する.ATR指数は,市場の変動幅を測定できる.ストップポイントは,市場変動に応じて合理的なストップを設定するために,ATRを減算したクローズアップ価格に設定する.ストップポイントは,リスク・リターン比率を利用して設定する.ここでは,リスク・リターン比率は2,つまり,ストップポイント =クローズアップ価格 + 2 *ATR値に設定する.
これは非常にシンプルで実用的なショートライン取引戦略で,以下の利点があります.
この戦略にはいくつかのリスクがあります.
これらのリスクは,最適化パラメータ,厳格な止損,合理的な位置管理によって軽減できます.
この戦略はさらに改善できる:
この戦略は,全体的な考え方が明確で,実行が容易で,特に初心者向けに適しています. 基本的なショートライン取引戦略として,操作が簡単で,最適化が容易であるなどの利点があります.COMPLETEまたは他のフレームワークを使用すると,この戦略をさらに強化して,十分な実用的な量化取引システムにすることができます.
/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA Crossover Strategy with Stop-Loss and Take-Profit", overlay=true)
// Input for selecting the length of the moving averages
maShortLength = input(9, title="Short MA Length")
maLongLength = input(55, title="Long MA Length")
// Input for setting the risk-reward ratio
riskRewardRatio = input(2, title="Risk-Reward Ratio")
// Calculate moving averages
maShort = ta.sma(close, maShortLength)
maLong = ta.sma(close, maLongLength)
// Buy condition: 9-period MA crosses above 55-period MA
buyCondition = ta.crossover(maShort, maLong)
// Sell condition: 9-period MA crosses below 55-period MA
sellCondition = ta.crossunder(maShort, maLong)
// Set stop-loss and take-profit levels
atrValue = ta.atr(14)
stopLossLevel = close - atrValue // Use ATR for stop-loss (adjust as needed)
takeProfitLevel = close + riskRewardRatio * atrValue // Risk-reward ratio of 1:2
// Execute buy and sell orders with stop-loss and take-profit
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.exit("Sell", from_entry="Buy", loss=stopLossLevel, profit=takeProfitLevel)
// Plot moving averages on the chart
plot(maShort, color=color.blue, title="Short MA")
plot(maLong, color=color.red, title="Long MA")