커뮤니티

조건검색 문의

프로필 이미지
사공하늘
2025-11-07 14:11:36
164
글번호 227767
답변완료

//@version=5

indicator(title="Money Order Block with Bullish BOS Signals - Fixed", overlay=true, max_bars_back=5000)



// Input options

inputRange = input.int(25, "Candle Range", minval=5, maxval=100, step=1, group="BASIC SETTINGS")

bullishBreakerSource = input.source(close, title="Bullish Breaker Source")

bearishBreakerSource = input.source(close, title="Bearish Breaker Source")



// Signal display options

showBullishBOS = input.bool(true, "Show Bullish BOS Signals", group="Signal Settings")

bullishSignalColor = input.color(color.green, "Bullish Signal Color", group="Signal Settings")

showSignalLabels = input.bool(true, "Show Signal Labels", group="Signal Settings")



// optional displays

showPD = input.bool(false, "Show Previous Day High/Low", group="Extras")

showBearishBOS = input.bool(false, "Show Bearsish BOS Line", group="Extras")

showBreakerCandles = input.bool(false, "Highlight Breaker Candles", group="Extras")

showRetestCandles = input.bool(false, "Highlight Re-test Candles", group="Extras")

showTrendColours = input.bool(false, "Show Trend Colours", group="Extras")

useMitigatedBlocks = input.bool(false, "Show Mitigated Blocks", group="Extras")



// colours & styles

bearishOBColour = input.color(color.rgb(219, 166, 50, 80), title="Bearish Order Block Colour", group="STYLES")

bullishOBColour = input.color(color.rgb(192, 230, 174, 60), title="Bullish Order Block Colour", group="STYLES")

mitigatedOBColour = input.color(color.rgb(207, 203, 202, 80), title="Mitigated Order Block Colour", group="STYLES")

BOSCandleColour = input.color(color.yellow, title="Breaker Candle Colour", group="STYLES")

shortRetestCandleColour = input.color(color.purple, title="Short Re-Test Candle Colour", group="STYLES")

longRetestCandleColour = input.color(color.orange, title="Long Re-Test Candle Colour", group="STYLES")

bullishTrendColor = input.color(color.lime, title="Bullish Trend Colour", group="STYLES")

bearishTrendColour = input.color(color.red, title="Bearish Trend Colour", group="STYLES")



// Bullish BOS Signals

var bullishSignals = array.new_label()



// candle colouring

var int CandleColourMode = 0

var bool BosCandle = false

var bool bullishAlert = false

var bool bearishAlert = false

var bool shortRetestCandle = false

var bool longRetestCandle = false



// tracking for entries

var int lastDownIndex = 0

var float lastDown = 0

var float lastLow = 0



var int lastUpIndex = 0

var float lastUp = 0

var float lastUpLow = 0

var float lastUpOpen = 0

var float lastHigh = 0

var float lastBullBreakLow = 0



// structure

var int structureLowIndex = 0

float structureLow = 1000000



// order block drawing arrays

var longBoxes = array.new_box()

var longBoxStart = array.new_int()

var longBoxState = array.new_int()

var shortBoxes = array.new_box()

var shortBoxStart = array.new_int()

var shortBoxState = array.new_int()

var bosLines = array.new_line()



var int lastLongIndex = 0

var int lastShortIndex = 0



BosCandle := false

bullishAlert := false

bearishAlert := false

shortRetestCandle := false

longRetestCandle := false



// Previous Day High/Low - Improved for replay compatibility

var float PDH = na

var float PDL = na

var float dailyHigh = na

var float dailyLow = na



if ta.change(time("D"))

    PDH := dailyHigh

    PDL := dailyLow

    dailyHigh := high

    dailyLow := low

else

    dailyHigh := math.max(nz(dailyHigh), high)

    dailyLow := math.min(nz(dailyLow), low)



if (showPD)

    var line l_pdh = na, var line l_pdl = na, var label lbl_pdh = na, var label lbl_pdl = na

    if barstate.islast

        lbl_pdh := label.new(bar_index + 8, PDH, "PDH", style=label.style_label_left, textcolor=color.white)

        lbl_pdl := label.new(bar_index + 8, PDL, "PDL", style=label.style_label_left, textcolor=color.white)

        l_pdh := line.new(bar_index - 1, PDH, bar_index + 8, PDH, extend=extend.left, color=color.blue)

        l_pdl := line.new(bar_index - 1, PDL, bar_index + 8, PDL, extend=extend.left, color=color.blue)

    line.delete(l_pdh[1])

    line.delete(l_pdl[1])

    label.delete(lbl_pdh[1])

    label.delete(lbl_pdl[1])



// functions

structureLowIndexPointer(len) =>

    float minValue = ta.highest(high, inputRange)[1]

    int minIndex = bar_index

    for i = 1 to len

        if low[i] < minValue

            minValue := low[i]

            minIndex := bar_index[i]

    minIndex



withinBullishBlock(position) =>

    bool result = false

    if (array.size(longBoxes) > 0)

        for i = (array.size(longBoxes) - 1) to 0

            box = array.get(longBoxes, i)

            top = box.get_top(box)

            bottom = box.get_bottom(box)

            if (position < top and position > bottom)

                result := true

    result



// get the lowest point in the range

structureLow := ta.lowest(low, inputRange)[1]

structureLowIndex := structureLowIndexPointer(inputRange)



// bearish break of structure

if (ta.crossunder(bearishBreakerSource, structureLow))

    if ((bar_index - lastUpIndex) < 1000)

        array.push(shortBoxStart, bar_index)

        array.push(shortBoxState, 0)

        array.push(shortBoxes, box.new(left=lastUpIndex, top=lastHigh, bottom=lastUpLow, right=lastUpIndex, bgcolor=bearishOBColour, border_color=color.rgb(207, 203, 202, 100), extend=extend.right))

        if (showBearishBOS)

            array.push(bosLines, line.new(structureLowIndex, structureLow, bar_index, structureLow, color=color.red, style=line.style_solid, width=2))

        BosCandle := true

        CandleColourMode := 0

        lastShortIndex := lastUpIndex

        bearishAlert := true



// bullish break of structure - FIXED VERSION

if (array.size(shortBoxes) > 0)

    i = array.size(shortBoxes) - 1

    while i >= 0

        if i < array.size(shortBoxes)

            sbox = array.get(shortBoxes, i)

            lstart = array.get(shortBoxStart, i)

            lstate = array.get(shortBoxState, i)

            top = box.get_top(sbox)

            left = box.get_left(sbox)

            bottom = box.get_bottom(sbox)

           

            // re-test 확인

            if (high > bottom and low < bottom and bar_index > lstart and lstate == 0 and useMitigatedBlocks)

                sbox.set_bgcolor(mitigatedOBColour)

                shortRetestCandle := true

                array.set(shortBoxState, i, 1)

           

            // Bullish BOS 신호 - barstate.islast 제거

            if (bullishBreakerSource > top)

                // Bullish BOS Signal 표시 - 리플레이 호환

                if showBullishBOS

                    label.new(bar_index, low, "▲BOS", color=bullishSignalColor, style=label.style_label_up, textcolor=color.white, size=size.normal)

               

                bullishAlert := true

               

                // Bullish Order Block 생성

                if ((bar_index - lastDownIndex) < 1000 and bar_index > lastLongIndex)

                    array.push(longBoxStart, bar_index + 1)

                    array.push(longBoxState, 0)

                    array.push(longBoxes, box.new(left=lastDownIndex, top=lastDown, bottom=lastLow, right=lastDownIndex, bgcolor=bullishOBColour, border_color=color.rgb(207, 203, 202, 100), extend=extend.right))

                    if (showBullishBOS)

                        array.push(bosLines, line.new(left, top, bar_index, top, color=color.green, style=line.style_solid, width=1))

                    BosCandle := true

                    CandleColourMode := 1

                    lastLongIndex := bar_index

                    lastBullBreakLow := low

               

                // Bearish 박스 제거

                box.delete(sbox)

                array.remove(shortBoxState, i)

                array.remove(shortBoxes, i)

                array.remove(shortBoxStart, i)

        i := i - 1



// 알람 조건

alertcondition(bullishAlert, "Bullish break of structure", 'bullish break of structure was triggered')

alertcondition(bearishAlert, "Bearish break of structure", 'bearish break of structure was triggered')

alertcondition(shortRetestCandle, "Bearish order block re-tested", 'bearish order block has been re-tested')

alertcondition(longRetestCandle, "Bullish order block re-tested", 'bullish order block has been re-tested')



// update bullish order blocks

if (array.size(longBoxes) > 0)

    i = array.size(longBoxes) - 1

    while i >= 0

        if i < array.size(longBoxes)

            lbox = array.get(longBoxes, i)

            lstart = array.get(longBoxStart, i)

            lstate = array.get(longBoxState, i)

            bottom = box.get_bottom(lbox)

            top = box.get_top(lbox)

            boxLeft = box.get_left(lbox)

            if (low <= top and high > top and bar_index > lstart and lstate == 0)

                if (useMitigatedBlocks)

                    lbox.set_bgcolor(mitigatedOBColour)

                longRetestCandle := true

                array.set(longBoxState, i, 1)

            if (close < bottom)

                array.remove(longBoxStart, i)

                array.remove(longBoxState, i)

                array.remove(longBoxes, i)

                box.delete(lbox)

        i := i - 1



// 이전 신호 레이블 정리 (성능 최적화)

if barstate.islast and array.size(bullishSignals) > 0

    for i = 0 to array.size(bullishSignals) - 1

        if i < array.size(bullishSignals)

            label.delete(array.get(bullishSignals, i))



// candle colouring

CandleColour = CandleColourMode == 1 ? bullishTrendColor : bearishTrendColour

CandleColour := BosCandle and showBreakerCandles ? BOSCandleColour : CandleColour

CandleColour := shortRetestCandle and showRetestCandles ? shortRetestCandleColour : CandleColour

CandleColour := longRetestCandle and showRetestCandles ? longRetestCandleColour : CandleColour

barcolor(showTrendColours ? CandleColour : na)

barcolor(showBreakerCandles and BosCandle ? CandleColour : na)



// record last up and down candles

if (close < open)

    lastDown := high

    lastDownIndex := bar_index

    lastLow := low



if (close > open)

    lastUp := close

    lastUpIndex := bar_index

    lastUpOpen := open

    lastUpLow := low

    lastHigh := high



// update last high/low

lastHigh := high > lastHigh ? high : lastHigh

lastLow := low < lastLow ? low : lastLow



// 디버깅용 플롯 (필요시 주석 해제)

// plotshape(bullishAlert, "Bullish Alert", shape.triangleup, location.belowbar, color.green, size=size.small)

// plotshape(array.size(shortBoxes) > 0, "Short Boxes Exist", shape.circle, location.abovebar, color.red, size=size.tiny)



여기서 다른 것들 제외하구, 일봉상 'bos'신호가 나오는 종목에 대한 검색식을 구현시켜주시면 감사드리겠습니다 (__)

감사합니다 늘 (__)

검색
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-11-10 09:31:49

안녕하세요 예스스탁입니다. 올려주신 내용은 작성해 보는데 시간이 많이 요구되어 답변이 어렵습니다. 업무상 일정이상 시간이 요구되는 내용은 저희가 작성을 해드리지 않습니다. 도움을 드리지 못해 죄송합니다. 즐거운 하루되세요