
이 전략은 2개의 다른 주기들의 지수 이동 평균 ((EMA) 을 계산하여 시장의 경향 방향을 판단하고, 경향 방향이 결정된 것을 전제로, 부린에 대한 자조와 결합하여 과매매 기회를 발견하고, 트렌드 추적 거래를 실현한다.
200주기 및 30주기 EMA를 계산하고, 200EMA가 30EMA보다 크면 긴 선의 상승으로 판단하고, 그렇지 않으면 긴 선의 하향으로 판단한다.
트렌드 방향을 결정한 후, 브린 밴드의 기본선, 상단선 및 하단선을 계산한다. 기본선은 구성 가능한 주기 (예: 8주기) 를 사용하는 SMA를 계산하고, 폭은 동일한 주기 (예: 1.3과 1.1) 의 최고 가격과 최저 가격의 극한의 구성 가능한 배수를 사용합니다.
긴 선 위쪽에서는 가격이 아래쪽에서 위쪽으로 하차할 때 구매점으로 판단하고, 긴 선 아래쪽에서는 가격이 위쪽에서 아래쪽으로 하차할 때 판매점으로 판단한다.
가짜 돌파를 필터링하기 위해, 돌파가 발생했을 때 전 K 선의 변화율이 설정 가능한 값 (예: 3%) 보다 작는지 확인하고, 부린 벨트 상하 궤도 간격이 설정 가능한 거리 (예: 2.2%) 보다 크는지 확인한다.
포지션을 개시한 후 설정할 수 있는 스톱로스 (예: 3%) 와 스톱 (예: 10%) 를 설정하여 수익을 고정한다.
이중 EMA는 주 트렌드를 판단하여 주 트렌드가 불분명할 때 무질서하게 포지션을 개설하는 것을 피한다.
적응형 부린 띠는 개시점을 설정하고, 트렌드에 따라 자동으로 대역폭 파라미터를 조정하여 추세를 더욱 고정합니다.
변동률과 최소 대역폭 검사 메커니즘은 가짜 돌파구를 효과적으로 필터링한다.
상쇄장치 설정이 합리적이고, 수익을 고정하는 위험도 조절할 수 있다.
이중 EMA는 전환점을 정확하게 판단하지 못하여 트렌드 전환 기회를 놓칠 수 있습니다.
부린 밴드 파라미터를 잘못 설정하면 가짜 신호가 발생할 수 있다.
고정된 스피드 스은 시장의 변동에 적응하기 힘들다.
다른 지표와 함께 추세를 판단하여 주요 트렌드 전환점을 결정한다.
브린 대역변수를 동적으로 조정하는 방법을 사용한다.
조건형 단발 스톱 손실을 설정하고, 특정 조건에 따라 스톱 라인을 조정한다.
이 전략은 쌍 EMA 판단 주 트렌드 및 부린 밴드 발견 기회의 방법을 통합하여 트렌드 추적 거래를 구현합니다. 전략의 장점은 합리적으로 개시 및 중지 조건을 설정하여 트렌드 수익을 효과적으로 잠금 할 수 있습니다. 또한 전환점을 판단 할 수 없는 것과 부린 밴드 파라미터를 부적절하게 설정하는 것과 같은 위험이 있습니다. 이러한 문제에는 더 나은 최적화 공간이 있으며, 전략이 트렌드 수익을 더 잘 파악 할 수 있습니다.
/*backtest
start: 2022-12-04 00:00:00
end: 2023-12-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//////////////////////////////////////////////////////////////////////
// Component Code Start
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2039, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false
// Component Code Stop
strategy("Custom Band Strategy", overlay=true)
source = close //종가 기준
//추세 조건 설정
emaLong = ema(source, input(200, minval=0))
emaShort = ema(source, input(30, minval=0))
trend = if emaShort>=emaLong
1
else
-1
plot(emaLong, color=red, transp=0)
plot(emaShort, color=blue, transp=0)
//BB 계산(default 14/3.2)
length = input(8, minval=1)
basis = sma(source, length)
plot(basis, color=green, transp=0)
max=highest(abs(source-basis), length)
factor1 = input(1.3, minval=0.5)
factor2 = input(1.1, minval=0.5)
upper = if trend==1
basis + max*factor1
else
basis + max*factor2
lower = if trend==-1
basis - max*factor1
else
basis - max*factor2
plot1 = plot(upper)
plot2 = plot(lower)
fill(plot1, plot2, transp=80, color=green)
//밴드 이탈 후 재진입 조건 설정
cross_over = (low<=lower and close>=lower) or crossover(close,lower)
cross_under = (high>=upper and close<=upper) or crossunder(close,upper)
//변동율 계산
maxCandle=highest(abs(open-close), length)
roc = abs(open-close)/open*100
changerate = input(3, minval=0.0)
//수익률 계산
value = abs(strategy.position_size)*strategy.position_avg_price
roe = strategy.openprofit/value * 100
expRoeL = (upper-lower)/lower*100
expRoeS = (upper-lower)/upper*100
exp = input(2.2, minval=0.0)
target = input(10, minval=0.0)
stop = input(-3, minval=-10.0)
strategy.close_all(when=roc>=changerate and testPeriod())
strategy.close_all(when=roe>=target and testPeriod())
strategy.close_all(when=roe<=stop and testPeriod())
plotchar(crossover(close,lower) and crossunder(close,upper),color=blue, transp=0, text="cross")
plotchar(roc>=changerate,color=red, transp=0, text="roc")
plotchar(roe>=target,color=blue, transp=0, text="target")
plotchar(roe<=stop,color=green, transp=0, text="stop")
minroe = input(2, minval=0.0)
strategy.close_all(when=cross_under and roe>minroe and testPeriod())
strategy.entry("BBandLE", strategy.long, stop=source, oca_name="BollingerBands", comment="BBandLE", when=(cross_over) and trend==1 and roc<changerate and expRoeL>exp and source>emaLong and strategy.position_size==0 and testPeriod()) //trend==1 and
//else
strategy.close_all(when=cross_over and roe>minroe and testPeriod())
strategy.entry("BBandSE", strategy.short, stop=source, oca_name="BollingerBands", comment="BBandSE", when=(cross_under) and trend==-1 and roc<changerate and expRoeS>exp and source<emaLong and strategy.position_size==0 and testPeriod()) //trend==-1 and