
평균 회귀 단계적 포지션 개시 전략은 HedgerLabs가 설계한 고급 양적 거래 전략 스크립트이며, 금융 시장의 평균 회귀 기술에 초점을 맞추고 있다. 이 전략은 체계화된 방법을 선호하고 가격의 상대적인 이동 평균에 기반한 단계적 포지션 개시 방식을 강조하는 거래자를 겨냥한다.
이 전략의 핵심은 간단한 이동 평균 (SMA) 이다. 모든 입출장 거래는 이동 평균을 중심으로 이루어진다. 거래자는 MA 길이를 사용자 정의하여 다른 거래 스타일과 시간 범위에 적용 할 수 있습니다.
이 전략의 특징은 점진적인 포지션 개시 메커니즘에 있다. 가격이 이동 평균에서 이탈한 것이 일정 비율을 초과할 때 이 전략은 첫 번째 포지션을 시작한다. 그 후, 가격이 이동 평균에서 이탈하는 정도가 계속 커질수록 이 전략은 거래자가 정의하는 방식으로 점진적으로 포지션을 증가시킨다. 이 방법은 시장의 변동성이 커질 때 더 높은 수익을 얻을 수 있다.
이 전략은 또한 지위를 지능적으로 관리한다. 가격이 이동 평균보다 낮을 때 더 많이 하고, 가격이 이동 평균보다 높을 때 공백을 하고, 다양한 시장 조건에 적응한다. 평소 지점은 가격이 이동 평균을 만질 때 잠재적인 역전점을 잡기 위해 설정되어 최적의 폐쇄 지위를 달성한다.
활성화calc_on_every_tick이 전략은 시장의 상황을 지속적으로 평가하고 적절한 시기에 대응할 수 있습니다.
평균 회귀 점진적 상장 전략은 다음과 같은 장점이 있다:
이 전략에는 몇 가지 위험도 있습니다.
이러한 위험을 적절히 최적화된 출구, 더 나은 추세 판단, 또는 적절히 축소된 포지션 개척률으로 완화할 수 있다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
평균 회귀 점진적 포지션 개시 전략은 평균 회귀 거래 기술에 초점을 맞추고, 체계화된 점진적 포지션 개시 관리 포지션을 채택하고, 사용자 정의 가능한 매개 변수가 다른 거래 품종에 적용됩니다. 이 전략은 변동 시장에서 잘 작동하며, 단선 연산에 관심이있는 양적 거래자에게 적합합니다.
/*backtest
start: 2023-12-29 00:00:00
end: 2024-01-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Mean Reversion with Incremental Entry by HedgerLabs", overlay=true, calc_on_every_tick=true)
// Input for adjustable settings
maLength = input.int(30, title="MA Length", minval=1)
initialPercent = input.float(5, title="Initial Percent for First Order", minval=0.01, step=0.01)
percentStep = input.float(1, title="Percent Step for Additional Orders", minval=0.01, step=0.01)
// Calculating Moving Average
ma = ta.sma(close, maLength)
// Plotting the Moving Average
plot(ma, "Moving Average", color=color.blue)
var float lastBuyPrice = na
var float lastSellPrice = na
// Function to calculate absolute price percentage difference
pricePercentDiff(price1, price2) =>
diff = math.abs(price1 - price2) / price2 * 100
diff
// Initial Entry Condition Check Function
initialEntryCondition(price, ma, initialPercent) =>
pricePercentDiff(price, ma) >= initialPercent
// Enhanced Entry Logic for Buy and Sell
if (low < ma)
if (na(lastBuyPrice))
if (initialEntryCondition(low, ma, initialPercent))
strategy.entry("Buy", strategy.long)
lastBuyPrice := low
else
if (low < lastBuyPrice and pricePercentDiff(low, lastBuyPrice) >= percentStep)
strategy.entry("Buy", strategy.long)
lastBuyPrice := low
if (high > ma)
if (na(lastSellPrice))
if (initialEntryCondition(high, ma, initialPercent))
strategy.entry("Sell", strategy.short)
lastSellPrice := high
else
if (high > lastSellPrice and pricePercentDiff(high, lastSellPrice) >= percentStep)
strategy.entry("Sell", strategy.short)
lastSellPrice := high
// Exit Conditions - Close position if price touches the MA
if (close >= ma and strategy.position_size > 0)
strategy.close("Buy")
lastBuyPrice := na
if (close <= ma and strategy.position_size < 0)
strategy.close("Sell")
lastSellPrice := na
// Reset last order price when position is closed
if (strategy.position_size == 0)
lastBuyPrice := na
lastSellPrice := na