다중 시간대 모멘텀 브레이크아웃 전략


생성 날짜: 2023-12-29 16:56:09 마지막으로 수정됨: 2023-12-29 16:56:09
복사: 1 클릭수: 663
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

다중 시간대 모멘텀 브레이크아웃 전략

개요

이 전략은 RSI, ADX, ATR 및 동력 지표와 같은 여러 가지 기술 지표와 결합하여 트렌드를 판단하고 돌파구를 포착합니다. 이 전략은 피보나치 회귀선과 평균선을 결합하여 핵심 지점과 트렌드를 판단하는 정확성을 더욱 향상시킵니다.

전략 원칙

  1. RSI, ADX, DI+, DI- 등의 지표를 통해 트렌드 방향과 강도를 판단한다. RSI는 과매매를 나타낼 수 있다. ADX는 트렌드 강도를 나타내고, DI+/DI-는 다면 및 공백 트렌드를 판단한다.

  2. 평균선과 결합하여 트렌드 방향을 판단한다. 5일과 9일 EMA를 이용하여 단기 트렌드를 판단하고, 21일 WMA를 이용하여 중기 트렌드를 판단하고, 60일 WMA를 통하여 장기 트렌드를 판단한다. 단기 상에서 중기 장기 평균선을 통과할 때 다목적 신호이다.

  3. 피보나치 회귀선을 사용하여 0.5, 0.618과 같은 중요한 지지를 찾으십시오. 이 지점은 종종 잠재적인 전환점입니다.

  4. ATR와 스톱 손실 비율을 기반으로 스톱 손실 가격을 설정하여 위험을 제어하십시오. ATR와 스톱 손실 비율을 기반으로 스톱 손실 가격을 설정하여 이익을 잠금하십시오.

  5. RSI 오버 바이 오버 셀 신호가 발생했을 때, 반전 진입을 고려하십시오. 단기 평균선 상에서 뚫렸을 때 (아래로 뚫렸을 때) 중기 평균선과 거래량이 커질 때 트렌드를 추적하는 진입을 고려하십시오. 신호에 진입한 후 스톱로스와 스톱 스톱을 설정하십시오.

우위 분석

  1. 트렌드 방향과 강도를 판단하기 위해 다양한 지표를 통합적으로 사용하여 의사 결정의 정확성을 향상시킵니다.

  2. ATR 기반의 스톱 로즈 스 메커니즘으로 위험을 효과적으로 제어한다.

  3. 피보나치 요점점과 결합하여 역점 판단의 정확도를 높인다.

  4. 트렌드 추적을 위한 보조 조건으로 거래량을 늘리고, 가짜 브레이크를 피한다.

  5. 표는 여러 지표의 현재 값을 직관적으로 표시하여 신속한 판단과 의사결정을 돕습니다.

위험 분석

  1. 지표가 잘못된 신호를 보내는 확률을 완전히 피할 수 없으며, 잘못된 조작의 위험을 초래할 수 있다. 매개 변수를 조정하여 지표의 매개 변수를 최적화 할 수 있다.

  2. ATR 및 중지 비율 설정은 실제 중지 포인트에 영향을 미칩니다. 이 비율이 너무 크거나 너무 작으면 어느 정도의 위험이 발생하고, 균형 설정이 필요합니다.

  3. 거래량을 확대하는 것이 엔트리의 조건으로도 가짜 돌파구를 완전히 피할 수 없으며, 가격 상황의 세부 사항과 함께 판단해야합니다.

  4. 피보나치 지점은 100% 신뢰성이 없습니다. 가격이 이 지점을 직접 통과 할 수 있습니다.

최적화 방향

  1. RSI, ADX, ATR 등의 파라미터를 테스트하고 최적화하여 최적의 파라미터 조합을 찾습니다.

  2. 다양한 평행선 조합을 테스트하여 어떤 평행선 조합이 가장 좋은지 판단합니다.

  3. 다양한 스톱로스 스톱 비율 변수를 테스트하여 리스크 수익률이 최적화된 변수를 찾습니다.

  4. 거래량을 확대하는 효과를 판단하기 위해 볼린저밴드 지표를 추가하는 것을 고려할 수 있다.

요약하다

이 전략은 종합적으로 트렌드 판단, 핵심 지점 판단, 거래량 분석 등 여러 가지 기술적 수단을 사용한다. 파라미터를 최적화하여 판단 정확성과 수익성을 더욱 향상시킨다. 스톱 로드 설치는 위험을 제어하고 수익을 극대화한다. 이 전략은 중장선 트렌드를 판단하고 단기 반전의 효과를 포착하는 데 좋다. 지속적인 최적화 테스트를 통해 전략을 더 안정적이고 신뢰할 수 있다.

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

//@version=5

strategy(" KritikSharma Strategy for NIFTY,BNIFTY,NG,CRUDE,WTICrude,BTC,GOLD,SILVER,COPPER", overlay=true)
plotHVB = input.bool(defval=true, title='Plot HVB')
plotPVT = input.bool(defval=false, title='Plot Pivots')
hvbEMAPeriod = input.int(defval=12, minval=1, title='Volume EMA Period')
hvbMultiplier = input.float(defval=1.5, title='Volume Multiplier')
pivotLookup = input.int(defval=2, minval=1, maxval=15, title='Pivot Lookup')
ShowAvg1 = input(false, title="Show trend line", group="TREND LINE Moving Average", tooltip="Display a trend line based on EMA.")
showLines1 = input.bool(defval=false, title="Draw EMA,WMA Line")
ema200_length= input.int(defval=200, minval=1, maxval=500, title='ema1')
ema300_length= input.int(defval=300, minval=1, maxval=500, title='ema2')
wma60_length= input.int(defval=60, minval=1, maxval=100, title='wma60')
ema5 = ta.ema(close, 5)
ema9 = ta.ema(close, 9)
wma21=ta.wma(close,21)
wma60=ta.wma(close,wma60_length)
len1 = input.int(11, minval=1, maxval=500, title="Length", group="TREND LINE Moving Average", tooltip="Set EMA length.")
ema=ta.ema(close, len1)
rsiLength = input.int(14, title="RSI Length", minval=1, maxval=50, group="Table ADX, RSI, DI values with Red, Green, Yellow Signal")
adxLength = input.int(14, title="ADX Length", minval=1, maxval=50, group="Table ADX, RSI, DI values with Red, Green, Yellow Signal")
adxThreshold = input.int(20, title="ADX Threshold", group="Table ADX, RSI, DI values with Red, Green, Yellow Signal")
diThreshold = input.int(25, title="DI Threshold", group="Table ADX, RSI, DI values with Red, Green, Yellow Signal")
atr = input.int(14, title="ATR values", group="Table ADX, RSI, DI values with Red, Green, Yellow Signal")
////////////////////////////////////////////////

hvbBullColor = color.rgb(181, 37, 225)
hvbBearColor = #ffbb00ad

pvtTopColor = color.new(#154bef, 0)
pvtBottomColor = color.new(#b81657, 0)

//////////////////// Pivots //////////////////// 
hih = ta.pivothigh(high, pivotLookup, pivotLookup)
lol = ta.pivotlow(low , pivotLookup, pivotLookup)
top1 = ta.valuewhen(hih, high[pivotLookup], 0)
bottom1 = ta.valuewhen(lol, low [pivotLookup], 0)
plot(top1, offset=-pivotLookup, linewidth=1, color=(top1 != top1[1] ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")
plot(bottom1, offset=-pivotLookup, linewidth=1, color=(bottom1 != bottom1[1] ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot Bottom")

//////////////////////////////////////Functions
isUp(index) =>
    close[index] > open[index]

isDown(index) =>
    close[index] < open[index]

isObUp(index) =>
    isDown(index + 1) and isUp(index) and close[index] > high[index + 1]

isObDown(index) =>
    isUp(index + 1) and isDown(index) and close[index] < low[index + 1]
////////////////// High Volume Bars //////////////////
volEma = ta.ema(volume, hvbEMAPeriod)
isHighVolume = volume > (hvbMultiplier * volEma)
barcolor(plotHVB and isUp(0) and isHighVolume ? hvbBullColor : na, title="Bullish HVB")
barcolor(plotHVB and isDown(0) and isHighVolume ? hvbBearColor : na, title="Bearish HVB")

// Calculate ADX, DI+,  DI-,RSI,ATR
[diplus, diminus, adx] = ta.dmi(adxLength, adxThreshold)
rsi=ta.rsi(close,rsiLength)
atrValue=ta.atr(atr)

// Check for oversold,Overbought condition
oversold_condition = rsi < 20
overbought_condition = rsi > 80

// Plot Trend Line
trendColor = ema5 > ema9 ? color.rgb(22, 203, 28) : ema5 < ema9 ? color.rgb(224, 15, 15) : na
plot(ShowAvg1? ema:na, color=trendColor, linewidth=6, title="Trend Line Upper Ribbon")

/////////////////////////plot ema,wma
plot(showLines1 ? ta.ema(close, ema200_length) : na, color=color.rgb(102, 110, 103), style=plot.style_line, title="ema1",linewidth = 4)
plot(showLines1 ? ta.ema(close, ema300_length) : na, color=color.rgb(18, 20, 18), style=plot.style_line, title="ema2",linewidth = 4)
plot(showLines1 ? ta.wma(close, wma60_length) : na, color=color.rgb(238, 75, 211), style=plot.style_line, title="wma60",linewidth = 3)

// Plot signals with smaller text
plotshape(oversold_condition ? 1 : na, title="RSI Oversold Signal", color=color.rgb(238, 8, 8), style=shape.labelup, location=location.belowbar, text="RSI OS", textcolor=color.rgb(17, 17, 17), size=size.tiny)
plotshape(overbought_condition ? 1 : na, title="RSI Overbought Signal", color=#08f710, style=shape.labeldown, location=location.abovebar, text="RSI OB", textcolor=color.rgb(8, 8, 8), size=size.tiny)
///////////////////////////////////////////////////////////////////////////////////////////////

// Define input options
showTable = input(false, title="Show Table ADX, RSI, DI values with RED, GREEN and YELLOW Signal")
tablePosition = input.string("Top Right", title="Table Position", options=["Top Right", "Top Left", "Top Center", "Bottom Right", "Bottom Left", "Bottom Center"])

// Define colors for the table cells
colorRsi = rsi > 55 ? color.green : rsi < 45 ? color.red : color.yellow
colorDiPlus = diplus > diThreshold ? color.green : color.red
colorDiMinus = diminus > diThreshold ? color.red : color.green
colorAdx = (rsi < 45 and diplus < diThreshold and diminus > diThreshold and adx > adxThreshold) ? color.red : 
           (rsi > 55 and diplus > diThreshold and diminus < diThreshold and adx > adxThreshold) ? color.green : 
           color.yellow

// Create the table
var table testTable = na
if showTable
    var position = tablePosition == "Top Right" ? position.top_right :
                   tablePosition == "Top Left" ? position.top_left :
                   tablePosition == "Top Center" ? position.top_center :
                   tablePosition == "Bottom Right" ? position.bottom_right :
                   tablePosition == "Bottom Left" ? position.bottom_left :
                   position.bottom_center

    testTable := table.new(position, columns = 4, rows = 2, border_width = 1, border_color = color.black, frame_width = 1, frame_color = color.black)

    // Column Headings
    table.cell(table_id = testTable, column = 0, row = 0, text = " DI+ ", bgcolor=color.aqua, text_color = color.white)
    table.cell(table_id = testTable, column = 1, row = 0, text = " DI- ", bgcolor=color.aqua, text_color = color.white)
    table.cell(table_id = testTable, column = 2, row = 0, text = " ADX ", bgcolor=color.aqua, text_color = color.white)
    table.cell(table_id = testTable, column = 3, row = 0, text = " RSI ", bgcolor=color.aqua, text_color = color.white)

    // Column values
    table.cell(table_id = testTable, column = 0, row = 1, text = str.tostring(math.round(diplus, 0)), bgcolor=colorDiPlus, text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 1, text = str.tostring(math.round(diminus, 0)), bgcolor=colorDiMinus, text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 1, text = str.tostring(math.round(adx, 0)), bgcolor=colorAdx, text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 1, text = str.tostring(math.round(rsi, 0)), bgcolor=colorRsi, text_color = color.black)


// Initialize variables to keep track of the previous condition
var bool prev_oversold = na
var bool prev_overbought = na

plotshape(ta.crossover(ema,wma60) and isHighVolume,  style=shape.labelup, location=location.belowbar, color=#1adaf3,size=size.small)
plotshape(ta.crossunder(ema,wma60) and isHighVolume,  style=shape.labeldown, location=location.abovebar, color=#f30aa9, size=size.small)
//////////////////////////////////////////////////   
plotFibRetracement = input.bool(title="Plot Fibonacci Retracement", defval=false)
fibLevel1 = input.float(title="Fibonacci Level", defval=0.5, minval=0, maxval=1, step=0.01)
fibLevel2 = input.float(title="Fibonacci Level", defval=0.618, minval=0, maxval=1, step=0.01)
fibLevel3 = input.float(title="Fibonacci Level", defval=0.368, minval=0, maxval=1, step=0.01) 
// Calculate Fibonacci Levels
highPrice = ta.highest(high, 100)
lowPrice = ta.lowest(low, 100)
priceRange = highPrice - lowPrice
fibonacciLevel1 = lowPrice + priceRange * fibLevel1
fibonacciLevel2 = lowPrice + priceRange * fibLevel2
fibonacciLevel3 = lowPrice + priceRange * fibLevel3

// Plot Fibonacci Levels
if plotFibRetracement
    line.new(x1=bar_index[1], y1=fibonacciLevel1, x2=bar_index, y2=fibonacciLevel1, color=color.blue, width=2)
    line.new(x1=bar_index[1], y1=fibonacciLevel2, x2=bar_index, y2=fibonacciLevel2, color=color.blue, width=2)
    line.new(x1=bar_index[1], y1=fibonacciLevel3, x2=bar_index, y2=fibonacciLevel3, color=color.blue, width=2)
// Draw Trendline
var float trendlineY1 = na
var float trendlineY2 = na

if bar_index % 50 == 0
    trendlineY1 := low
    trendlineY2 := high

// line.new(x1=bar_index, y1=trendlineY1, x2=bar_index - 100, y2=trendlineY2, color=#3708a5, width=2)

////////////////////////////////////////////////entry, exit, profit booking, stoploss///////////////////////
if (rsi > 63 and adx> adxThreshold and diplus>diThreshold)
    strategy.entry("Buy", strategy.long, qty = 1)

if (rsi < 40 and adx> adxThreshold and diminus>diThreshold)
    strategy.entry("Sell", strategy.short, qty = 1)

// Set stop loss and take profit levels
stop_loss = input(1.5, title = "Stop Loss (%)") * atrValue
take_profit = input(4.0, title = "Take Profit (%)") * atrValue
strategy.exit("Take Profit/Stop Loss", from_entry = "Buy", stop = close - stop_loss, limit = close + take_profit)
strategy.exit("Take Profit/Stop Loss", from_entry = "Sell", stop = close + stop_loss, limit = close - take_profit)
////////////////////////