// SMA sma4_strong = ta.sma(close, 8) sma5_strong = ta.sma(close, 9)
// Signal Generation // Signal Generation Function supertrend(_src, factor, atrLen) => atr = ta.atr(atrLen) upperBand = _src + factor * atr lowerBand = _src - factor * atr prevLowerBand = nz(lowerBand[1]) prevUpperBand = nz(upperBand[1]) lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand var int direction = na var float superTrend = na prevSuperTrend = nz(superTrend[1])
if na(atr[1]) direction := 1 else if prevSuperTrend == prevUpperBand direction := close > upperBand ? -1 : 1 else direction := close < lowerBand ? 1 : -1
smoothrng(x, t, m) => wper = t * 2 - 1 avrng = ta.ema(math.abs(x - x[1]), t) smoothrng = ta.ema(avrng, wper) * m smoothrng smrng = smoothrng(close, 22, 6)
rngfilt(x, r) => rngfilt = x rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r rngfilt filt = rngfilt(close, smrng)
rngfiltx1x1(x, r) => rngfiltx1x1 = x rngfiltx1x1 := x > nz(rngfiltx1x1[1]) ? x - r < nz(rngfiltx1x1[1]) ? nz(rngfiltx1x1[1]) : x - r : x + r > nz(rngfiltx1x1[1]) ? nz(rngfiltx1x1[1]) : x + r rngfiltx1x1 filtx1 = rngfiltx1x1(close, smrngx1x) filtx12 = rngfiltx1x1(close, smrngx1x2)
// boolean expression to see if the ADX is below tehe sideways threshold bool isSideways = sig < sidewaysThreshold
// adding the option to color the bars when in a trading range useBarColor = true bColor = isSideways ? #b102fc : na barcolor(useBarColor ? bColor : na)
barcolor(close > supertrend ? #3cff00 : #fe0100)
percentStop = input.float(1, "Stop Loss % (0 to Disable)", 0, group="BUY & SELL SIGNALS")
//-----------------------------------------------------------------------------{ //Constants //-----------------------------------------------------------------------------{ color TRANSP_CSS = #ffffff00
//Tooltips string MODE_TOOLTIP = 'Allows to display historical Structure or only the recent ones' string STYLE_TOOLTIP = 'Indicator color theme' string COLOR_CANDLES_TOOLTIP = 'Display additional candles with a color reflecting the current trend detected by structure' string SHOW_INTERNAL = 'Display internal market structure' string CONFLUENCE_FILTER = 'Filter non significant internal structure breakouts' string SHOW_SWING = 'Display swing market Structure' string SHOW_SWING_POINTS = 'Display swing point as labels on the chart' string SHOW_SWHL_POINTS = 'Highlight most recent strong and weak high/low points on the chart' string INTERNAL_OB = 'Display internal order blocks on the chart\n\nNumber of internal order blocks to display on the chart' string SWING_OB = 'Display swing order blocks on the chart\n\nNumber of internal swing blocks to display on the chart' string FILTER_OB = 'Method used to filter out volatile order blocks \n\nIt is recommended to use the cumulative mean range method when a low amount of data is available' string SHOW_EQHL = 'Display equal highs and equal lows on the chart' string EQHL_BARS = 'Number of bars used to confirm equal highs and equal lows' string EQHL_THRESHOLD = 'Sensitivity threshold in a range (0, 1) used for the detection of equal highs & lows\n\nLower values will return fewer but more pertinent results' string SHOW_FVG = 'Display fair values gaps on the chart' string AUTO_FVG = 'Filter out non significant fair value gaps' string FVG_TF = 'Fair value gaps timeframe' string EXTEND_FVG = 'Determine how many bars to extend the Fair Value Gap boxes on chart' string PED_ZONES = 'Display premium, discount, and equilibrium zones on chart'
//Display Structure function display_Structure(x, y, txt, css, dashed, down, lbl_size)=> structure_line = line.new(x, y, n, y , color = css , style = dashed ? line.style_dashed : line.style_solid)
structure_lbl = label.new(int(math.avg(x, n)), y, txt , color = TRANSP_CSS , textcolor = css , style = down ? label.style_label_down : label.style_label_up , size = lbl_size)
if mode == 'Present' line.delete(structure_line[1]) label.delete(structure_lbl[1])
//Swings detection/measurements swings(len)=> var os = 0
//Search for highest/lowest high within the structure interval and get range if use_max for i = 1 to (n - loc)-1 if (high - low) < ob_threshold * 2 max := math.max(high, max) min := max == high ? low : min idx := max == high ? i : idx else for i = 1 to (n - loc)-1 if (high - low) < ob_threshold * 2 min := math.min(low, min) max := min == low ? high : max idx := min == low ? i : idx
//-----------------------------------------------------------------------------} //Pivot High //-----------------------------------------------------------------------------{ var line extend_top = na
var label extend_top_lbl = label.new(na, na , color = TRANSP_CSS , textcolor = bear_css , style = label.style_label_down , size = size.tiny)
if top top_cross := true txt_top := top > top_y ? 'HH' : 'LH'
//Extend recent top to last bar line.delete(extend_top[1]) extend_top := line.new(n-length, top, n, top , color = bear_css)
top_y := top top_x := n - length
trail_up := top trail_up_x := n - length
if itop itop_cross := true
itop_y := itop itop_x := n - 5
//Trailing maximum trail_up := math.max(high, trail_up) trail_up_x := trail_up == high ? n : trail_up_x
//Set top extension label/line if barstate.islast and show_hl_swings line.set_xy1(extend_top, trail_up_x, trail_up) line.set_xy2(extend_top, n + 20, trail_up)
//-----------------------------------------------------------------------------} //Pivot Low //-----------------------------------------------------------------------------{ var line extend_btm = na
var label extend_btm_lbl = label.new(na, na , color = TRANSP_CSS , textcolor = bull_css , style = label.style_label_up , size = size.tiny)
//-----------------------------------------------------------------------------} //Order Blocks Arrays //-----------------------------------------------------------------------------{ var iob_top = array.new_float(0) var iob_btm = array.new_float(0) var iob_left = array.new_int(0) var iob_type = array.new_int(0)
var ob_top = array.new_float(0) var ob_btm = array.new_float(0) var ob_left = array.new_int(0) var ob_type = array.new_int(0)
//-----------------------------------------------------------------------------} //Pivot High BOS/CHoCH //-----------------------------------------------------------------------------{ //Filtering var bull_concordant = true
if ifilter_confluence bull_concordant := high - math.max(close, open) > math.min(close, open - low)
//Detect internal bullish Structure if ta.crossover(close, itop_y) and itop_cross and top_y != itop_y and bull_concordant bool choch = na
if show_internals if show_ibull == 'All' or (show_ibull == 'BOS' and not choch) or (show_ibull == 'CHoCH' and choch) display_Structure(itop_x, itop_y, txt, ibull_css, true, true, internal_structure_lbl_size)
itop_cross := false itrend := 1
//Internal Order Block if show_iob ob_coord(false, itop_x, iob_top, iob_btm, iob_left, iob_type)
//Detect bullish Structure if ta.crossover(close, top_y) and top_cross bool choch = na
if show_Structure if show_bull == 'All' or (show_bull == 'BOS' and not choch) or (show_bull == 'CHoCH' and choch) display_Structure(top_x, top_y, txt, bull_css, false, true, swing_structure_lbl_size)
//Order Block if show_ob ob_coord(false, top_x, ob_top, ob_btm, ob_left, ob_type)
top_cross := false trend := 1
//-----------------------------------------------------------------------------} //Pivot Low BOS/CHoCH //-----------------------------------------------------------------------------{ var bear_concordant = true
if ifilter_confluence bear_concordant := high - math.max(close, open) < math.min(close, open - low)
//Detect internal bearish Structure if ta.crossunder(close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and bear_concordant bool choch = false
if show_internals if show_ibear == 'All' or (show_ibear == 'BOS' and not choch) or (show_ibear == 'CHoCH' and choch) display_Structure(ibtm_x, ibtm_y, txt, ibear_css, true, false, internal_structure_lbl_size)
ibtm_cross := false itrend := -1
//Internal Order Block if show_iob ob_coord(true, ibtm_x, iob_top, iob_btm, iob_left, iob_type)
//Detect bearish Structure if ta.crossunder(close, btm_y) and btm_cross bool choch = na
if show_Structure if show_bear == 'All' or (show_bear == 'BOS' and not choch) or (show_bear == 'CHoCH' and choch) display_Structure(btm_x, btm_y, txt, bear_css, false, false, swing_structure_lbl_size)
//Order Block if show_ob ob_coord(true, btm_x, ob_top, ob_btm, ob_left, ob_type)
btm_cross := false trend := -1
//-----------------------------------------------------------------------------} //Order Blocks //-----------------------------------------------------------------------------{ //Set order blocks var iob_boxes = array.new_box(0) var ob_boxes = array.new_box(0)
//Delete internal order blocks box coordinates if top/bottom is broken for element in iob_type index = array.indexof(iob_type, element)
if close < array.get(iob_btm, index) and element == 1 array.remove(iob_top, index) array.remove(iob_btm, index) array.remove(iob_left, index) array.remove(iob_type, index) bull_iob_break := true
else if close > array.get(iob_top, index) and element == -1 array.remove(iob_top, index) array.remove(iob_btm, index) array.remove(iob_left, index) array.remove(iob_type, index) bear_iob_break := true
//Delete internal order blocks box coordinates if top/bottom is broken for element in ob_type index = array.indexof(ob_type, element)
if close < array.get(ob_btm, index) and element == 1 array.remove(ob_top, index) array.remove(ob_btm, index) array.remove(ob_left, index) array.remove(ob_type, index) bull_ob_break := true
else if close > array.get(ob_top, index) and element == -1 array.remove(ob_top, index) array.remove(ob_btm, index) array.remove(ob_left, index) array.remove(ob_type, index) bear_ob_break := true
if barstate.isfirst if show_iob for i = 0 to iob_showlast-1 array.push(iob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time)) if show_ob for i = 0 to ob_showlast-1 array.push(ob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
if iob_size > 0 if barstate.islast display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type, iob_showlast, false, iob_size)
if ob_size > 0 if barstate.islast display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type, ob_showlast, true, ob_size)
//-----------------------------------------------------------------------------} //EQH/EQL //-----------------------------------------------------------------------------{ var eq_prev_top = 0. var eq_top_x = 0
var eq_prev_btm = 0. var eq_btm_x = 0
if show_eq eq_top = ta.pivothigh(eq_len, eq_len) eq_btm = ta.pivotlow(eq_len, eq_len)
if eq_top max = math.max(eq_top, eq_prev_top) min = math.min(eq_top, eq_prev_top)
if max < min + atr * eq_threshold eqh_line = line.new(eq_top_x, eq_prev_top, n-eq_len, eq_top , color = bear_css , style = line.style_dotted)
if mode == 'Present' line.delete(eql_line[1]) label.delete(eql_lbl[1])
eq_prev_btm := eq_btm eq_btm_x := n-eq_len
//-----------------------------------------------------------------------------} //Fair Value Gaps //-----------------------------------------------------------------------------{ var bullish_fvg_max = array.new_box(0) var bullish_fvg_min = array.new_box(0)
var bearish_fvg_max = array.new_box(0) var bearish_fvg_min = array.new_box(0)
float bullish_fvg_avg = na float bearish_fvg_avg = na
//-----------------------------------------------------------------------------} //Trend //-----------------------------------------------------------------------------{ var color trend_css = na
if show_trend if style == 'Colored' trend_css := itrend == 1 ? bull_css : bear_css else if style == 'Monochrome' trend_css := itrend == 1 ? #b2b5be : #5d606b
plotcandle(open, high, low, close , color = trend_css , wickcolor = trend_css , bordercolor = trend_css , editable = false)