//@version=4
study("OB by SB", overlay=true)

//Inputs
highBarNext = high
lowBarNext = low
highBarPrevious = high
lowBarPrevious = low
openBarPrevious = open
closeBarPrevious = close
openBarCurrent = open
closeBarCurrent = close
int offset = 2
bar_index_ = bar_index
//bearCandlecolor = input(defval=#a86161, title="Bearish OB Candle", type=input.color, inline='customcolor', group="Chart Customization Candles")
//bullcandlecolor = input(defval=#004d40, title="Bullish OB Candle", type=input.color, inline='customcolor', group="Chart Customization Candles")
//adtranspCandle = input(defval=65, title="Candle Transparency", type=input.integer, minval=1, maxval=100, group="Chart Customization Candles")
bearboxcolor = input(defval=#a86161, title="Bearish OB Box", type=input.color, inline='customcolor', group="Chart Customization Box")
bullboxcolor = input(defval=#004d40, title="Bullish OB Box", type=input.color, inline='customcolor', group="Chart Customization Box")
showOBboxes = input(true, title="Show OB Boxes",group="Chart Customization Box")
adtransp = input(defval=90, title="Box Transparency", type=input.integer, minval=1, maxval=100, group="Chart Customization Box")
adboxcount = input(defval=10, title="Maximum Box Displayed", type=input.integer, minval=1, maxval=200, group="Chart Customization")



//If the Candle in index of 1 (the candle being detected as engulfing and imbalanced) and the next candle does not fill the imbalance, then a signal is generated.
bullishEngulfing = openBarCurrent <= closeBarPrevious and openBarCurrent < openBarPrevious and
closeBarCurrent > openBarPrevious and lowBarNext > highBarPrevious
bearishEngulfing = openBarCurrent >= closeBarPrevious and openBarCurrent > openBarPrevious and
closeBarCurrent < openBarPrevious and highBarNext < lowBarPrevious

//Plot OB Candles
//barcolor(bullishEngulfing? color.new(bullcandlecolor,adtranspCandle) : na, offset=-2)
//barcolor(bearishEngulfing? color.new(bearCandlecolor,adtranspCandle) : na, offset=-2)


//Box Variables
var box bearboxarray = array.new_box()
var box bullboxarray = array.new_box()

//Box Color Variables
var color adbearboxcolor = color.new(bearboxcolor, adtransp)
var color adbullboxcolor = color.new(bullboxcolor, adtransp)
var color adbearborderboxcolor = color.new(bearboxcolor, adtransp)
var color adbullborderboxcolor = color.new(bullboxcolor, adtransp)

//Bearish OB Box Calculation
f_choppedoffbear(bearboxarray) =>
if (array.size(bearboxarray) > 0)
for i = array.size(bearboxarray) - 1 to 0
cutbox = array.get(bearboxarray, i)
boxlowzone = box.get_bottom(cutbox)
boxhighzone = box.get_top(cutbox)
boxrightzone = box.get_right(cutbox)
if (na or (bar_index - 1 == boxrightzone and not ((high > boxlowzone and low < boxlowzone) or (high > boxhighzone and low < boxhighzone))))
box.set_right(array.get(bearboxarray, i), bar_index)

//Bearish OB Box Plotting
if (bearishEngulfing and showOBboxes)
boxhighzone = high > high ? high : high
boxlowzone = open
bearbox = box.new(bar_index_, boxhighzone, bar_index, boxlowzone, border_color=adbearborderboxcolor, border_style=line.style_dashed, bgcolor=adbearboxcolor)
if (array.size(bearboxarray) > adboxcount)
box.delete(array.shift(bearboxarray))
array.push(bearboxarray, bearbox)

f_choppedoffbear(bearboxarray)

//Bullish OB Box Calculation

f_choppedoffbull(bullboxarray) =>
if (array.size(bullboxarray) > 0)
for i = array.size(bullboxarray) - 1 to 0
cutbox = array.get(bullboxarray, i)
boxlowzone = box.get_bottom(cutbox)
boxhighzone = box.get_top(cutbox)
boxrightzone = box.get_right(cutbox)
if (na or (bar_index - 1 == boxrightzone and not ((high > boxlowzone and low < boxlowzone) or (high > boxhighzone and low < boxhighzone))))
box.set_right(array.get(bullboxarray, i), bar_index)

//Bullish OB Box Plotting

if (bullishEngulfing and showOBboxes)
boxlowzone = low < low ? low : low
boxhighzone = open
bullbox = box.new(bar_index_, boxhighzone, bar_index, boxlowzone, border_color=adbullborderboxcolor, border_style=line.style_dashed, bgcolor=adbullboxcolor)
if (array.size(bullboxarray) > adboxcount)
box.delete(array.shift(bullboxarray))
array.push(bullboxarray, bullbox)

f_choppedoffbull(bullboxarray)

Ý tưởng liên quan

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.