
この戦略は,暗号通貨市場に適用される単純な移動平均 (SMA) 交差戦略である.これは,潜在的な入場と出場のシグナルを識別するために,快速,中速,および遅速の3つのSMAを使用する.快速SMAが中速SMAを突破すると,買入シグナルを生成し,快速SMAが中速SMAを突破すると,売り出します.
策略は,トレーダーに以下の重要なパラメータを設定することを許可します.
ユーザが設定したSMAの長さに応じて,それぞれ高速SMA,中速SMA,および遅速SMAが計算されます.
急速SMA上から中速SMAを通過すると,買い信号が生じ,急速SMA下から中速SMAを通過すると,売り信号が生じます.
戦略は,口座の資金と取引ごとに負うリスクの比率を組み合わせて,取引ごとに名目資本を計算する.その後,ATRを組み合わせて,停止損失幅を計算し,最終的に取引ごとに特定のポジションを決定する.
適切なSMA周期の短縮,その他の指標の補助などによって最適化することができます.
この戦略は,SMAのクロス判断,リスク管理およびポジション最適化の複数の機能を統合し,暗号市場に適したトレンド追跡戦略です.トレーダーは,自身の取引スタイル,市場環境などの要因に応じてパラメータを調整し,最適化を実施することができます.
/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Onchain Edge Trend SMA Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Configuration Parameters
priceSource = input(close, title="Price Source")
includeIncompleteBars = input(true, title="Consider Incomplete Bars")
maForecastMethod = input(defval="flat", options=["flat", "linreg"], title="Moving Average Prediction Method")
linearRegressionLength = input(3, title="Linear Regression Length")
fastMALength = input(7, title="Fast Moving Average Length")
mediumMALength = input(30, title="Medium Moving Average Length")
slowMALength = input(50, title="Slow Moving Average Length")
tradingCapital = input(100000, title="Trading Capital")
tradeRisk = input(1, title="Trade Risk (%)")
// Calculation of Moving Averages
calculateMA(source, period) => sma(source, period)
predictMA(source, forecastLength, regressionLength) =>
maForecastMethod == "flat" ? source : linreg(source, regressionLength, forecastLength)
offset = includeIncompleteBars ? 0 : 1
actualSource = priceSource[offset]
fastMA = calculateMA(actualSource, fastMALength)
mediumMA = calculateMA(actualSource, mediumMALength)
slowMA = calculateMA(actualSource, slowMALength)
// Trading Logic
enterLong = crossover(fastMA, mediumMA)
exitLong = crossunder(fastMA, mediumMA)
// Risk and Position Sizing
riskCapital = tradingCapital * tradeRisk / 100
lossThreshold = atr(14) * 2
tradeSize = riskCapital / lossThreshold
if (enterLong)
strategy.entry("Enter Long", strategy.long, qty=tradeSize)
if (exitLong)
strategy.close("Enter Long")
// Display Moving Averages
plot(fastMA, color=color.blue, linewidth=2, title="Fast Moving Average")
plot(mediumMA, color=color.purple, linewidth=2, title="Medium Moving Average")
plot(slowMA, color=color.red, linewidth=2, title="Slow Moving Average")