
이 전략은 암호화폐 시장에 적용되는 간단한 이동 평균 (SMA) 교차 전략이다. 그것은 잠재적인 입시 및 출구 신호를 식별하기 위해 빠른, 중간, 느린 세 개의 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")