답변완료
조건검색 문의
//@version=5indicator(title="Money Order Block with Bullish BOS Signals - Fixed", overlay=true, max_bars_back=5000)// Input optionsinputRange = 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 optionsshowBullishBOS = 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 displaysshowPD = 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 & stylesbearishOBColour = 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 Signalsvar bullishSignals = array.new_label()// candle colouringvar int CandleColourMode = 0var bool BosCandle = falsevar bool bullishAlert = falsevar bool bearishAlert = falsevar bool shortRetestCandle = falsevar bool longRetestCandle = false// tracking for entriesvar int lastDownIndex = 0var float lastDown = 0var float lastLow = 0var int lastUpIndex = 0var float lastUp = 0var float lastUpLow = 0var float lastUpOpen = 0var float lastHigh = 0var float lastBullBreakLow = 0// structurevar int structureLowIndex = 0float structureLow = 1000000// order block drawing arraysvar 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 = 0var int lastShortIndex = 0BosCandle := falsebullishAlert := falsebearishAlert := falseshortRetestCandle := falselongRetestCandle := false// Previous Day High/Low - Improved for replay compatibilityvar float PDH = navar float PDL = navar float dailyHigh = navar float dailyLow = naif ta.change(time("D")) PDH := dailyHigh PDL := dailyLow dailyHigh := high dailyLow := lowelse 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])// functionsstructureLowIndexPointer(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] minIndexwithinBullishBlock(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 rangestructureLow := ta.lowest(low, inputRange)[1]structureLowIndex := structureLowIndexPointer(inputRange)// bearish break of structureif (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 VERSIONif (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 blocksif (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 colouringCandleColour = CandleColourMode == 1 ? bullishTrendColor : bearishTrendColourCandleColour := BosCandle and showBreakerCandles ? BOSCandleColour : CandleColourCandleColour := shortRetestCandle and showRetestCandles ? shortRetestCandleColour : CandleColourCandleColour := longRetestCandle and showRetestCandles ? longRetestCandleColour : CandleColourbarcolor(showTrendColours ? CandleColour : na)barcolor(showBreakerCandles and BosCandle ? CandleColour : na)// record last up and down candlesif (close < open) lastDown := high lastDownIndex := bar_index lastLow := lowif (close > open) lastUp := close lastUpIndex := bar_index lastUpOpen := open lastUpLow := low lastHigh := high// update last high/lowlastHigh := high > lastHigh ? high : lastHighlastLow := 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'신호가 나오는 종목에 대한 검색식을 구현시켜주시면 감사드리겠습니다 (__) 감사합니다 늘 (__)