
이 전략은 부린 띠의 돌파구를 사용하여 거래 신호를 탐지하여 MCL와 YG의 두 가지 긍정적으로 관련된 자산에 대한 쌍거래를 구현합니다. MCL 가격이 부린 띠를 터치 할 때, MCL를 더하고 YG를 더합니다.
우선, 이 전략은 특정 주기 동안의 종식 가격에 기초하여 SMA 평균선과 표준 차 StdDev를 계산한다. 그리고 SMA 평균선 위에 아래로 각각 1개의 오차량을 추가하여, 브린 밴드의 상반도와 하반도를 형성한다. 가격이 상반도를 접촉할 때 구매 신호를 생성하고, 하반도를 접촉할 때 판매 신호를 생성한다.
이 전략은 부린띠의 돌파구 거래 사고방식을 채택합니다. 즉, 가격이 돌파구에 올라갈 때 더 많이 보고, 돌파구에 내려갈 때 아무것도 보지 않습니다. 부린띠는 채널 폭을 동적으로 조정하여 시장 변화에 적응하여 시장의 흔들림의 잡음을 효과적으로 필터링 할 수 있습니다. 고정된 채널과 달리 부린띠의 채널 폭은 시장의 변동성 변화에 따라 확장 또는 축소됩니다.
두 가지 긍정적으로 관련된 자산인 MCL와 YG에 대해 쌍거래한다. MCL이 경로를 돌파할 때 MCL 가격이 상승 추세에 있다는 것을 나타냅니다. 이 때 더 많은 MCL을 하고, 동시에 YG를 니다. 즉, 더 강한 자산을 구입하고, 더 약한 자산을 판매하여 두 자산 가격 차이에서 이익을 얻습니다.
매개 변수를 최적화하고, 더 연관성이 강하고, 유동성이 좋은 거래 대상을 선택하고, 합리적인 스톱 포지션을 설정하는 등의 방법으로 위험을 줄일 수 있다.
이 전략은 전체적으로 단순하고 직접적인 것으로 보이며, 브린띠를 통해 트렌드를 캡처하고, 거래의 알파 수익을 얻습니다. 그러나 몇 가지 변수 최적화, 중지 손실 및 쌍의 선택과 같은 최적화 가능한 공간이 있습니다. 다른 변수, 거래 대상을 테스트하고, 트렌드 필터링과 같은 방법을 적절하게 도입함으로써 더 나은 전략 효과를 얻을 수 있습니다.
/*backtest
start: 2022-11-07 00:00:00
end: 2023-11-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shark792
//@version=5
// 1. Define strategy settings
strategy(title="MCL-YG Pair Trading Strategy", overlay=true,
pyramiding=0, initial_capital=10000,
commission_type=strategy.commission.cash_per_order,
commission_value=4, slippage=2)
smaLength = input.int(title="SMA Length", defval=20)
stdLength = input.int(title="StdDev Length", defval=20)
ubOffset = input.float(title="Upper Band Offset", defval=1, step=0.5)
lbOffset = input.float(title="Lower Band Offset", defval=1, step=0.5)
usePosSize = input.bool(title="Use Position Sizing?", defval=true)
riskPerc = input.float(title="Risk %", defval=0.5, step=0.25)
// 2. Calculate strategy values
smaValue = ta.sma(close, smaLength)
stdDev = ta.stdev(close, stdLength)
upperBand = smaValue + (stdDev * ubOffset)
lowerBand = smaValue - (stdDev * lbOffset)
riskEquity = (riskPerc / 100) * strategy.equity
atrCurrency = (ta.atr(20) * syminfo.pointvalue)
posSize = usePosSize ? math.floor(riskEquity / atrCurrency) : 1
// 3. Output strategy data
plot(series=smaValue, title="SMA", color=color.teal)
plot(series=upperBand, title="UB", color=color.green,
linewidth=2)
plot(series=lowerBand, title="LB", color=color.red,
linewidth=2)
// 4. Determine long trading conditions
enterLong = ta.crossover(close, upperBand)
exitLong = ta.crossunder(close, smaValue)
// 5. Code short trading conditions
enterShort = ta.crossunder(close, lowerBand)
exitShort = ta.crossover(close, smaValue)
// 6. Submit entry orders
if enterLong
strategy.entry(id="EL", direction=strategy.long, qty=posSize)
if enterShort
strategy.entry(id="ES", direction=strategy.short, qty=posSize)
// 7. Submit exit orders
strategy.close(id="EL", when=exitLong)
strategy.close(id="ES", when=exitShort)