0% found this document useful (0 votes)
30 views2 pages

Balanced Price Range (BPR)

Uploaded by

6dm28nk48c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Balanced Price Range (BPR)

Uploaded by

6dm28nk48c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/@version=5

indicator("Double FVG", overlay = true, max_bars_back = 500, max_boxes_count = 500)

enable_fvg = input.bool(title = '', defval = true, inline = 'fvg')


fvg_type = input.string(title = '', defval = 'Double FVG', options=['FVG','Inverse
FVG','Double FVG', 'FVG + IFVG', 'IFVG + DFVG', 'All'], inline = 'fvg')
bars_since = input(20, "Lookback", tooltip = "Only look for BPR's when a sequence
of bearish and bullish FVG's are within this many bars of each other")
extend = input.int(20, 'Extend', minval = 0, tooltip = 'No. of bard to extend the
BPR right side of the chart')
bpr_threshold = input.float(0, step = 0.25, title = "Threshold", tooltip = "Valid
BPR's must have a range greater than this number")
bearish_bpr_color = input.color(color.new(color.red, 70), title = '', inline =
'fvg')
bullish_bpr_color = input.color(color.new(color.green, 70), title = '', inline =
'fvg')
invis = color.rgb(0,0,0,100)

float box_high = na
float box_low = na
int box_left = 0
int box_right = 0
var box box_bearish = na
var box box_bullish = na

new_fvg_bearish = low[2] - high > 0


new_fvg_bullish = low - high[2] > 0

valid_high = high[1] > high[2] and high[1] > high[0]


valid_low = low[1] < low[2] and low[1] < low[0]

shouldDisplayDFVG()=>
fvg_type == 'Double FVG' or fvg_type == 'FVG + DFVG' or fvg_type == 'IFVG +
DFVG' or fvg_type == 'All'

// Bullish BPR
bull_num_since = ta.barssince(new_fvg_bearish)
bull_bpr_cond_1 = new_fvg_bullish and bull_num_since <= bars_since
bull_bpr_cond_2 = bull_bpr_cond_1 ? high[bull_num_since] + low[bull_num_since + 2]
+ high[2] + low > math.max(low[bull_num_since + 2], low) -
math.min(high[bull_num_since], high[2]) : na

bull_combined_low = bull_bpr_cond_2 ? math.max(high[bull_num_since], high[2]) : na


bull_combined_high = bull_bpr_cond_2 ? math.min(low[bull_num_since + 2], low) : na

bull_bpr_cond_3 = true

bull_result = bull_bpr_cond_1 and bull_bpr_cond_2 and bull_bpr_cond_3 and


(bull_combined_high - bull_combined_low >= bpr_threshold)

if bull_result[1] and shouldDisplayDFVG()


box_bullish := box.new(bar_index - 1, bull_combined_high[1], bar_index +
extend, bull_combined_low[1], border_color = invis, bgcolor = bullish_bpr_color)
alertcondition(bull_result[1], "Bullish Alert", "New Bullish BPR")

if not na(box_bullish) and low < box.get_bottom(box_bullish)


box.delete(box_bullish)
box_bullish := na
// Bearish BPR
bear_num_since = ta.barssince(new_fvg_bullish)
bear_bpr_cond_1 = new_fvg_bearish and bear_num_since <= bars_since
bear_bpr_cond_2 = bear_bpr_cond_1 ? high[bear_num_since] + low[bear_num_since + 2]
+ high[2] + low > math.max(low[bear_num_since + 2], low) -
math.min(high[bear_num_since], high[2]) : na

bear_combined_low = bear_bpr_cond_2 ? math.max(high[bear_num_since + 2], high) : na


bear_combined_high = bear_bpr_cond_2 ? math.min(low[bear_num_since], low[2]) : na

bear_bpr_cond_3 = true

bear_result = bear_bpr_cond_1 and bear_bpr_cond_2 and bear_bpr_cond_3 and


(bear_combined_high - bear_combined_low >= bpr_threshold)

if bear_result[1] and shouldDisplayDFVG()


box_bearish := box.new(bar_index - 1, bear_combined_high[1], bar_index +
extend, bear_combined_low[1], border_color = invis, bgcolor = bearish_bpr_color)
alertcondition(bear_result[1], "Bearish Alert", "New Bearish BPR")

if not na(box_bearish) and high > box.get_top(box_bearish)


box.delete(box_bearish)
box_bearish := na

You might also like