OPEN-SOURCE SCRIPT

Order Block Finder

209
//version=5
indicator("Order Block Finder", overlay=true)

// Input settings
blockLookback = input(20, title="Lookback Period")
minBlockSize = input(5, title="Minimum Block Size (Pips)") * syminfo.mintick
maxBlockAge = input(50, title="Maximum Block Age (Bars)")
combineCloseBlocks = input(true, title="Combine Close Blocks")

topSwingHigh = ta.highest(high, blockLookback)
topSwingLow = ta.lowest(low, blockLookback)

// Identifying Order Blocks
bullishBlock = ta.crossover(close, topSwingLow)
bearishBlock = ta.crossunder(close, topSwingHigh)

var float blockHigh = na
var float blockLow = na
var int blockAge = 0

if bullishBlock
blockHigh := high
blockLow := low
blockAge := 0

if bearishBlock
blockHigh := high
blockLow := low
blockAge := 0

blockAge := blockAge + 1
validBlock = blockAge < maxBlockAge

// Display Order Blocks
blockColor = bullishBlock ? color.green : bearishBlock ? color.red : na
if validBlock and not na(blockHigh) and not na(blockLow)
bgColor = color.new(blockColor, 80)
box.new(left=bar_index, right=bar_index + maxBlockAge, top=blockHigh, bottom=blockLow, border_color=blockColor, bgcolor=bgColor)

// Display Block Information Label
if validBlock
label.new(x=bar_index, y=blockHigh, text="Order Block", color=blockColor, textcolor=color.white, style=label.style_label_down)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.