
이 전략은 부린 띠 지표를 사용하여 다공간 브레이크 포인트를 찾고, ADX 지표와 결합하여 하향 변동의 불리한 행동을 필터링하여 트렌드 추적을 수행합니다.
이 전략은 주로 부린 띠 지표에 기반하여 다공간 방향을 판단한다. 부린 띠 중선은 N일 종전 가격의 이동 평균이며, 대역은 표준 차원에서 계산된다. 가격이 하향 경로를 돌파 할 때 다공간 신호로 판단하고, 가격이 경로를 돌파 할 때 공중 신호로 판단한다.
비 트렌드 상태의 비효율적인 돌파구로 인한 잘못된 거래를 피하기 위해, 이 전략은 ADX 지표를 결합하여 낮은 변동성을 필터링한다. ADX 값이 설정된 경미치보다 낮으면 구매 신호가 발송된다. ADX 값이 경미치보다 높으면 모든 포지션을 평행하고, 트렌드 전환을 기다린다.
이 전략은 또한 회귀 손해 중지 및 상향 추적 중지 설정한다. 구체적으로, 매번 포지션을 열면, 이전 N 일간의 최저 가격은 회귀 손해 중지 지점으로 기록되고, 최고 가격은 상향 추적 중지 지점으로 기록된다. 이것은 수익을 잠금화하면서 역전으로 인한 손실을 최소화 할 수 있다.
코드 논리적으로 볼 때, 이 전략은 먼저 부린 반지와 ADX 지표 파라미터를 계산한다. 다음으로 가격이 부린 반지를 뚫고 하향 궤도에 올랐는지 판단하고, ADX 값이 하위치보다 낮아지면 구매 신호를 발생시킨다. 그 다음에는 지주 여부와 지주 방향에 따라 실시간으로 업데이트 및 추적 스톱 손실 스톱을 발생시킨다.
다른 지표의 판단량 지원과 결합하여 VALID를 뚫을 수 있도록 고려할 수 있습니다. ADX 필터링 조건을 최적화하여 ADX 곡선의 기울기를 사용하여 트렌드 전환점을 판단합니다.
이 전략의 전체적인 아이디어는 명확하고 간결하며, 브린 띠를 사용하여 명확한 다공간 돌파 신호를 판단하고, ADX 지표를 사용하여 명확한 추세가없는 Choppy 거래를 필터링하여 트렌드 기회를 잠금합니다. 동시에 리모컨 스톱과 추적 스톱을 설정하여 위험을 제어하고 수익을 잠금합니다. 이 전략은 구현을 이해하기 쉽고, 추가 테스트 및 최적화를 할 가치가 있으며, 기본 트렌드 추적 전략이 될 수 있습니다.
/*backtest
start: 2023-10-26 00:00:00
end: 2023-11-02 00:00:00
period: 1m
basePeriod: 1m
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/
// © tweakerID
// This strategy uses Bollinger Bands to buy when the price
// crosses over the lower band and sell when it crosses down
// the upper band. It only takes trades when the ADX is
// below a certain level, and exits all trades when it's above it.
//@version=4
strategy("BB + ADX Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value = 0.04, initial_capital=100)
//Inputs
i_reverse=input(false, title="Reverse Trades")
i_ADXClose=input(true, title="ADX Close")
i_SL=input(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")
i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")
i_SLExpander=input(defval=0, step=.5, title="SL Expander")
i_TPExpander=input(defval=0, step=.5, title="TP Expander")
//ADX Calculations
adxlen = input(14, title="ADX Smoothing")
dilen = input(20, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
adxlevel=input(30, step=5)
//BB Calculations
BBCALC=input(false, title="-----------BB Inputs-----------")
length = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50)
MAlen=input(defval=9)
source = close
basis = sma(source, length)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
//Entry Logic
BUY = crossover(source, lower) and sig < adxlevel
SELL = crossunder(source, upper) and sig < adxlevel
//SL & TP Calculations
SwingLow=lowest(i_SwingLookback)
SwingHigh=highest(i_SwingLookback)
bought=strategy.position_size != strategy.position_size[1]
LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0))*i_SLExpander)
SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0))*i_SLExpander)
lTP=strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0))+((valuewhen(bought, atr(14), 0))*i_TPExpander))
sTP=strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((valuewhen(bought, atr(14), 0))*i_TPExpander)
islong=strategy.position_size > 0
isshort=strategy.position_size < 0
SL= islong ? LSL : isshort ? SSL : na
TP= islong ? lTP : isshort ? sTP : na
//Entries
strategy.entry("long", long=i_reverse?false:true, when=BUY)
strategy.entry("short", long=i_reverse?true:false, when=SELL)
//EXITS
if i_ADXClose
strategy.close_all(when=sig > adxlevel)
if i_SL
strategy.exit("longexit", "long", stop=SL, limit=TP)
strategy.exit("shortexit", "short", stop=SL, limit=TP)
//Plots
plot(i_SL ? SL : na, color=color.red, style=plot.style_cross, title="SL")
plot(i_SL ? TP : na, color=color.green, style=plot.style_cross, title="TP")
plot(upper)
plot(lower)