모멘텀 브레이크업 거래 전략

저자:차오장, 날짜: 2024-02-04 10:55:31
태그:

img

전반적인 설명

이 전략은 동력에 기반한 브레이크아웃 거래 전략이다. 시장 추세와 변동성을 판단하기 위해 이동 평균, ATR, RSI 및 기타 지표를 사용하여 거래에 대한 엄격한 스톱 로스 / 영리 설정과 결합합니다. 전략은 주로 가격이 이동 평균과 ATR 범위를 넘어 또는 아래로 떨어지는지 판단하여 거래 신호를 생성합니다.

전략 원칙

이 전략의 주요 내용은 다음과 같습니다.

  1. 가격 트렌드 방향을 판단하기 위해 EMA를 사용하십시오. EMA 이상의 가격 경선은 상승 신호이며 아래의 경선은 하락 신호입니다.

  2. ATR은 시장 변동성을 나타냅니다. ATR을 계수로 곱하면 스톱 로스 범위로 사용됩니다. 이것은 단일 손실을 효과적으로 제어 할 수 있습니다.

  3. RSI는 과잉 구매/ 과잉 판매 상태를 나타냅니다. 스톱 로스 가격과 EMA 크로스오버에 의해 신호되는 브레이크업 거래는 RSI가 과잉 구매/ 과잉 판매 구역에 있지 않을 때 이루어져야 합니다. 이것은 거짓 브레이크업을 피합니다.

  4. 이전 기간의 높은 / 낮은 점을 취득 기준으로 사용하십시오. 취득 가격을 추적하면 더 많은 이익을 얻을 수 있습니다.

  5. 엄격한 스톱 로스/프로피스 취득 규칙 ATR 기반 스톱 로스 리스크 제어 및 이윤 취득 잠금

엔트리 신호는 가격이 EMA와 ATR 스톱 로스 범위를 넘을 때 발생한다. 상승 신호의 경우 가격이 높은 지점을 넘어야 한다. 하락 신호의 경우 가격이 낮은 지점을 넘어야 한다.

이점 분석

이 전략의 장점:

  1. 다중 표시기 는 잘못된 브레이크 를 방지 하고 정확성 을 향상 시킨다.

  2. ATR 스톱 로스는 적당한 수준에서 손실을 유지합니다.

  3. 동적 취득 추적은 이익을 극대화합니다.

  4. 엄격한 규칙은 위험 통제를 촉진합니다.

  5. 다양한 시장에 적응하기 위한 지표와 매개 변수에 대한 최적화 공간

위험 분석

이 전략의 위험:

  1. 수익성은 시장의 변동성과 상관관계를 가지고 있습니다. 추세가 불분명하거나 주기가 길다면 이익은 제한 될 수 있습니다.

  2. 스톱 로스 가격은 다시 깨지기 전에 윙사브가 될 수 있습니다. 이것은 트렌드를 놓치는 데로 이어집니다. 스톱 로스 가격을 약간 느리게 할 수 있습니다.

3.트렌딩 시장에서 추격할 가능성이 있습니다.

최적화 방향

최적화 아이디어:

  1. 각기 다른 제품과 시간 프레임에 대한 MA, ATR 매개 변수를 조정합니다.

  2. MACD, KDJ와 같은 더 많은 지표를 추가하십시오.

  3. 동적 정지시 실시간 ATR 값에 기초한 ATR 계수를 동적으로 조정합니다.

  4. 여러 시간 프레임을 가진 콤보 시스템을 설치하십시오. 다른 시간 프레임 지표는 신호 품질을 향상시킬 수 있습니다.

  5. 최고의 성능을 달성하기 위해 매개 변수 / 지표 최적화를 위해 기계 학습을 활용하십시오.

요약

이 전략은 판단을 위한 지표와 엄격한 스톱 로스/프로프트를 활용한다. 시장 트렌드를 결정하기 위해 이동 평균, ATR 및 RSI를 활용한다. 엄격한 리스크 제어로 리스크를 관리하면서 트렌드를 탈 수 있다. 추가 매개 변수 및 규칙 최적화는 장기적으로 수익성이 높은 거래 시스템으로 만들 수 있다.


/*backtest
start: 2024-01-27 00:00:00
end: 2024-02-03 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="UT Bot Strategy", overlay = true)
//CREDITS to HPotter for the orginal code. The guy trying to sell this as his own is a scammer lol. 
// Inputs
emaLengh = input(2, title = "emaLengh")
a = input(3.0,     title = "Key Vaule. 'This changes the sensitivity'")
c = input(10,    title = "ATR Period")
h = input(false, title = "Signals from Heikin Ashi Candles")
emaLengh2 = input(9, title = "emaLengh show")




rate = input(0.00025,    title = "波动率min")
rateMax = input(0.00045,    title = "波动率max")
adx_length =   input(20,    title = "adx_length")
adx_min =   input(14,    title = "adx_min")

sma_length =   input(11,    title = "sma_length")
rsi_len = input(9, title = "rsi_len")

src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close

// boll 通道----------------------------------------------------
length = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
bbr = (src - lower)/(upper - lower)
// plot(upper, color = color.rgb(46, 59, 240), title="upper")
// plot(lower, color = color.rgb(46, 59, 240), title="lower")


// plot(bbr, "Bollinger Bands %B", color=#26A69A)
// band1 = hline(1, "Overbought", color=#787B86, linestyle=hline.style_dashed)
// hline(0.5, "Middle Band", color=color.new(#787B86, 50))
// band0 = hline(0, "Oversold", color=#787B86, linestyle=hline.style_dashed)
// fill(band1, band0, color=color.rgb(38, 166, 154, 90), title="Background")
// boll 通道----------------------------------------------------

// 线性回归 --------------------------------------------------------------
zlsma_length = input(title="zlsma-Length", type=input.integer, defval=50)
zlsma_offset = input(title="zlsma-Offset", type=input.integer, defval=0)
lsma = linreg(src, zlsma_length, zlsma_offset)
lsma2 = linreg(lsma, zlsma_length, zlsma_offset)
eq= lsma-lsma2
zlsma = lsma+eq
// plot(zlsma , color = color.rgb(243, 243, 14), title="zlsma",linewidth=3)
// 线性回归 --------------------------------------------------------------



// --------------------------------
rsi = rsi(src, 6)

// xHH = sma(high, sma_length)
// xLL = sma(low, sma_length)
// movevalue = (xHH - xLL) / 2
// xHHM = xHH + movevalue
// xLLM = xLL - movevalue

// plot(xHHM, color = color.rgb(208, 120, 219), title="xHHM")
// plot(xLLM, color = color.rgb(208, 120, 219), title="xLLM")


xATR  = atr(c)
nLoss = a * xATR



xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
   iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss), 
   iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))


 
pos = 0   
pos :=	iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
   iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 
   
xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue 

ema   = ema(src,emaLengh)
// sma   = sma(src,emaLengh)
emaFast   = ema(src,100)
emaSlow   = ema(src,576)
emaShow   = ema(src, emaLengh2)
// sma       =  sma(src, 8)

// [superTrend, dir] = supertrend(3, 200) 
// 判断连续涨

[diplus, diminus, adx] = dmi(adx_length, adx_length)


above = crossover(ema, xATRTrailingStop)
below = crossover(xATRTrailingStop, ema)
// above = ema == xATRTrailingStop
// below = xATRTrailingStop== ema

// smaabove = crossover(src, sma)
// smabelow = crossover(sma, src)
// smaabove = src > sma
// smabelow = sma > src
close_rate (n)=>
    abs(close[n]-open[n])/min(close[n],open[n])

rate_val = close_rate(0)
rate_val1 = close_rate(1)

buy  = src > xATRTrailingStop and above  and src > zlsma  and adx >adx_min
// and  src>emaShow
// and rate_val < rate_val1*2 and rate_val >=rate_val1
// and rate_val1<rateMax
// and close[1]>open[1] 
sell = src < xATRTrailingStop and below  and src < zlsma and adx >adx_min
// and  src<emaShow
// and rate_val < rate_val1*2  and rate_val >=rate_val1
//  and rate_val1<rateMax
// and open[1]>close[1]  and rate_val1 > rate  

// buy  = src > xATRTrailingStop 
// sell = src < xATRTrailingStop 
// plot(rate_val1 , color = color.red, title="rate_val1")



barbuy  = src > xATRTrailingStop 
barsell = src < xATRTrailingStop

atrRsi = rsi(xATRTrailingStop,rsi_len)

// plot(emaFast , color = color.rgb(243, 206, 127), title="emaFast")
// plot(ema , color = color.rgb(47, 227, 27), title="ut-ema")



// plot(emaShow , color = color.rgb(47, 227, 27), title="ema9")

plot(xATRTrailingStop, color = color.rgb(233, 233, 232), title="xATRTrailingStop")

plotshape(buy,  title = "Buy",  text = 'Buy',  style = shape.labelup,   location = location.belowbar, color= color.green, textcolor = color.white, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red,   textcolor = color.white, size = size.tiny)


// plotshape(buy,  title = "Sell",  text = 'Sell',  style = shape.labelup,   location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
// plotshape(sell, title = "buy", text = 'buy', style = shape.labeldown, location = location.abovebar, color= color.red,   textcolor = color.white, transp = 0, size = size.tiny)

// barcolor(barbuy  ? color.green : na)
// barcolor(barsell ? color.red   : na)

// strategy.entry("short",   false, when = buy)
// strategy.entry("long ", true, when = sell)


strategy.entry("long",   true, when = buy and strategy.position_size == 0)
strategy.entry("short", false, when = sell and strategy.position_size == 0)


//动态止盈start------------------------------------------------------------------------------------------
profit = input( 0.015,     title = "最小收益率")
close_profit_rate = input( 10,     title = "平仓收益回撤比")
loss = input(0.004,    title = "回撤率")

// 收益回撤比例
profit_price_scale =profit/close_profit_rate

var float profit_price = 0


// 计算小收益价格

get_profit_price(long) =>
    float res = 0
    if long == true
        res := strategy.position_avg_price * (1+profit)
    if long == false
        res := strategy.position_avg_price * (1-profit)
    res

// 止盈平仓条件
close_profit_position(long)=>
    bool result=false
    if long == true and profit_price>0 and profit_price*(1-profit_price_scale) >=close and  get_profit_price(true) <= close 
        result:=true
    if long == false and profit_price>0 and profit_price*(1+profit_price_scale) <=close and  get_profit_price(false) >= close 
        result:=true
    result

// 更新动态止盈价格
update_profit_price(price)=>
    float res = price
   // 无仓位时 动态止盈价格为0
    if strategy.position_size == 0 
        res := 0
   // long - 价格大于最小收益时保存
    if strategy.position_size > 0 and get_profit_price(true) <= close and (res==0 or res < close)
        res := close
   // short - 价格小于最小收益时保存
    if strategy.position_size < 0 and get_profit_price(true) >= close and (res==0 or res > close)
        res := close
    res
   
///////



profit_price := update_profit_price(profit_price)
long_close_profit_position = close_profit_position(true)
short_close_profit_position = close_profit_position(false)

// plot(profit_price, color = color.green, title="profit_price")
//动态止盈end------------------------------------------------------------------------------------------




strategy.close("long",comment="long-止盈",when = strategy.position_size > 0 and long_close_profit_position)

strategy.close("long",comment="long-止损",when = strategy.position_size >0 and strategy.position_avg_price * (1-loss) >= close)

strategy.close("short",comment="short-止盈",when = strategy.position_size <0 and short_close_profit_position)

strategy.close("short",comment="short-止损",when = strategy.position_size <0 and strategy.position_avg_price * (1+loss) <= close)

  






더 많은