주문 블록 모멘텀 브레이크업 전략

저자:차오장, 날짜: 2024-02-26 11:54:02
태그:

img

전반적인 설명

이 전략은 추진력 폭발을 찾아내기 위해 가격 행동에서 주문 블록을 식별하고 구매/판매 신호가 나타날 때 시장에 진출합니다. 주문 블록은 제도적 참여와 중요한 시장 세력을 나타냅니다. 따라서 주문 블록 신호는 트렌딩 가격 행동으로 이어질 확률이 높습니다.

전략 논리

순서 블록을 식별

오더 블록에는 두 가지 유형이 있습니다. 상승 및 하락. 상승 오더 블록은 마지막 빨간 촛불이 연속된 녹색 촛불이 따라가는 것으로 정의됩니다. 하락 오더 블록은 마지막 녹색 촛불이 연속된 빨간 촛불이 따라가는 것으로 정의됩니다.

명령 블록을 식별하려면 다음 기준이 동시에 충족되어야 합니다.

  1. 촛불 색의 변화 - 촛불의 색은 이전 촛불에서 현재 촛불으로 변경됩니다 (예를 들어 빨간색에서 녹색으로, 또는 녹색에서 빨간색으로). 이것은 기관이 이전 트렌드를 종료하고 새로운 잠재적 트렌드를 시작할 수 있음을 시사합니다.

  2. 이후 일관된 방향 - 다음 촛불은 매개 변수에서 지정된 기간 동안 동일한 색상 방향을 유지합니다 (예: 잠재적 인 상승 블록 후 모든 녹색 촛불). 이것은 새로운 경향을 확인합니다.

  3. 브레이크아웃이 임계치를 초과합니다. 주문 블록 촛불의 오픈에서 최종 확인 촛불의 종료까지의 비율 가격 변화는 임계 매개 변수를 초과합니다. 이것은 충분히 강한 추진력을 보장합니다.

이 세 가지 기준이 모두 사실이라면, 명령 블록 신호가 확인됩니다.

거래 신호 생성

바이 신호는 상승 오더 블록을 감지 할 때 생성됩니다. 판매 신호는 하락 오더 블록이 식별 될 때 나타납니다.

주문 흐름 신호의 불확실성을 고려할 때, 전략은 즉시 시장에 진출하지 않습니다. 거래자를 경고하고 가격 제한 주문을 주문 블록 수준 근처에 배치 할 수 있습니다. 이것은 통제 된 입출과 리스크 관리를 제공합니다.

장점

숨겨진 모멘텀을 캡처합니다.

오더 블록은 제도적 금전 흐름과 상당한 양을 나타냅니다. 그들은 시장 힘의 변화를 나타내고 잠재적 인 브레이크오웃 방향에 대한 초기 단서를 제공합니다. 이것은 적절한 타이밍으로 트렌드를 따르는 것을 촉진합니다.

사용자 정의 가능한 매개 변수

촛불 수, 브레이크아웃 비율 등을 제어하는 매개 변수는 변화하는 시장 조건과 거래 스타일에 최적화하도록 조정할 수 있습니다. 이것은 적응력을 향상시킵니다.

통제된 위험

신호를 자동으로 입력하지 않고 제한 주문을 사용함으로써 거래자는 입력 수준을 정의하고 위험을 제어 할 수 있습니다. 실패한 신호는 단순히 채우지 않은 제한 주문으로 이어집니다. 위험은 포함됩니다.

위험성

재검사 가능성은 높습니다

오더 블록은 구역을 의미하기 때문에 가격을 재검토하는 것이 일반적입니다. 신호는 직접 엔트리로 간주되어서는 안됩니다. 추가 타이밍 판단이 필요합니다.

매개 변수 오작동은 나쁜 신호를 유발합니다.

매개 변수들이 제대로 설정되지 않으면, 범위에 묶인 시장에서 가짜 신호가 나타날 수 있다. 거래자는 신호를 적용함에 있어 신중을 기해야 한다. 맹목적 최적화를 피해야 한다.

수동 검토가 필요합니다.

추가 검증이 필요한 각 신호에 상당한 수동 노력이 포함됩니다. 신호 품질에 대한 인간의 판단의 불일치로 인해 성능의 차이가 발생할 수 있습니다.

더 나은 기회

다른 표시로 신호 필터링

시그널이 시장 조건을 측정하는 것처럼 보일 때 MACD 및 RSI와 같은 추가 지표를 포함하십시오. 이것은 잘못된 매개 변수 설정에서 나쁜 신호를 필터합니다.

매개 변수 최적화

매개 변수는 테스트되고 더 잘 적합하도록 다른 시장과 도구에 맞게 조정 할 수 있습니다. 변동성과 위험 관용에 따라 자동 조정 할 수 있는 적응 설정도 구현할 수 있습니다.

자동 출입/출입

현재 전략은 신호 알림으로만 사용됩니다. 신호에 대한 제한 순서 입력을 자동화하고 출구에 대한 정지를 구현하기 위해 논리를 추가 할 수 있습니다. 이것은 자동화를 증가시키고 인간의 판단에 대한 의존도를 감소시킵니다.

결론

이 전략은 순서 흐름 컨버전스를 탐지함으로써 표면 아래의 숨겨진 모멘텀 움직임을 드러낸다. 단순한 트렌드 추종과 비교하면 전환점을 찾아내는 예측 능력을 갖는다. 최적화 및 위험 통제 기술과 결합하면 효과적인 트렌드 거래 시스템으로 변할 수 있다. 그럼에도 불구하고, 거래자는 나쁜 신호에 대해 경계하고 각 신호의 품질을 평가해야 한다. 추가 노력은 주관적 재량에서 인한 편견을 최소화하기 위해 자동화를 강화하는 데 집중해야 한다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © TradingSecrets and wugamlo


// This experimental Indicator helps identifying instituational Order Blocks. 
// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again. 
// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB). 
//
// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
//
// In the settings the number of required sequential candles can be adjusted. 
// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block. 
// Channels for the last Bullish/Bearish Block can be shown/hidden.
//
// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
//
// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the 
// number of consecutive candles is reached.



//@version=4
strategy("[Backtest] Order Block Finder", overlay = true)               

colors    = input(title = "Color Scheme", defval="DARK", options=["DARK", "BRIGHT"])
periods   = input(5,     "Relevant Periods to identify OB")                // Required number of subsequent candles in the same direction to identify Order Block
threshold = input(0.0,   "Min. Percent move to identify OB", step = 0.1)   // Required minimum % move (from potential OB close to last subsequent candle to identify Order Block)
usewicks  = input(false, "Use whole range [High/Low] for OB marking?" )    // Display High/Low range for each OB instead of Open/Low for Bullish / Open/High for Bearish
showbull  = input(false,  "Show latest Bullish Channel?")                   // Show Channel for latest Bullish OB?
showbear  = input(false,  "Show latest Bearish Channel?")                   // Show Channel for latest Bearish OB?
showdocu  = input(false, "Show Label for documentation tooltip?")          // Show Label which shows documentation as tooltip?
info_pan  = input(false, "Show Latest OB Panel?")                          // Show Info Panel with latest OB Stats
//strategy inputs
plot_offset = input( type=input.bool,defval = false, title = 'Plot Offset?')
stoploss_percent = input(type=input.float, defval = 1, title = 'Stop Loss [%]')
takeprofit_percent = input(type=input.float, defval = 2, title = 'Take Profit [%]')
pyramiding = input( type=input.bool,defval = true, title = 'Pyramiding')

ob_period = periods + 1                                                    // Identify location of relevant Order Block candle
absmove   = ((abs(close[ob_period] - close[1]))/close[ob_period]) * 100    // Calculate absolute percent move from potential OB to last candle of subsequent candles
relmove   = absmove >= threshold                                           // Identify "Relevant move" by comparing the absolute move to the threshold

// Color Scheme
bullcolor = colors == "DARK"? color.white : color.green
bearcolor = colors == "DARK"? color.blue : color.red

// Bullish Order Block Identification
bullishOB = close[ob_period] < open[ob_period]                             // Determine potential Bullish OB candle (red candle)

int upcandles  = 0
for i = 1 to periods
    upcandles := upcandles + (close[i] > open[i]? 1 : 0)                   // Determine color of subsequent candles (must all be green to identify a valid Bearish OB)

OB_bull      = bullishOB and (upcandles == (periods)) and relmove          // Identification logic (red OB candle & subsequent green candles)
OB_bull_high = OB_bull? usewicks? high[ob_period] : open[ob_period] : na   // Determine OB upper limit (Open or High depending on input)
OB_bull_low  = OB_bull? low[ob_period]  : na                               // Determine OB lower limit (Low)
OB_bull_avg  = (OB_bull_high + OB_bull_low)/2                              // Determine OB middle line


// Bearish Order Block Identification
bearishOB = close[ob_period] > open[ob_period]                             // Determine potential Bearish OB candle (green candle)

int downcandles  = 0
for i = 1 to periods
    downcandles := downcandles + (close[i] < open[i]? 1 : 0)               // Determine color of subsequent candles (must all be red to identify a valid Bearish OB)

OB_bear      = bearishOB and (downcandles == (periods)) and relmove        // Identification logic (green OB candle & subsequent green candles)
OB_bear_high = OB_bear? high[ob_period] : na                               // Determine OB upper limit (High)
OB_bear_low  = OB_bear? usewicks? low[ob_period] : open[ob_period] : na    // Determine OB lower limit (Open or Low depending on input)
OB_bear_avg  = (OB_bear_low + OB_bear_high)/2                              // Determine OB middle line

//@TradingSecrets: Option to disable the offset in order to allign signals with Backtest
if not plot_offset
    ob_period := 0
// Plotting
plotshape(OB_bull, title="Bullish OB", style = shape.triangleup,   color = bullcolor, textcolor = bullcolor, size = size.tiny, location = location.belowbar, offset = -ob_period, text = "Bullish OB")     // Bullish OB Indicator
bull1 = plot(OB_bull_high, title="Bullish OB High", style = plot.style_linebr, color = bullcolor, offset = -ob_period, linewidth = 3)                                               // Bullish OB Upper Limit
bull2 = plot(OB_bull_low,  title="Bullish OB Low",  style = plot.style_linebr, color = bullcolor, offset = -ob_period, linewidth = 3)                                               // Bullish OB Lower Limit
fill(bull1, bull2, color=bullcolor, transp = 0, title = "Bullish OB fill")                                                                                                          // Fill Bullish OB
plotshape(OB_bull_avg, title="Bullish OB Average", style = shape.cross,   color = bullcolor, size = size.normal, location = location.absolute, offset = -ob_period)                 // Bullish OB Average


plotshape(OB_bear, title="Bearish OB", style = shape.triangledown, color = bearcolor, textcolor = bearcolor,  size = size.tiny, location = location.abovebar, offset = -ob_period, text = "Bearish OB")     // Bearish OB Indicator
bear1 = plot(OB_bear_low,  title="Bearish OB Low",  style = plot.style_linebr, color = bearcolor, offset = -ob_period, linewidth = 3)                                                // Bearish OB Lower Limit
bear2 = plot(OB_bear_high, title="Bearish OB High", style = plot.style_linebr, color = bearcolor, offset = -ob_period, linewidth = 3)                                                // Bearish OB Upper Limit
fill(bear1, bear2, color=bearcolor, transp = 0, title = "Bearish OB fill")                                                                                                           // Fill Bearish OB
plotshape(OB_bear_avg, title="Bearish OB Average", style = shape.cross,   color = bearcolor, size = size.normal, location = location.absolute, offset = -ob_period)                  // Bullish OB Average

var line linebull1 = na       // Bullish OB average 
var line linebull2 = na       // Bullish OB open
var line linebull3 = na       // Bullish OB low
var line linebear1 = na       // Bearish OB average
var line linebear2 = na       // Bearish OB high
var line linebear3 = na       // Bearish OB open


if OB_bull and showbull
    line.delete(linebull1)
    linebull1 := line.new(x1 = bar_index, y1 = OB_bull_avg, x2 = bar_index - 1, y2 = OB_bull_avg, extend = extend.left, color = bullcolor, style = line.style_solid, width = 1)
    
    line.delete(linebull2)
    linebull2 := line.new(x1 = bar_index, y1 = OB_bull_high, x2 = bar_index - 1, y2 = OB_bull_high, extend = extend.left, color = bullcolor, style = line.style_dashed, width = 1)
    
    line.delete(linebull3)
    linebull3 := line.new(x1 = bar_index, y1 = OB_bull_low, x2 = bar_index - 1, y2 = OB_bull_low, extend = extend.left, color = bullcolor, style = line.style_dashed, width = 1)

if OB_bear and showbear
    line.delete(linebear1)
    linebear1 := line.new(x1 = bar_index, y1 = OB_bear_avg, x2 = bar_index - 1, y2 = OB_bear_avg, extend = extend.left, color = bearcolor,  style = line.style_solid, width = 1)
    
    line.delete(linebear2)
    linebear2 := line.new(x1 = bar_index, y1 = OB_bear_high, x2 = bar_index - 1, y2 = OB_bear_high, extend = extend.left, color = bearcolor,  style = line.style_dashed, width = 1)
    
    line.delete(linebear3)
    linebear3 := line.new(x1 = bar_index, y1 = OB_bear_low, x2 = bar_index - 1, y2 = OB_bear_low, extend = extend.left, color = bearcolor,  style = line.style_dashed, width = 1)


// Alerts for Order Blocks Detection

alertcondition(OB_bull, title='New Bullish OB detected', message='New Bullish OB detected - This is NOT a BUY signal!')
alertcondition(OB_bear, title='New Bearish OB detected', message='New Bearish OB detected - This is NOT a SELL signal!')

// Print latest Order Blocks in Data Window

var latest_bull_high = 0.0         // Variable to keep latest Bull OB high
var latest_bull_avg  = 0.0         // Variable to keep latest Bull OB average
var latest_bull_low  = 0.0         // Variable to keep latest Bull OB low
var latest_bear_high = 0.0         // Variable to keep latest Bear OB high
var latest_bear_avg  = 0.0         // Variable to keep latest Bear OB average
var latest_bear_low  = 0.0         // Variable to keep latest Bear OB low

// Assign latest values to variables
if OB_bull_high > 0
    latest_bull_high := OB_bull_high

if OB_bull_avg > 0
    latest_bull_avg := OB_bull_avg

if OB_bull_low > 0
    latest_bull_low := OB_bull_low

if OB_bear_high > 0
    latest_bear_high := OB_bear_high
    
if OB_bear_avg > 0
    latest_bear_avg := OB_bear_avg
    
if OB_bear_low > 0
    latest_bear_low := OB_bear_low

// Plot invisible characters to be able to show the values in the Data Window
plotchar(latest_bull_high, char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bull High")
plotchar(latest_bull_avg,  char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bull Avg")
plotchar(latest_bull_low,  char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bull Low")
plotchar(latest_bear_high, char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bear High")
plotchar(latest_bear_avg,  char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bear Avg")
plotchar(latest_bear_low,  char = ' ', location = location.abovebar, color = #777777, transp = 100, size = size.tiny, title = "Latest Bear Low")


//InfoPanel for latest Order Blocks

draw_InfoPanel(_text, _x, _y, font_size)=>
    var label la_panel = na
    label.delete(la_panel)
    la_panel := label.new(
         x=_x, y=_y, 
         text=_text, xloc=xloc.bar_time, yloc=yloc.price, 
         color=color.new(#383838, 5), style=label.style_label_left, textcolor=color.white, size=font_size)

info_panel_x = time_close + round(change(time) * 100)
info_panel_y = close

title = "LATEST ORDER BLOCKS"
row0 = "-----------------------------------------------------"
row1 = ' Bullish - High: ' + tostring(latest_bull_high, '#.##')
row2 = ' Bullish - Avg: ' + tostring(latest_bull_avg, '#.##')
row3 = ' Bullish - Low: ' + tostring(latest_bull_low, '#.##')
row4 = "-----------------------------------------------------"
row5 = ' Bearish - High: ' + tostring(latest_bear_high, '#.##')
row6 = ' Bearish - Avg: ' + tostring(latest_bear_avg, '#.##')
row7 = ' Bearish - Low: ' + tostring(latest_bear_low, '#.##')

panel_text = '\n' + title + '\n' + row0 + '\n' + row1 + '\n' + row2 + '\n' + row3 + '\n' + row4 + '\n\n' + row5 + '\n' + row6 + '\n' + row7 + '\n'

if info_pan
    draw_InfoPanel(panel_text, info_panel_x, info_panel_y, size.normal)


// === Label for Documentation/Tooltip ===
chper = time - time[1]
chper := change(chper) > 0 ? chper[1] : chper

// === Tooltip text ===

var vartooltip = "Indicator to help identifying instituational Order Blocks. Often these blocks signal the beginning of a strong move, but there is a high probability, that these prices will be revisited at a later point in time again and therefore are interesting levels to place limit orders. \nBullish Order block is the last down candle before a sequence of up candles. \nBearish Order Block is the last up candle before a sequence of down candles. \nIn the settings the number of required sequential candles can be adjusted. \nFurthermore a %-threshold can be entered which the sequential move needs to achieve in order to validate a relevant Order Block. \nChannels for the last Bullish/Bearish Block can be shown/hidden."

// === Print Label ===
var label l_docu = na
label.delete(l_docu)

if showdocu
    l_docu := label.new(x = time + chper * 35, y = close, text = "DOCU OB", color=color.gray, textcolor=color.white, style=label.style_label_center, xloc = xloc.bar_time, yloc=yloc.price, size=size.tiny, textalign = text.align_left, tooltip = vartooltip)

// @TradingSecrets: Generate entry and exit orders based on the signals
entryLongSignal = OB_bull
entryShortSignal = OB_bear

if not pyramiding
    entryLongSignal := entryLongSignal and not strategy.position_size
    entryShortSignal := entryShortSignal and not strategy.position_size
if entryLongSignal
    strategy.entry("Long Entry", strategy.long)
    //strategy.exit("Long Exit Loss", "Long Entry", stop = close * (1 - stoploss_percent*0.01))

if entryShortSignal
    strategy.entry("Short Entry", strategy.short)
    //strategy.exit("Short Exit Loss", "Short Entry", stop = close * (1 + stoploss_percent*0.01))
strategy.initial_capital = 50000        
//Close Position by market order
if strategy.position_size > 0 and strategy.openprofit/nz(strategy.initial_capital + strategy.netprofit) >= takeprofit_percent*0.01
    //If I m in a long position and my take profit got hit close it by market order
    strategy.close("Long Entry", comment = "Long Exit Profit")
if strategy.position_size < 0 and strategy.openprofit/nz(strategy.initial_capital + strategy.netprofit) >= takeprofit_percent*0.01
    strategy.close("Short Entry", comment = "Short Exit Profit")

if strategy.position_size > 0 and strategy.openprofit/nz(strategy.initial_capital + strategy.netprofit) <= -stoploss_percent*0.01
    //If I m in a long position and my take profit got hit close it by market order
    strategy.close("Long Entry", comment = "Long Exit Loss")
if strategy.position_size < 0 and strategy.openprofit/nz(strategy.initial_capital + strategy.netprofit) <= -stoploss_percent*0.01
    strategy.close("Short Entry", comment = "Short Exit Loss")

더 많은