PDIM
//==============================
// PDIM SMART TRADER PRO
// PART 2A - MARKET STRUCTURE
// BOS + CHoCH
//==============================
// Pivot Length
pivotLen = input.int(5, "Swing Length", minval = 2)
// Swing Detection
pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
// Store previous swing levels
var float lastHigh = na
var float lastLow = na
if not na(pivotHigh)
lastHigh := pivotHigh
if not na(pivotLow)
lastLow := pivotLow
// Break of Structure
bullBOS = not na(lastHigh) and ta.crossover(close, lastHigh)
bearBOS = not na(lastLow) and ta.crossunder(close, lastLow)
// Change of Character
bullCHoCH = bearTrend and bullBOS
bearCHoCH = bullTrend and bearBOS
// Labels
if bullBOS
label.new(bar_index, high,
"BOS",
style = label.style_label_up,
color = color.green,
textcolor = color.white)
if bearBOS
label.new(bar_index, low,
"BOS",
style = label.style_label_down,
color = color.red,
textcolor = color.white)
if bullCHoCH
label.new(bar_index, high,
"CHoCH",
style = label.style_label_up,
color = color.blue,
textcolor = color.white)
if bearCHoCH
label.new(bar_index, low,
"CHoCH",
style = label.style_label_down,
color = color.orange,
textcolor = color.white)
// Updated Buy/Sell Logic
buySignal :=
bullTrend and
bullBOS and
rsi > rsiBull
sellSignal :=
bearTrend and
bearBOS and
rsi < rsiBearish