OPEN-SOURCE SCRIPT

Support and Resistance

//version=5
indicator("Fair Value Gaps and Order Blocks", overlay=true)

// Input parameters
fvgLookback = input.int(3, title="FVG Lookback (Candles)", minval=1)
obLookback = input.int(5, title="Order Block Lookback (Candles)", minval=1)
fvgColor = input.color(color.new(color.teal, 80), title="FVG Color")
obBullishColor = input.color(color.new(color.green, 80), title="Bullish OB Color")
obBearishColor = input.color(color.new(color.red, 80), title="Bearish OB Color")

// Fair Value Gap (FVG) Detection
fvgUp = (high[2] < low[1]) and (low[2] < low[1]) // Bullish FVG condition
fvgDown = (low[2] > high[1]) and (high[2] > high[1]) // Bearish FVG condition

// Plot FVG
if (fvgUp)
label.new(bar_index[1], na, text="FVG", style=label.style_circle, color=fvgColor, textcolor=color.white, size=size.small)
if (fvgDown)
label.new(bar_index[1], na, text="FVG", style=label.style_circle, color=fvgColor, textcolor=color.white, size=size.small)

// Order Block (OB) Detection
isBullishOB = (close[1] > open[1]) and (close[1] > close[obLookback]) and (open[1] < close[obLookback]) // Bullish OB condition
isBearishOB = (close[1] < open[1]) and (close[1] < close[obLookback]) and (open[1] > close[obLookback]) // Bearish OB condition

// Plot Order Blocks
if (isBullishOB)
box.new(left=bar_index[1], right=bar_index, top=high[1], bottom=low[1], bgcolor=obBullishColor, border_color=color.green, border_width=1)
if (isBearishOB)
box.new(left=bar_index[1], right=bar_index, top=high[1], bottom=low[1], bgcolor=obBearishColor, border_color=color.red, border_width=1)

Aviso legal