모멘텀 스윙 트레이딩 전략


생성 날짜: 2023-12-15 11:00:25 마지막으로 수정됨: 2023-12-15 11:00:25
복사: 0 클릭수: 679
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

모멘텀 스윙 트레이딩 전략

개요

다이내믹 모멘텀 오스실레이터 트레이딩 전략 (Dynamic Momentum Oscillator Trading Strategy, DMO 전략) 은 동력 흔들림 지표를 기반으로 한 15 분 단선 거래 전략이다. 이 전략은 여러 가지 기술 지표를 결합하여 높은 정밀도의 거래 신호를 구현하여 초보자 거래자가 짧은 시간에 구매 결정을 내리고, 위험을 통제하고, 수익률을 높일 수 있도록 효과적으로 지원한다.

전략 원칙

이 전략은 우선 도인치안 채널을 사용하여 시장의 주요 트렌드 방향을 판단한다. 가격이 이 채널을 뚫을 때 상행선 시 bullish 신호이며, 상행선 시 bearish 신호이다. 다음으로, 전략은 3가지의 헐 이동 평균 변종 중 하나를 사용하여 ATR 채널에 맞게 더 정확한 추세를 판단한다.

우위 분석

DMO 전략의 가장 큰 장점은 여러 지표가 유기적으로 결합되어 서로 다른 지표가 서로 검증되어 가짜 신호를 필터링하여 매 거래 신호를 더 정확하고 신뢰할 수 있다는 것입니다. 또한, 도인치안 채널은 주 트렌드를 판단하는 방법이 간단하고 직접적이며, 반 전체 평균 선 필터 신호의 수단도 일반적입니다. 전반적으로 이해하기 쉽고, 초보자가 다루기 어렵지 않습니다. 단일 지표와 비교하면 DMO는 동일한 거래 횟수에서 더 높은 승률과 수익률을 얻을 수 있습니다.

위험 분석

DMO 전략은 안정적이고 신뢰할 수 있음에도 불구하고, 모든 양적 거래 전략에는 반드시 위험이 있습니다. 특히, 빠른 선과 중간 선이 사각지대를 만들 때, 다른 지표 검증이 없으면 여전히 가짜 신호가 될 수 있습니다. 또한, 모든 짧은 선 전략과 마찬가지로, DMO는 과도한 거래 위험에 직면합니다. 시장의 갑작스러운 사건으로 지표가 실패하면, 중단 손실이 잘못 설정되면 큰 손실이 발생할 수 있습니다. 위험을 줄이기 위해 중·장기 지표 매개 변수를 적절하게 조정하고 더 높은 시간 주기 지표와 조합 검사를 수행하는 동시에 큰 손실 거리를 추가하여 단독 손실을 엄격하게 제어하는 것이 좋습니다.

최적화 방향

DMO 전략은 다음과 같은 몇 가지 차원에서 최적화 될 수 있습니다: 첫째, 헐 MA의 파라미터를 조정하여 이동 평균의 길이를 최적화하고, 부드러운 효과와 민감성 사이의 균형을 맞추기; 둘째, 도인치안 통로 판단 논리를 개선하여 통로 파라미터를 조정하거나 추가 조건 제한을 추가합니다. 셋째, 부린밴드, KDJ 등과 같은 반 전체 평균을 대신하여 보조 필터링 효과를 향상시키는 다른 지표를 시도합니다. 넷째, 다른 품종의 특성에 따라 적절한 거래 간격을 지정하여 5분 또는 30분으로 변경하십시오. 이러한 최적화 조치는 시장 환경 및 품종 특성에 따라 DMO 전략을 수립하고, 전략의 안정성을 향상시키는 데 도움이됩니다.

요약하다

DMO는 다중 지표 최적화 포트폴리오의 단선 전략이다. 그것은 도인치안 채널, 헐 MA 및 반 전체 평균을 결합하여 시장 추세를 효과적으로 판단하고 정확한 거래 신호를 생성한다. 전략 수단은 비교적 간단하고 직관적이며, 조작의 어려움이 많지 않으며, 초보자 입문 전략으로 사용할 수 있다. 단일 지표에 비해 DMO는 더 높은 거래 승률과 수익률을 창출한다.

전략 소스 코드
/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 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/
// © kgynofomo

//@version=5
strategy(title="[Salavi] | Andy Super Pro Strategy [BTC|M15]",overlay = true, pyramiding = 1,initial_capital = 10000, default_qty_type = strategy.cash,default_qty_value = 10000)

//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)