This indicator presents an alternative approach to identify Market Structure. The logic used is derived from learning material created by @DaveTeachesWhen quantifying Market Structure, it is common to use fractal highs and lows to identify \'significant\' swing pivots. When price closes through these pivots, we may identify a Market Structure Shift (MSS) for reversals or a Break of Structure (BOS) for continuations. The main difference with this \'protected\' logic is in how we determine the pivots/levels that are utilized to determine a valid MSS or BOS.Nonetheless, the significance of our swing pivots is still governed by the input Pivot Strength parameter, which requires valid swing pivots to be compared to this many bars to the left and right of them. This is an optional parameter as it is traditionally set to 1 by default.
bull if close < p.price and p.valid == false p.valid := true else if close > p.price and p.valid == false p.valid := true check_pb(pb_from_high) check_pb(pb_from_low) if (high[ps] > track_high or na(track_high) or last_low_idx >= track_high_idx) and not na(ta.pivothigh(high, ps, ps)) and (use_valid_pbs ? pb_from_low.valid == true : true) track_high := high[ps] track_high_idx := bar_index ps if (low[ps] < track_low or na(track_low) or last_high_idx >= track_low_idx) and not na(ta.pivotlow(low, ps, ps)) and (use_valid_pbs ? pb_from_high.valid == true : true) track_low := low[ps] track_low_idx := bar_index ps bos_bear = false bos_bull = false mss_bear = false mss_bull = false change = false var dwgs = dwg.new(array.new_label(), array.new_label(), array.new_line(), array.new_bool()) var snd = snd.new() maintain(snd s) =>
id: f9ac65e8469854ca248404fc49ca3106 - page: 4
_box) s._box.set_right(time) s._30.set_x2(time) s._50.set_x2(time) s._70.set_x2(time) maintain(snd) if ph.size() > 0 if close > ph.get(0) label _label = na label _phl = na if show_labels save = false if label_type == 'MSS' and not bull save := true else if label_type == 'BOS' and bull save := true else if label_type == 'All' save := true if save _label := label.new(math.floor(math.avg(time, pht.get(0))), ph.get(0), bull ? "BOS" : "MSS", xloc = xloc.bar_time, style = label.style_label_down, color = #ffffff00, textcolor = na) if bull bos_bull := true else mss_bull := true if show_rets and (use_valid_pbs ? pb_from_high.valid == true : true) snd.snd_add(ph.get(0), track_low, true) _line = line.new(pht.get(0), ph.get(0), time, ph.get(0), color = na, xloc = xloc.bar_time, style = line.style_dashed) bull := true change := true clear_all() if not na(track_low)
id: 1dfb8072ca8ebd6c16adf427192a6a43 - page: 5
new(time[bar_index track_low_idx], track_low, "", xloc = xloc.bar_time, style = label.style_label_up, textcolor = na, color = #ffffff00) pl.unshift(track_low) plt.unshift(time[bar_index track_low_idx]) last_high := na dwgs.dwg_add(_label, _phl, _line, bull) if pl.size() > 0 if close < pl.get(0) label _label = na label _phl = na if show_labels save = false if label_type == 'MSS' and bull save := true else if label_type == 'BOS' and not bull save := true else if label_type == 'All' save := true if save _label := label.new(math.floor(math.avg(time, plt.get(0))), pl.get(0), not bull ? "BOS" : "MSS", xloc = xloc.bar_time, style = label.style_label_up, color = #ffffff00, textcolor = na) if not bull bos_bear := true else mss_bear := true if show_rets and (use_valid_pbs ? pb_from_low.valid == true : true)
id: 95e8c98ee271ed61c7a1af88c832474d - page: 6
snd_add(pl.get(0), track_high, false) _line = line.new(plt.get(0), pl.get(0), time, pl.get(0), color = na, xloc = xloc.bar_time, style = line.style_dashed) bull := false change := true clear_all() if not na(track_high) if show_phl _phl := label.new(time[bar_index track_high_idx], track_high, "", xloc = xloc.bar_time, style = label.style_label_down, textcolor = na, color = #ffffff00) ph.unshift(track_high) pht.unshift(time[bar_index track_high_idx]) last_low := na dwgs.dwg_add(_label, _phl, _line, bull) if change if bos_bear or mss_bear trail_price := track_high trail_color := ph_color else if bos_bull or mss_bull trail_price := track_low trail_color := pl_color _bull = dwgs._bull.get(0) dwgs._label.get(0).set_textcolor(_bull ? bull_color : bear_color) dwgs._phl.get(0).set_textcolor(_bull ? pl_color : ph_color) dwgs._line.get(0).set_color(_bull ? bull_color : bear_color)
id: 0eb43c223a73711445d23a642695d72f - page: 6