모멘텀 브레이크아웃 트렌드 추종 전략


생성 날짜: 2023-11-06 09:37:44 마지막으로 수정됨: 2023-11-06 09:56:20
복사: 0 클릭수: 698
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

모멘텀 브레이크아웃 트렌드 추종 전략

개요

이 전략은 트렌드 방향을 식별하는 여러 가지 기술 지표를 통합하여 트렌드가 동력을 뚫을 때 추적하여 초과 수익을 추구합니다.

전략 원칙

  1. Donchian 통로를 사용하여 전체 트렌드 방향을 판단한다. 가격이 이 통로를 뚫었을 때, 트렌드가 변하는 것을 확인한다.

  2. 헐 이동 평균은 트렌드 방향을 결정하는데 도움을 준다. 이 지표는 가격 변화에 민감하여 트렌드 회전을 사전에 발견할 수 있다.

  3. 반궤도 시스템은 구매 및 판매 신호를 발송한다. 이 시스템은 가격 통로와 평균 실제 변동 범위에 기반하여 가짜 돌파구를 피할 수 있다.

  4. Donchian 통로, Hull 지표 및 반궤도 시스템이 동시에 신호를 발산할 때, 트렌드가 발생했다고 판단한 강력한 동력이 뚫려, 이 때 경기장에 들어간다.

  5. 평점 조건: 위의 지표가 역전 신호를 냈을 때, 트렌드가 반전되었다고 판단하고, 즉시 손실을 중단하고 탈퇴한다.

우위 분석

  • 다중 지표 조합, 판단력이 강하다. Donchian 통로는 기본 사항을 판단하고, Hull 지표와 반궤도는 세부 사항을 판단하여 트렌드를 정확하게 파악합니다.

  • 동력이 뚫린 참여, 과잉 수익을 추구한다. 강한 트렌드 뚫린 경우에만 출전하고, 흔들림에 걸리지 않도록 한다.

  • 엄격한 중지, 자금 안전을 보장한다. 지표가 역전 신호를 발산하면 즉시 중지, 손실이 확대되는 것을 피한다.

  • 매개 변수 조절은 다양한 시장에 적응할 수 있다. 채널 길이, 변동 간격 등의 매개 변수를 조정할 수 있으며, 다른 주기들에 대해 최적화한다.

  • 이해하기 쉽고 구현하기 쉽고, 초보자도 익힐 수 있다. 지표와 조건의 조합은 간단하고 명확하며, 프로그래밍하기 쉽다.

위험 분석

  • 트렌드 초기에 놓친 기회. 진입 시기가 늦고 초기 상승은 잡히지 않는다.

  • 돌파 실패 회전 손해 . 진입 후 돌파 실패와 반전이 발생할 수 있으며, 이로 인해 손해 .

  • 지표가 잘못된 신호를 낸다. 파라미터가 잘못 설정되어 지표 판단에 오류가 발생할 수 있다.

  • 거래 횟수가 제한된다. 명확한 트렌드 돌파할 때만 입점한다. 연간 거래 횟수는 제한된다.

최적화 방향

  • 최적화 변수 조합 testing different parameters to find the best combination

  • 스톱 손실을 줄이고, 트렌드 기회를 놓치지 않도록 한다.

  • 다른 지표 필터를 추가한다. MACD, KDJ 등 보조 판단, 잘못된 신호를 줄인다.

  • 거래 시간대를 최적화하십시오. 다른 시간대의 매개 변수를 최적화 할 수 있습니다.

  • 자금 사용 효율을 확대한다. 레버리지, 고정 투자 등의 방법으로 자금 사용 효율을 향상한다.

요약하다

이 전략은 여러 지표들을 통합하여 트렌드가 동력으로 돌파되는 시기를 판단하고, 형성된 트렌드를 추적하여 초과 수익을 달성한다. 엄격한 손해 방지 장치가 위험을 제어하고, 다양한 시장 환경에 적응하는 유연한 변수 조절이 있다. 거래 빈도가 낮음에도 불구하고, 각 거래는 높은 수익을 얻기 위해 노력하고 있다. 변수 최적화, 보조 지표 도입 등의 방법으로 이 전략은 지속적인 개선을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-10-29 00:00:00
end: 2023-11-05 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/
// © kgynofomo

// @version=5
strategy(title="[Salavi] | Andy Super Pro Strategy",overlay = true)

//Doinchian Trend Ribbon
dlen = input.int(defval=30, minval=10)

dchannel(len) =>
    float hh = ta.highest(len)
    float ll = ta.lowest(len)

    int trend = 0
    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
    trend

dchannelalt(len, maintrend) =>
    float hh = ta.highest(len)
    float ll = ta.lowest(len)

    int trend = 0
    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
    maintrend == 1 ? trend == 1 ? #00FF00ff : #00FF009f : maintrend == -1 ? trend == -1 ? #FF0000ff : #FF00009f : na

maintrend = dchannel(dlen)
donchian_bull = maintrend==1
donchian_bear = maintrend==-1


//Hulls
src = input(hlc3, title='Source')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])
length = input(55, title='Length')
lengthMult = input(1.0, title='Length multiplier ')

useHtf = false
htf = '240'

switchColor = true
candleCol = false
visualSwitch = true
thicknesSwitch = 1
transpSwitch = 40

//FUNCTIONS
//HMA
HMA(_src, _length) =>
    ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
//EHMA    
EHMA(_src, _length) =>
    ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))
//THMA    
THMA(_src, _length) =>
    ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)

//SWITCH
Mode(modeSwitch, src, len) =>
    modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na

//OUT
_hull = Mode(modeSwitch, src, int(length * lengthMult))
HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
MHULL = HULL[0]
SHULL = HULL[2]

//COLOR
hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800
hull_bull = HULL > HULL[2]
bull_start = hull_bull and hull_bull[1]==false
hull_bear = HULL < HULL[2]
bear_start = hull_bear and hull_bear[1]==false

barcolor(color=candleCol ? switchColor ? hullColor : na : na)

//halftrend
amplitude = input(title='Amplitude', defval=2)
channelDeviation = input(title='Channel Deviation', defval=2)
// showArrows = input(title='Show Arrows', defval=true)
// showChannels = input(title='Show Channels', defval=true)

var int trend = 0
var int nextTrend = 0
var float maxLowPrice = nz(low[1], low)
var float minHighPrice = nz(high[1], high)

var float up = 0.0
var float down = 0.0
float atrHigh = 0.0
float atrLow = 0.0
float arrowUp = na
float arrowDown = na

atr2 = ta.atr(100) / 2
dev = channelDeviation * atr2

highPrice = high[math.abs(ta.highestbars(amplitude))]
lowPrice = low[math.abs(ta.lowestbars(amplitude))]
highma = ta.sma(high, amplitude)
lowma = ta.sma(low, amplitude)

if nextTrend == 1
    maxLowPrice := math.max(lowPrice, maxLowPrice)

    if highma < maxLowPrice and close < nz(low[1], low)
        trend := 1
        nextTrend := 0
        minHighPrice := highPrice
        minHighPrice
else
    minHighPrice := math.min(highPrice, minHighPrice)

    if lowma > minHighPrice and close > nz(high[1], high)
        trend := 0
        nextTrend := 1
        maxLowPrice := lowPrice
        maxLowPrice

if trend == 0
    if not na(trend[1]) and trend[1] != 0
        up := na(down[1]) ? down : down[1]
        arrowUp := up - atr2
        arrowUp
    else
        up := na(up[1]) ? maxLowPrice : math.max(maxLowPrice, up[1])
        up
    atrHigh := up + dev
    atrLow := up - dev
    atrLow
else
    if not na(trend[1]) and trend[1] != 1
        down := na(up[1]) ? up : up[1]
        arrowDown := down + atr2
        arrowDown
    else
        down := na(down[1]) ? minHighPrice : math.min(minHighPrice, down[1])
        down
    atrHigh := down + dev
    atrLow := down - dev
    atrLow

ht = trend == 0 ? up : down

var color buyColor = color.blue
var color sellColor = color.red

htColor = trend == 0 ? buyColor : sellColor
// htPlot = plot(ht, title='HalfTrend', linewidth=2, color=htColor)

// atrHighPlot = plot(showChannels ? atrHigh : na, title='ATR High', style=plot.style_circles, color=color.new(sellColor, 0))
// atrLowPlot = plot(showChannels ? atrLow : na, title='ATR Low', style=plot.style_circles, color=color.new(buyColor, 0))

// fill(htPlot, atrHighPlot, title='ATR High Ribbon', color=color.new(sellColor, 90))
// fill(htPlot, atrLowPlot, title='ATR Low Ribbon', color=color.new(buyColor, 90))

HalfTrend_buySignal = not na(arrowUp) and trend == 0 and trend[1] == 1
HalfTrend_sellSignal = not na(arrowDown) and trend == 1 and trend[1] == 0

// plotshape(showArrows and buySignal ? atrLow : na, title='Arrow Up', style=shape.triangleup, location=location.absolute, size=size.tiny, color=color.new(buyColor, 0))
// plotshape(showArrows and sellSignal ? atrHigh : na, title='Arrow Down', style=shape.triangledown, location=location.absolute, size=size.tiny, color=color.new(sellColor, 0))




//ema
filter_ema = ta.ema(close,200)
ema_bull = close>filter_ema
ema_bear = close<filter_ema

atr_length = input.int(7)
atr = ta.atr(atr_length)
atr_rsi_length = input.int(50)
atr_rsi = ta.rsi(atr,atr_rsi_length)
atr_valid = atr_rsi>50

longCondition = bull_start and atr_valid
shortCondition = bear_start and atr_valid

Exit_long_condition = shortCondition
Exit_short_condition = longCondition

if longCondition
    strategy.entry("Andy Buy",strategy.long, limit=close,comment="Andy Buy Here")

if Exit_long_condition
    strategy.close("Andy Buy",comment="Andy Buy Out")
    // strategy.entry("Andy fandan Short",strategy.short, limit=close,comment="Andy 翻單 short Here")
    // strategy.close("Andy fandan Buy",comment="Andy short Out")


if shortCondition
    strategy.entry("Andy Short",strategy.short, limit=close,comment="Andy short Here")


// strategy.exit("STR","Long",stop=longstoploss)
if Exit_short_condition
    strategy.close("Andy Short",comment="Andy short Out")
    // strategy.entry("Andy fandan Buy",strategy.long, limit=close,comment="Andy 翻單 Buy Here")
    // strategy.close("Andy fandan Short",comment="Andy Buy Out")




inLongTrade = strategy.position_size > 0
inLongTradecolor = #58D68D
notInTrade = strategy.position_size == 0
inShortTrade = strategy.position_size < 0

// bgcolor(color = inLongTrade?color.rgb(76, 175, 79, 70):inShortTrade?color.rgb(255, 82, 82, 70):na)
plotshape(close!=0,location = location.bottom,color = inLongTrade?color.green:inShortTrade?color.red:na)


plotshape(longCondition, title='Buy', text='Andy Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(shortCondition, title='Sell', text='Andy Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

Fi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)
Fi2 = plot(SHULL, title='SHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)

fill(Fi1, Fi2, title='Band Filler', color=hullColor, transp=transpSwitch)