// © BARBARIANS TRADING CLUB / www.barbarianstrading.com //@version=5 indicator(title="Barbarians Trading Club", shorttitle="Barbarians Trading", overlay = true, max_boxes_count=500, max_labels_count=500, max_lines_count=500, max_bars_back=1000) // Global settings { timeonoff = input(false, title='Show Time', group='Global Settings') msbonoff = input(false, title='OB & MSB', group='Global Settings') Imbalance = input(false, title='Imbalance', group='Global Settings') htfonoff = input(false, title='HTF Liquidity', group='Global Settings') sfpon = input(false, title="Swing Failure Pattern", group='Global Settings') Manyind = input(false, title="Divergence For Many", group='Global Settings') vpoconoff = input(false, title='vPOC Days Period', group='Global Settings') SRchannel = input(false, title='Support & Resistance Channel', group='Global Settings') show_zigzag = input.bool(false, title="Zigzag", group='Global Settings') ShowHHLL = input(false, title='HH, LL, LH, HL', group='Global Settings') vwaponoff = input(false, title="VWAP ", group='Global Settings') showmas = input.bool(false, title='MA 50 & 200', group='Global Settings') bullbearEnOp = input(false, title='Bullish & Bearish Engulfing', group='Global Settings') filigran = input(true, title='Filigran', group='Global Settings') // } // Show Time { f_create_level(_type, _start_condition, _active_condition, _global_level_array, _color, _line_width, _line_ext, _line_style, _label_size, _title, _iter, _is_enabled) => var float _price = na var int _start_time = na var float _hh = na var float _ll = na var line _price_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_time, color = _color, width = _line_width, style = _line_style) var label _price_label = label.new(x = na, y = na, xloc = xloc.bar_time, style = label.style_label_left, color = #00000000, size = _label_size, textcolor = _color) _end_time = int(time + _line_ext * ta.change(time)) if _type == "open" if _start_condition _price := open _start_time := time else if _type == "high" if _start_condition _price := high _start_time := time else if _active_condition _price := math.max(_price, high) else if _type == "low" if _start_condition _price := low _start_time := time else if _active_condition _price := math.min(_price, low) else if _type == "eq" if _start_condition _hh := high _ll := low _price := math.avg(_hh, _ll) _start_time := time else if _active_condition _hh := math.max(_hh, high) _ll := math.min(_ll, low) _price := math.avg(_hh, _ll) float _price_val = _iter == 0 ? _price : ta.valuewhen(_start_condition, _price[1], _iter - 1) int _start_time_val = _iter == 0 ? _start_time : ta.valuewhen(_start_condition, _start_time[1], _iter - 1) _found_existing = array.indexof(_global_level_array, _price_val) > -1 if _is_enabled and timeonoff if _found_existing line.set_xy1(_price_line, x = na, y = na) line.set_xy2(_price_line, x = na, y = na) label.set_xy(_price_label, x = na, y = na) else array.push(_global_level_array, _price_val) line.set_xy1(_price_line, x = _start_time_val, y = _price_val) line.set_xy2(_price_line, x = _end_time, y = _price_val) label.set_text(_price_label, text = _title + " : " + str.tostring(_price_val)) label.set_xy(_price_label, x = _end_time, y = _price_val) float[] global_open_array = array.new_float() float[] global_high_array = array.new_float() float[] global_low_array = array.new_float() float[] global_eq_array = array.new_float() new_H4 = ta.change(time("240")) != 0 new_day = ta.change(time("D")) != 0 new_week = ta.change(time("W")) != 0 new_month = ta.change(time("M")) != 0 new_quarter = ta.change(time("3M")) != 0 new_year = ta.change(time("12M")) != 0 is_monday = dayofweek == dayofweek.monday inp_open_line_style = input.string("Solid", options = ["Solid", "Dotted", "Dashed"], title = "Open ", group = "Time Settings", inline='1') inp_high_line_style = input.string("Solid", options = ["Solid", "Dotted", "Dashed"], title = " | High", group = "Time Settings", inline='1') inp_low_line_style = input.string("Solid", options = ["Solid", "Dotted", "Dashed"], title = " | Low", group = "Time Settings", inline='1') inp_text_size = input.string("Small", options = ["Small", "Normal", "Large"], title = "Text Size", group = "Time Settings", inline='4') inp_ext = input.int(20, title = "Line Extension", group = "Time Settings", inline='4') text_size = inp_text_size == "Small" ? size.small : inp_text_size == "Normal" ? size.normal : size.large open_line_style = inp_open_line_style == "Solid" ? line.style_solid : inp_open_line_style == "Dotted" ? line.style_dotted : line.style_dashed high_line_style = inp_high_line_style == "Solid" ? line.style_solid : inp_high_line_style == "Dotted" ? line.style_dotted : line.style_dashed low_line_style = inp_low_line_style == "Solid" ? line.style_solid : inp_low_line_style == "Dotted" ? line.style_dotted : line.style_dashed inp_show_daily_open = input.bool(true, title = "Daily        |",group = "TIME OPEN-HIGH-LOW", inline = "5") inp_show_daily_high = input.bool(false, title = "High |", group = "TIME OPEN-HIGH-LOW", inline = "5") inp_show_daily_low = input.bool(false, title = "Low |", group = "TIME OPEN-HIGH-LOW", inline = "5") inp_daily_col = input.color(color.gray, title = "", group = "TIME OPEN-HIGH-LOW", inline = "5") inp_daily_line_width = input.int(1, title = "", minval = 1, group = "TIME OPEN-HIGH-LOW", inline = "5") daily_ok = timeframe.isintraday f_create_level("open", new_day, not new_day, global_open_array, inp_daily_col, inp_daily_line_width, inp_ext, open_line_style, text_size, "DO", 0, inp_show_daily_open and daily_ok) f_create_level("high", new_day, not new_day, global_high_array, inp_daily_col, inp_daily_line_width, inp_ext, high_line_style, text_size, "DH", 0, inp_show_daily_high and daily_ok) f_create_level("low", new_day, not new_day, global_low_array, inp_daily_col, inp_daily_line_width, inp_ext, low_line_style, text_size, "DL", 0, inp_show_daily_low and daily_ok) inp_show_prev_daily_open = input.bool(false, title = "Prev Daily     |", group = "PREV TIME OPEN-HIGH-LOW", inline = "6") inp_show_prev_daily_high = input.bool(false, title = "High |", group = "PREV TIME OPEN-HIGH-LOW", inline = "6") inp_show_prev_daily_low = input.bool(false, title = "Low |", group = "PREV TIME OPEN-HIGH-LOW", inline = "6") inp_prev_daily_col = input.color(color.gray, title = "", group = "PREV TIME OPEN-HIGH-LOW", inline = "6") inp_prev_daily_line_width = input.int(1, title = "", minval = 1, group = "PREV TIME OPEN-HIGH-LOW", inline = "6") f_create_level("open", new_day, not new_day, global_open_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, open_line_style, text_size, "PDO", 1, inp_show_prev_daily_open and daily_ok) f_create_level("high", new_day, not new_day, global_high_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, high_line_style, text_size, "PDH", 1, inp_show_prev_daily_high and daily_ok) f_create_level("low", new_day, not new_day, global_low_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, low_line_style, text_size, "PDL", 1, inp_show_prev_daily_low and daily_ok) inp_show_weekly_open = input.bool(true, title = "Weekly      |", group = "TIME OPEN-HIGH-LOW", inline = "7") inp_show_weekly_high = input.bool(false, title = "High |", group = "TIME OPEN-HIGH-LOW", inline = "7") inp_show_weekly_low = input.bool(false, title = "Low |", group = "TIME OPEN-HIGH-LOW", inline = "7") inp_weekly_col = input.color(color.aqua, title = "", group = "TIME OPEN-HIGH-LOW", inline = "7") inp_weekly_line_width = input.int(2, title = "", minval = 1, group = "TIME OPEN-HIGH-LOW", inline = "7") weekly_ok = timeframe.isintraday or timeframe.isdaily f_create_level("open", new_week, not new_week, global_open_array, inp_weekly_col, inp_weekly_line_width, inp_ext, open_line_style, text_size, "WO", 0, inp_show_weekly_open and weekly_ok) f_create_level("high", new_week, not new_week, global_high_array, inp_weekly_col, inp_weekly_line_width, inp_ext, high_line_style, text_size, "WH", 0, inp_show_weekly_high and weekly_ok) f_create_level("low", new_week, not new_week, global_low_array, inp_weekly_col, inp_weekly_line_width, inp_ext, low_line_style, text_size, "WL", 0, inp_show_weekly_low and weekly_ok) inp_show_prev_weekly_open = input.bool(false, title = "Prev Weekly   |", group = "PREV TIME OPEN-HIGH-LOW", inline = "8") inp_show_prev_weekly_high = input.bool(false, title = "High |", group = "PREV TIME OPEN-HIGH-LOW", inline = "8") inp_show_prev_weekly_low = input.bool(false, title = "Low |", group = "PREV TIME OPEN-HIGH-LOW", inline = "8") inp_prev_weekly_col = input.color(color.blue, title = "", group = "PREV TIME OPEN-HIGH-LOW", inline = "8") inp_prev_weekly_line_width = input.int(2, title = "", minval = 1, group = "PREV TIME OPEN-HIGH-LOW", inline = "8") f_create_level("open", new_week, not new_week, global_open_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, open_line_style, text_size, "PWO", 1, inp_show_prev_weekly_open and weekly_ok) f_create_level("high", new_week, not new_week, global_high_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, high_line_style, text_size, "PWH", 1, inp_show_prev_weekly_high and weekly_ok) f_create_level("low", new_week, not new_week, global_low_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, low_line_style, text_size, "PWL", 1, inp_show_prev_weekly_low and weekly_ok) inp_show_monthly_open = input.bool(true, title = "Monthly     |",group = "TIME OPEN-HIGH-LOW", inline = "9") inp_show_monthly_high = input.bool(false, title = "High |", group = "TIME OPEN-HIGH-LOW", inline = "9") inp_show_monthly_low = input.bool(false, title = "Low |", group = "TIME OPEN-HIGH-LOW", inline = "9") inp_monthly_col = input.color(color.lime, title = "", group = "TIME OPEN-HIGH-LOW", inline = "9") inp_monthly_line_width = input.int(3, title = "", minval = 1, group = "TIME OPEN-HIGH-LOW", inline = "9") monthly_ok = timeframe.isintraday or timeframe.isdaily f_create_level("open", new_month, not new_month, global_open_array, inp_monthly_col, inp_monthly_line_width, inp_ext, open_line_style, text_size, "MO", 0, inp_show_monthly_open and monthly_ok) f_create_level("high", new_month, not new_month, global_high_array, inp_monthly_col, inp_monthly_line_width, inp_ext, high_line_style, text_size, "MH", 0, inp_show_monthly_high and monthly_ok) f_create_level("low", new_month, not new_month, global_low_array, inp_monthly_col, inp_monthly_line_width, inp_ext, low_line_style, text_size, "ML", 0, inp_show_monthly_low and monthly_ok) inp_show_prev_monthly_open = input.bool(false, title = "Prev Monthly  |", group = "PREV TIME OPEN-HIGH-LOW", inline = "10") inp_show_prev_monthly_high = input.bool(false, title = "High |", group = "PREV TIME OPEN-HIGH-LOW", inline = "10") inp_show_prev_monthly_low = input.bool(false, title = "Low |", group = "PREV TIME OPEN-HIGH-LOW", inline = "10") inp_prev_monthly_col = input.color(color.green, title = "", group = "PREV TIME OPEN-HIGH-LOW", inline = "10") inp_prev_monthly_line_width = input.int(3, title = "", minval = 1, group = "PREV TIME OPEN-HIGH-LOW", inline = "10") f_create_level("open", new_month, not new_month, global_open_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, open_line_style, text_size, "PMO", 1, inp_show_prev_monthly_open and monthly_ok) f_create_level("high", new_month, not new_month, global_high_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, high_line_style, text_size, "PMH", 1, inp_show_prev_monthly_high and monthly_ok) f_create_level("low", new_month, not new_month, global_low_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, low_line_style, text_size, "PML", 1, inp_show_prev_monthly_low and monthly_ok) inp_show_quarterly_open = input.bool(true, title = "Quarterly    |",group = "TIME OPEN-HIGH-LOW", inline = "11") inp_show_quarterly_high = input.bool(false, title = "High |", group = "TIME OPEN-HIGH-LOW", inline = "11") inp_show_quarterly_low = input.bool(false, title = "Low |", group = "TIME OPEN-HIGH-LOW", inline = "11") inp_quarterly_col = input.color(color.orange, title = "", group = "TIME OPEN-HIGH-LOW", inline = "11") inp_quarterly_line_width = input.int(4, title = "", minval = 1, group = "TIME OPEN-HIGH-LOW", inline = "11") quarterly_ok = timeframe.isintraday or timeframe.isdaily or timeframe.isweekly f_create_level("open", new_quarter, not new_quarter, global_open_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, open_line_style, text_size, "QO", 0, inp_show_quarterly_open and quarterly_ok) f_create_level("high", new_quarter, not new_quarter, global_high_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, high_line_style, text_size, "QH", 0, inp_show_quarterly_high and quarterly_ok) f_create_level("low", new_quarter, not new_quarter, global_low_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, low_line_style, text_size, "QL", 0, inp_show_quarterly_low and quarterly_ok) inp_show_prev_quarterly_open = input.bool(false, title = "Prev Quarterly |", group = "PREV TIME OPEN-HIGH-LOW", inline = "12") inp_show_prev_quarterly_high = input.bool(false, title = "High |", group = "PREV TIME OPEN-HIGH-LOW", inline = "12") inp_show_prev_quarterly_low = input.bool(false, title = "Low |", group = "PREV TIME OPEN-HIGH-LOW", inline = "12") inp_prev_quarterly_col = input.color(color.yellow, title = "", group = "PREV TIME OPEN-HIGH-LOW", inline = "12") inp_prev_quarterly_line_width = input.int(4, title = "", minval = 1, group = "PREV TIME OPEN-HIGH-LOW", inline = "12") f_create_level("open", new_quarter, not new_quarter, global_open_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, open_line_style, text_size, "PQO", 1, inp_show_prev_quarterly_open and quarterly_ok) f_create_level("high", new_quarter, not new_quarter, global_high_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, high_line_style, text_size, "PQH", 1, inp_show_prev_quarterly_high and quarterly_ok) f_create_level("low", new_quarter, not new_quarter, global_low_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, low_line_style, text_size, "PQL", 1, inp_show_prev_quarterly_low and quarterly_ok) inp_show_yearly_open = input.bool(true, title = "Yearly      |", group = "TIME OPEN-HIGH-LOW", inline = "13") inp_show_yearly_high = input.bool(false, title = "High |", group = "TIME OPEN-HIGH-LOW", inline = "13") inp_show_yearly_low = input.bool(false, title = "Low |", group = "TIME OPEN-HIGH-LOW", inline = "13") inp_yearly_col = input.color(color.red, title = "", group = "TIME OPEN-HIGH-LOW", inline = "13") inp_yearly_line_width = input.int(5, title = "", minval = 1, group = "TIME OPEN-HIGH-LOW", inline = "13") yearly_ok = timeframe.isintraday or timeframe.isdaily or timeframe.isweekly or (timeframe.ismonthly and timeframe.multiplier < 12) f_create_level("open", new_year, not new_year, global_open_array, inp_yearly_col, inp_yearly_line_width, inp_ext, open_line_style, text_size, "YO", 0, inp_show_yearly_open and yearly_ok) f_create_level("high", new_year, not new_year, global_high_array, inp_yearly_col, inp_yearly_line_width, inp_ext, high_line_style, text_size, "YH", 0, inp_show_yearly_high and yearly_ok) f_create_level("low", new_year, not new_year, global_low_array, inp_yearly_col, inp_yearly_line_width, inp_ext, low_line_style, text_size, "YL", 0, inp_show_yearly_low and yearly_ok) inp_show_prev_yearly_open = input.bool(false, title = "Prev Yearly   |", group = "PREV TIME OPEN-HIGH-LOW", inline = "14") inp_show_prev_yearly_high = input.bool(false, title = "High |", group = "PREV TIME OPEN-HIGH-LOW", inline = "14") inp_show_prev_yearly_low = input.bool(false, title = "Low |", group = "PREV TIME OPEN-HIGH-LOW", inline = "14") inp_prev_yearly_col = input.color(color.maroon, title = "", group = "PREV TIME OPEN-HIGH-LOW", inline = "14") inp_prev_yearly_line_width = input.int(5, title = "", minval = 1, group = "PREV TIME OPEN-HIGH-LOW", inline = "14") f_create_level("open", new_year, not new_year, global_open_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, open_line_style, text_size, "PYO", 1, inp_show_prev_yearly_open and yearly_ok) f_create_level("high", new_year, not new_year, global_high_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, high_line_style, text_size, "PYH", 1, inp_show_prev_yearly_high and yearly_ok) f_create_level("low", new_year, not new_year, global_low_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, low_line_style, text_size, "PYL", 1, inp_show_prev_yearly_low and yearly_ok) inp_show_monday_high = input.bool(true, title = "High    |", group = "MONDAY", inline = "14") inp_show_monday_low = input.bool(true, title = "Low |", group = "MONDAY", inline = "14") inp_monday_col = input.color(color.fuchsia, title = "", group = "MONDAY", inline = "14") inp_monday_line_width = input.int(1, title = "", minval = 1, group = "MONDAY", inline = "14") monday_ok = timeframe.isintraday f_create_level("high", new_week, is_monday, global_high_array, inp_monday_col, inp_monday_line_width, inp_ext, open_line_style, text_size, "Monday HIGH", 0, inp_show_monday_high and monday_ok) f_create_level("low", new_week, is_monday, global_low_array, inp_monday_col, inp_monday_line_width, inp_ext, open_line_style, text_size, "Monday LOW", 0, inp_show_monday_low and monday_ok) inp_show_prev_monday_high = input.bool(false, title = "Prev High |", group = "MONDAY", inline = "15") inp_show_prev_monday_low = input.bool(false, title = "Low |", group = "MONDAY", inline = "15") inp_prev_monday_col = input.color(color.purple, title = "", group = "MONDAY", inline = "15") inp_prev_monday_line_width = input.int(1, title = "", minval = 1, group = "MONDAY", inline = "15") f_create_level("high", new_week, is_monday, global_high_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, open_line_style, text_size, "PMonday HIGH", 1, inp_show_prev_monday_high and monday_ok) f_create_level("low", new_week, is_monday, global_low_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, open_line_style, text_size, "PMonday LOW", 1, inp_show_prev_monday_low and monday_ok) // } // Divergence for Many { shownum = input(defval=true, title='Show Divergence Number', group='DIVERGENCE FOR MANY') showlast = input(defval=false, title='Show Only Last Divergence', group='DIVERGENCE FOR MANY') dontconfirm = input(defval=false, title='Don\'t Wait for Confirmation', group='DIVERGENCE FOR MANY') showlines = input(defval=false, title='Show Divergence Lines', group='DIVERGENCE FOR MANY') showpivot = input(defval=false, title='Show Pivot Points', group='DIVERGENCE FOR MANY') calcmacd = input(defval=true, title='MACD', group='DIVERGENCE FOR MANY') calcmacda = input(defval=true, title='MACD Histogram', group='DIVERGENCE FOR MANY') calcrsi = input(defval=true, title='RSI', group='DIVERGENCE FOR MANY') calcstoc = input(defval=true, title='Stochastic', group='DIVERGENCE FOR MANY') calccci = input(defval=true, title='CCI', group='DIVERGENCE FOR MANY') calcmom = input(defval=true, title='Momentum', group='DIVERGENCE FOR MANY') calcobv = input(defval=true, title='OBV', group='DIVERGENCE FOR MANY') calcvwmacd = input(true, title='VWmacd', group='DIVERGENCE FOR MANY') calccmf = input(true, title='Chaikin Money Flow', group='DIVERGENCE FOR MANY') calcmfi = input(true, title='Money Flow Index', group='DIVERGENCE FOR MANY') calcext = input(true, title='Check External Indicator', group='DIVERGENCE FOR MANY') prds = input.int(defval=5, title='Pivot Period', minval=1, maxval=50, group='DIVERGENCE FOR MANY') sources = input.string(defval='Close', title='Source for Pivot Points', options=['Close', 'High/Low'], group='DIVERGENCE FOR MANY') searchdiv = input.string(defval='Regular', title='Divergence Type', options=['Regular', 'Hidden', 'Regular/Hidden'], group='DIVERGENCE FOR MANY') showindis = input.string(defval='Don\'t Show', title='Show Indicator Names', options=['Full', 'First Letter', 'Don\'t Show'], group='DIVERGENCE FOR MANY') showlimit = input.int(1, title='Minimum Number of Divergence', minval=1, maxval=11, group='DIVERGENCE FOR MANY') maxpp = input.int(defval=10, title='Maximum Pivot Points to Check', minval=1, maxval=20, group='DIVERGENCE FOR MANY') maxbars = input.int(defval=100, title='Maximum Bars to Check', minval=30, maxval=200, group='DIVERGENCE FOR MANY') externalindi = input(defval=close, title='External Indicator', group='DIVERGENCE FOR MANY') pos_reg_div_col = input(defval=color.yellow, title='Positive Regular Divergence', group='DIVERGENCE FOR MANY') neg_reg_div_col = input(defval=color.navy, title='Negative Regular Divergence', group='DIVERGENCE FOR MANY') pos_hid_div_col = input(defval=color.lime, title='Positive Hidden Divergence', group='DIVERGENCE FOR MANY') neg_hid_div_col = input(defval=color.red, title='Negative Hidden Divergence', group='DIVERGENCE FOR MANY') pos_div_text_col = input(defval=color.black, title='Positive Divergence Text Color', group='DIVERGENCE FOR MANY') neg_div_text_col = input(defval=color.white, title='Negative Divergence Text Color', group='DIVERGENCE FOR MANY') reg_div_l_style_ = input.string(defval='Solid', title='Regular Divergence Line Style', options=['Solid', 'Dashed', 'Dotted'], group='DIVERGENCE FOR MANY') hid_div_l_style_ = input.string(defval='Dashed', title='Hdden Divergence Line Style', options=['Solid', 'Dashed', 'Dotted'], group='DIVERGENCE FOR MANY') reg_div_l_width = input.int(defval=2, title='Regular Divergence Line Width', minval=1, maxval=5, group='DIVERGENCE FOR MANY') hid_div_l_width = input.int(defval=1, title='Hidden Divergence Line Width', minval=1, maxval=5, group='DIVERGENCE FOR MANY') cma1col = input.color(defval=color.lime, title='', inline='ma12', group='DIVERGENCE FOR MANY') cma2col = input.color(defval=color.red, title='', inline='ma12', group='DIVERGENCE FOR MANY') plot(showmas ? ta.sma(close, 50) : na, color=showmas ? cma1col : na) plot(showmas ? ta.sma(close, 200) : na, color=showmas ? cma2col : na) var reg_div_l_style = reg_div_l_style_ == 'Solid' ? line.style_solid : reg_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted var hid_div_l_style = hid_div_l_style_ == 'Solid' ? line.style_solid : hid_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted rsi = ta.rsi(close, 14) // RSI [macd, signal, deltamacd] = ta.macd(close, 12, 26, 9) // MACD moment = ta.mom(close, 10) // Momentum cci = ta.cci(close, 10) // CCI Obv = ta.obv // OBV stk = ta.sma(ta.stoch(close, high, low, 14), 3) // Stoch maFast = ta.vwma(close, 12) // volume weighted macd maSlow = ta.vwma(close, 26) vwmacd = maFast - maSlow Cmfm = (close - low - (high - close)) / (high - low) // Chaikin money flow Cmfv = Cmfm * volume cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21) Mfi = ta.mfi(close, 14) // Moneyt Flow Index var indicators_name = array.new_string(11) var div_colors = array.new_color(4) if Manyind and barstate.isfirst array.set(indicators_name, 0, showindis == 'Full' ? 'MACD' : 'M') array.set(indicators_name, 1, showindis == 'Full' ? 'Hist' : 'H') array.set(indicators_name, 2, showindis == 'Full' ? 'RSI' : 'E') array.set(indicators_name, 3, showindis == 'Full' ? 'Stoch' : 'S') array.set(indicators_name, 4, showindis == 'Full' ? 'CCI' : 'C') array.set(indicators_name, 5, showindis == 'Full' ? 'MOM' : 'M') array.set(indicators_name, 6, showindis == 'Full' ? 'OBV' : 'O') array.set(indicators_name, 7, showindis == 'Full' ? 'VWMACD' : 'V') array.set(indicators_name, 8, showindis == 'Full' ? 'CMF' : 'C') array.set(indicators_name, 9, showindis == 'Full' ? 'MFI' : 'M') array.set(indicators_name, 10, showindis == 'Full' ? 'Extrn' : 'X') array.set(div_colors, 0, pos_reg_div_col) array.set(div_colors, 1, neg_reg_div_col) array.set(div_colors, 2, pos_hid_div_col) array.set(div_colors, 3, neg_hid_div_col) float phhhh = ta.pivothigh(sources == 'Close' ? close : high, prds, prds) float pllll = ta.pivotlow(sources == 'Close' ? close : low, prds, prds) plotshape(phhhh and showpivot, text='H', style=shape.labeldown, color=color.new(color.white, 100), textcolor=color.new(color.red, 0), location=location.abovebar, offset=-prds) plotshape(pllll and showpivot, text='L', style=shape.labelup, color=color.new(color.white, 100), textcolor=color.new(color.lime, 0), location=location.belowbar, offset=-prds) var int maxarraysize = 20 var ph_positions = array.new_int(maxarraysize, 0) var pl_positions = array.new_int(maxarraysize, 0) var ph_vals = array.new_float(maxarraysize, 0.) var pl_vals = array.new_float(maxarraysize, 0.) if Manyind and phhhh array.unshift(ph_positions, bar_index) array.unshift(ph_vals, phhhh) if array.size(ph_positions) > maxarraysize array.pop(ph_positions) array.pop(ph_vals) if Manyind and pllll array.unshift(pl_positions, bar_index) array.unshift(pl_vals, pllll) if array.size(pl_positions) > maxarraysize array.pop(pl_positions) array.pop(pl_vals) positive_regular_positive_hidden_divergence(src, cond) => divlen = 0 prsc = sources == 'Close' ? close : low if Manyind and dontconfirm or src > src[1] or close > close[1] startpoint = dontconfirm ? 0 : 1 // don't check last candle for x = 0 to maxpp - 1 by 1 len = bar_index - array.get(pl_positions, x) + prds if array.get(pl_positions, x) == 0 or len > maxbars break if len > 5 and (cond == 1 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(pl_vals, x)) or cond == 2 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(pl_vals, x))) slope1 = (src[startpoint] - src[len]) / (len - startpoint) virtual_line1 = src[startpoint] - slope1 slope2 = (close[startpoint] - close[len]) / (len - startpoint) virtual_line2 = close[startpoint] - slope2 arrived = true for y = 1 + startpoint to len - 1 by 1 if src[y] < virtual_line1 or nz(close[y]) < virtual_line2 arrived := false break virtual_line1 -= slope1 virtual_line2 -= slope2 virtual_line2 if arrived divlen := len break divlen negative_regular_negative_hidden_divergence(src, cond) => divlen = 0 prsc = sources == 'Close' ? close : high if Manyind and dontconfirm or src < src[1] or close < close[1] startpoint = dontconfirm ? 0 : 1 // don't check last candle for x = 0 to maxpp - 1 by 1 len = bar_index - array.get(ph_positions, x) + prds if array.get(ph_positions, x) == 0 or len > maxbars break if len > 5 and (cond == 1 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(ph_vals, x)) or cond == 2 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(ph_vals, x))) slope1 = (src[startpoint] - src[len]) / (len - startpoint) virtual_line1 = src[startpoint] - slope1 slope2 = (close[startpoint] - nz(close[len])) / (len - startpoint) virtual_line2 = close[startpoint] - slope2 arrived = true for y = 1 + startpoint to len - 1 by 1 if src[y] > virtual_line1 or nz(close[y]) > virtual_line2 arrived := false break virtual_line1 -= slope1 virtual_line2 -= slope2 virtual_line2 if arrived divlen := len break divlen calculate_divs(cond, indicator_1) => divs = array.new_int(4, 0) array.set(divs, 0, cond and (searchdiv == 'Regular' or searchdiv == 'Regular/Hidden') ? positive_regular_positive_hidden_divergence(indicator_1, 1) : 0) array.set(divs, 1, cond and (searchdiv == 'Regular' or searchdiv == 'Regular/Hidden') ? negative_regular_negative_hidden_divergence(indicator_1, 1) : 0) array.set(divs, 2, cond and (searchdiv == 'Hidden' or searchdiv == 'Regular/Hidden') ? positive_regular_positive_hidden_divergence(indicator_1, 2) : 0) array.set(divs, 3, cond and (searchdiv == 'Hidden' or searchdiv == 'Regular/Hidden') ? negative_regular_negative_hidden_divergence(indicator_1, 2) : 0) divs var all_divergences = array.new_int(44) // 11 indicators * 4 divergence = 44 elements array_set_divs(div_pointer, index) => for x = 0 to 3 by 1 array.set(all_divergences, index * 4 + x, array.get(div_pointer, x)) array_set_divs(calculate_divs(calcmacd, macd), 0) array_set_divs(calculate_divs(calcmacda, deltamacd), 1) array_set_divs(calculate_divs(calcrsi, rsi), 2) array_set_divs(calculate_divs(calcstoc, stk), 3) array_set_divs(calculate_divs(calccci, cci), 4) array_set_divs(calculate_divs(calcmom, moment), 5) array_set_divs(calculate_divs(calcobv, Obv), 6) array_set_divs(calculate_divs(calcvwmacd, vwmacd), 7) array_set_divs(calculate_divs(calccmf, cmf), 8) array_set_divs(calculate_divs(calcmfi, Mfi), 9) array_set_divs(calculate_divs(calcext, externalindi), 10) total_div = 0 for x = 0 to array.size(all_divergences) - 1 by 1 total_div += math.round(math.sign(array.get(all_divergences, x))) total_div if Manyind and total_div < showlimit array.fill(all_divergences, 0) var pos_div_lines = array.new_line(0) var neg_div_lines = array.new_line(0) var pos_div_labels = array.new_label(0) var neg_div_labels = array.new_label(0) delete_old_pos_div_lines() => if array.size(pos_div_lines) > 0 for j = 0 to array.size(pos_div_lines) - 1 by 1 line.delete(array.get(pos_div_lines, j)) array.clear(pos_div_lines) delete_old_neg_div_lines() => if array.size(neg_div_lines) > 0 for j = 0 to array.size(neg_div_lines) - 1 by 1 line.delete(array.get(neg_div_lines, j)) array.clear(neg_div_lines) delete_old_pos_div_labels() => if array.size(pos_div_labels) > 0 for j = 0 to array.size(pos_div_labels) - 1 by 1 label.delete(array.get(pos_div_labels, j)) array.clear(pos_div_labels) delete_old_neg_div_labels() => if array.size(neg_div_labels) > 0 for j = 0 to array.size(neg_div_labels) - 1 by 1 label.delete(array.get(neg_div_labels, j)) array.clear(neg_div_labels) delete_last_pos_div_lines_label(n) => if n > 0 and array.size(pos_div_lines) >= n asz = array.size(pos_div_lines) for j = 1 to n by 1 line.delete(array.get(pos_div_lines, asz - j)) array.pop(pos_div_lines) if array.size(pos_div_labels) > 0 label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1)) array.pop(pos_div_labels) delete_last_neg_div_lines_label(n) => if n > 0 and array.size(neg_div_lines) >= n asz = array.size(neg_div_lines) for j = 1 to n by 1 line.delete(array.get(neg_div_lines, asz - j)) array.pop(neg_div_lines) if array.size(neg_div_labels) > 0 label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1)) array.pop(neg_div_labels) pos_reg_div_detected = false neg_reg_div_detected = false pos_hid_div_detected = false neg_hid_div_detected = false var last_pos_div_lines = 0 var last_neg_div_lines = 0 var remove_last_pos_divs = false var remove_last_neg_divs = false if Manyind and pllll remove_last_pos_divs := false last_pos_div_lines := 0 last_pos_div_lines if Manyind and phhhh remove_last_neg_divs := false last_neg_div_lines := 0 last_neg_div_lines divergence_text_top = '' divergence_text_bottom = '' distances = array.new_int(0) dnumdiv_top = 0 dnumdiv_bottom = 0 top_label_col = color.white bottom_label_col = color.white old_pos_divs_can_be_removed = true old_neg_divs_can_be_removed = true startpoint = dontconfirm ? 0 : 1 // used for don't confirm option for x = 0 to 10 by 1 div_type = -1 for y = 0 to 3 by 1 if array.get(all_divergences, x * 4 + y) > 0 // any divergence? div_type := y if y % 2 == 1 dnumdiv_top += 1 top_label_col := array.get(div_colors, y) top_label_col if y % 2 == 0 dnumdiv_bottom += 1 bottom_label_col := array.get(div_colors, y) bottom_label_col if not array.includes(distances, array.get(all_divergences, x * 4 + y)) // line not exist ? array.push(distances, array.get(all_divergences, x * 4 + y)) new_line = showlines ? line.new(x1=bar_index - array.get(all_divergences, x * 4 + y), y1=sources == 'Close' ? close[array.get(all_divergences, x * 4 + y)] : y % 2 == 0 ? low[array.get(all_divergences, x * 4 + y)] : high[array.get(all_divergences, x * 4 + y)], x2=bar_index - startpoint, y2=sources == 'Close' ? close[startpoint] : y % 2 == 0 ? low[startpoint] : high[startpoint], color=array.get(div_colors, y), style=y < 2 ? reg_div_l_style : hid_div_l_style, width=y < 2 ? reg_div_l_width : hid_div_l_width) : na if y % 2 == 0 if old_pos_divs_can_be_removed old_pos_divs_can_be_removed := false if not showlast and remove_last_pos_divs delete_last_pos_div_lines_label(last_pos_div_lines) last_pos_div_lines := 0 last_pos_div_lines if showlast delete_old_pos_div_lines() array.push(pos_div_lines, new_line) last_pos_div_lines += 1 remove_last_pos_divs := true remove_last_pos_divs if y % 2 == 1 if old_neg_divs_can_be_removed old_neg_divs_can_be_removed := false if not showlast and remove_last_neg_divs delete_last_neg_div_lines_label(last_neg_div_lines) last_neg_div_lines := 0 last_neg_div_lines if showlast delete_old_neg_div_lines() array.push(neg_div_lines, new_line) last_neg_div_lines += 1 remove_last_neg_divs := true remove_last_neg_divs if y == 0 pos_reg_div_detected := true pos_reg_div_detected if y == 1 neg_reg_div_detected := true neg_reg_div_detected if y == 2 pos_hid_div_detected := true pos_hid_div_detected if y == 3 neg_hid_div_detected := true neg_hid_div_detected if div_type >= 0 divergence_text_top += (div_type % 2 == 1 ? showindis != 'Don\'t Show' ? array.get(indicators_name, x) + '\n' : '' : '') divergence_text_bottom += (div_type % 2 == 0 ? showindis != 'Don\'t Show' ? array.get(indicators_name, x) + '\n' : '' : '') divergence_text_bottom if Manyind and showindis != 'Don\'t Show' or shownum if shownum and dnumdiv_top > 0 divergence_text_top += str.tostring(dnumdiv_top) divergence_text_top if shownum and dnumdiv_bottom > 0 divergence_text_bottom += str.tostring(dnumdiv_bottom) divergence_text_bottom if divergence_text_top != '' if showlast delete_old_neg_div_labels() array.push(neg_div_labels, label.new(x=bar_index, y=math.max(high, high[1]), text=divergence_text_top, color=top_label_col, textcolor=neg_div_text_col, style=label.style_label_down)) if divergence_text_bottom != '' if showlast delete_old_pos_div_labels() array.push(pos_div_labels, label.new(x=bar_index, y=math.min(low, low[1]), text=divergence_text_bottom, color=bottom_label_col, textcolor=pos_div_text_col, style=label.style_label_up)) alertcondition(pos_reg_div_detected, title='Positive Regular Divergence Detected', message='Positive Regular Divergence Detected') alertcondition(neg_reg_div_detected, title='Negative Regular Divergence Detected', message='Negative Regular Divergence Detected') alertcondition(pos_hid_div_detected, title='Positive Hidden Divergence Detected', message='Positive Hidden Divergence Detected') alertcondition(neg_hid_div_detected, title='Negative Hidden Divergence Detected', message='Negative Hidden Divergence Detected') alertcondition(pos_reg_div_detected or pos_hid_div_detected, title='Positive Divergence Detected', message='Positive Divergence Detected') alertcondition(neg_reg_div_detected or neg_hid_div_detected, title='Negative Divergence Detected', message='Negative Divergence Detected') // } // OB & MSB { settings = "OB & MSB" zigzag_len = input.int(9, "ZigZag Length", group=settings) fib_factor = input.float(0.33, "Fib Factor for breakout confirmation", 0, 1, 0.01, group=settings) tooltip_text = "Some timeframes may not be displayed in current timeframe. Zigzag lines only shows in current timeframe." time_frame= input.string("Chart", "Timeframe", ["Chart", "5m", "15m", "30m", "1h", "2h", "4h", "D"], tooltip=tooltip_text) tf = switch time_frame "5m" => "5" "15m" => "15" "30m" => "30" "1h" => "60" "2h" => "120" "4h" => "240" "D" => "D" => timeframe.period text_size1 = input.string(size.tiny, "Text Size", [size.tiny, size.small, size.normal, size.large, size.huge]) bu_ob_inline_color = "Bu-OB Colors" be_ob_inline_color = "Be-OB Colors" bu_bb_inline_color = "Bu-BB Colors" be_bb_inline_color = "Be-BB Colors" bu_ob_display_settings = "Bu-OB Display Settings" bu_ob_color = input.color(color.new(color.green, 70), "Color", group=bu_ob_display_settings, inline=bu_ob_inline_color) bu_ob_border_color = input.color(color.green, "Border Color", group=bu_ob_display_settings, inline=bu_ob_inline_color) bu_ob_text_color = input.color(color.green, "Text Color", group=bu_ob_display_settings, inline=bu_ob_inline_color) be_ob_display_settings = "Be-OB Display Settings" be_ob_color = input.color(color.new(color.red, 70), "Color", group=be_ob_display_settings, inline=be_ob_inline_color) be_ob_border_color = input.color(color.red, "Border Color", group=be_ob_display_settings, inline=be_ob_inline_color) be_ob_text_color = input.color(color.red, "Text Color", group=be_ob_display_settings, inline=be_ob_inline_color) bu_bb_display_settings = "Bu-BB & Bu-MB Display Settings" bu_bb_color = input.color(color.new(color.green, 70), "Color", group=bu_bb_display_settings, inline=bu_bb_inline_color) bu_bb_border_color = input.color(color.green, "Border Color", group=bu_bb_display_settings, inline=bu_bb_inline_color) bu_bb_text_color = input.color(color.green, "Text Color", group=bu_bb_display_settings, inline=bu_bb_inline_color) be_bb_display_settings = "Be-BB & Be-MB Display Settings" be_bb_color = input.color(color.new(color.red, 70), "Color", group=be_bb_display_settings, inline=be_bb_inline_color) be_bb_border_color = input.color(color.red, "Border Color", group=be_bb_display_settings, inline=be_bb_inline_color) be_bb_text_color = input.color(color.red, "Text Color", group=be_bb_display_settings, inline=be_bb_inline_color) var float[] high_points_arr = array.new_float(5) var int[] high_index_arr = array.new_int(5) var float[] low_points_arr = array.new_float(5) var int[] low_index_arr = array.new_int(5) var box[] bu_ob_boxes = array.new_box(5) var box[] be_ob_boxes = array.new_box(5) var box[] bu_bb_boxes = array.new_box(5) var box[] be_bb_boxes = array.new_box(5) f_get_high(ind) => [array.get(high_points_arr, array.size(high_points_arr) - 1 - ind), array.get(high_index_arr, array.size(high_index_arr) - 1 - ind)] f_get_low(ind) => [array.get(low_points_arr, array.size(low_points_arr) - 1 - ind), array.get(low_index_arr, array.size(low_index_arr) - 1 - ind)] f_main1() => to_up = high >= ta.highest(zigzag_len) to_down = low <= ta.lowest(zigzag_len) trend = 1 trend := nz(trend[1], 1) trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend last_trend_up_since = ta.barssince(to_up[1]) low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1)) low_index = bar_index - ta.barssince(low_val == low) last_trend_down_since = ta.barssince(to_down[1]) high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1, 1)) high_index = bar_index - ta.barssince(high_val == high) if ta.change(trend) != 0 if trend == 1 array.push(low_points_arr, low_val) array.push(low_index_arr, low_index) if trend == -1 array.push(high_points_arr, high_val) array.push(high_index_arr, high_index) [h0, h0i] = f_get_high(0) [h1, h1i] = f_get_high(1) [l0, l0i] = f_get_low(0) [l1, l1i] = f_get_low(1) market = 1 market := nz(market[1], 1) last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0) last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0) market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 > h1 + math.abs(h1 - l0) * fib_factor ? 1 : market alert_market = 1 alert_market := nz(alert_market[1], 1) alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market == 1 and trend == -1 and close < l0 and close < l0 - math.abs(h0 - l0) * fib_factor ? -1 : alert_market == -1 and trend == 1 and close > h0 and close > h0 + math.abs(h0 - l0) * fib_factor ? 1 : alert_market bu_ob_index = bar_index bu_ob_index := nz(bu_ob_index[1], bar_index) for i=h1i to l0i[zigzag_len] index = bar_index - i if open[index] > close[index] bu_ob_index := bar_index[index] bu_ob_since = bar_index - bu_ob_index be_ob_index = bar_index be_ob_index := nz(be_ob_index[1], bar_index) for i=l1i to h0i[zigzag_len] index = bar_index - i if open[index] < close[index] be_ob_index := bar_index[index] be_ob_since = bar_index - be_ob_index be_bb_index = bar_index be_bb_index := nz(be_bb_index[1], bar_index) for i=h1i - zigzag_len to l1i index = bar_index - i if open[index] > close[index] be_bb_index := bar_index[index] be_bb_since = bar_index - be_bb_index bu_bb_index = bar_index bu_bb_index := nz(bu_bb_index[1], bar_index) for i=l1i - zigzag_len to h1i index = bar_index - i if open[index] < close[index] bu_bb_index := bar_index[index] bu_bb_since = bar_index - bu_bb_index bu_ob_since_high = high[bu_ob_since] bu_ob_since_low = low[bu_ob_since] be_ob_since_high = high[be_ob_since] be_ob_since_low = low[be_ob_since] be_bb_since_high = high[be_bb_since] be_bb_since_low = low[be_bb_since] bu_bb_since_high = high[bu_bb_since] bu_bb_since_low = low[bu_bb_since] [trend, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high, bu_ob_since_low, be_ob_since_high, be_ob_since_low] f_main2() => to_up = high >= ta.highest(zigzag_len) to_down = low <= ta.lowest(zigzag_len) trend = 1 trend := nz(trend[1], 1) trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend last_trend_up_since = ta.barssince(to_up[1]) low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1)) low_index = bar_index - ta.barssince(low_val == low) last_trend_down_since = ta.barssince(to_down[1]) high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1, 1)) high_index = bar_index - ta.barssince(high_val == high) if ta.change(trend) != 0 if trend == 1 array.push(low_points_arr, low_val) array.push(low_index_arr, low_index) if trend == -1 array.push(high_points_arr, high_val) array.push(high_index_arr, high_index) [h0, h0i] = f_get_high(0) [h1, h1i] = f_get_high(1) [l0, l0i] = f_get_low(0) [l1, l1i] = f_get_low(1) market = 1 market := nz(market[1], 1) last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0) last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0) market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 > h1 + math.abs(h1 - l0) * fib_factor ? 1 : market // For alert alert_market = 1 alert_market := nz(alert_market[1], 1) alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market == 1 and trend == -1 and close < l0 and close < l0 - math.abs(h0 - l0) * fib_factor ? -1 : alert_market == -1 and trend == 1 and close > h0 and close > h0 + math.abs(h0 - l0) * fib_factor ? 1 : alert_market bu_ob_index = bar_index bu_ob_index := nz(bu_ob_index[1], bar_index) for i=h1i to l0i[zigzag_len] index = bar_index - i if open[index] > close[index] bu_ob_index := bar_index[index] bu_ob_since = bar_index - bu_ob_index be_ob_index = bar_index be_ob_index := nz(be_ob_index[1], bar_index) for i=l1i to h0i[zigzag_len] index = bar_index - i if open[index] < close[index] be_ob_index := bar_index[index] be_ob_since = bar_index - be_ob_index be_bb_index = bar_index be_bb_index := nz(be_bb_index[1], bar_index) for i=h1i - zigzag_len to l1i index = bar_index - i if open[index] > close[index] be_bb_index := bar_index[index] be_bb_since = bar_index - be_bb_index bu_bb_index = bar_index bu_bb_index := nz(bu_bb_index[1], bar_index) for i=l1i - zigzag_len to h1i index = bar_index - i if open[index] < close[index] bu_bb_index := bar_index[index] bu_bb_since = bar_index - bu_bb_index bu_ob_since_high = high[bu_ob_since] bu_ob_since_low = low[bu_ob_since] be_ob_since_high = high[be_ob_since] be_ob_since_low = low[be_ob_since] be_bb_since_high = high[be_bb_since] be_bb_since_low = low[be_bb_since] bu_bb_since_high = high[bu_bb_since] bu_bb_since_low = low[bu_bb_since] [alert_market, be_bb_since_high, be_bb_since_low, bu_bb_since_high, bu_bb_since_low, bu_ob_index, bu_bb_index, be_ob_index, be_bb_index] [trend, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high, bu_ob_since_low, be_ob_since_high, be_ob_since_low] = request.security(syminfo.tickerid, tf, f_main1()) [alert_market, be_bb_since_high, be_bb_since_low, bu_bb_since_high, bu_bb_since_low, bu_ob_index, bu_bb_index, be_ob_index, be_bb_index] = request.security(syminfo.tickerid, tf, f_main2()) // Be_bb_since olanlar değişecek be_ob_index ler eklenecek if ta.change(trend) != 0 and show_zigzag if trend == 1 line.new(h0i, h0, l0i, l0) if trend == -1 line.new(l0i, l0, h0i, h0) if ta.change(market) != 0 and msbonoff if market == 1 line.new(h1i, h1, h0i, h1, color=color.green, width=2) label.new(int(math.avg(h1i, l0i)), h1, "MSB", color=color.new(color.black, 100), style=label.style_label_down, textcolor=color.green, size=size.small) bu_ob = box.new(bu_ob_index, bu_ob_since_high, bar_index + 10, bu_ob_since_low, bgcolor=bu_ob_color, border_color=bu_ob_border_color, text="Bu-OB", text_color=bu_ob_text_color, text_halign=text.align_right, text_size=text_size1) bu_bb = box.new(bu_bb_index, bu_bb_since_high, bar_index + 10, bu_bb_since_low, bgcolor=bu_bb_color, border_color=bu_bb_border_color, text=l0 < l1 ? "Bu-BB" : "Bu-MB", text_color=bu_bb_text_color, text_halign=text.align_right, text_size=text_size1) array.push(bu_ob_boxes, bu_ob) array.push(bu_bb_boxes, bu_bb) if market == -1 line.new(l1i, l1, l0i, l1, color=color.red, width=2) label.new(int(math.avg(l1i, h0i)), l1, "MSB", color=color.new(color.black, 100), style=label.style_label_up, textcolor=color.red, size=size.small) be_ob = box.new(be_ob_index, be_ob_since_high, bar_index + 10, be_ob_since_low, bgcolor=be_ob_color, border_color=be_ob_border_color, text="Be-OB", text_color=be_ob_text_color, text_halign=text.align_right, text_size=text_size1) be_bb = box.new(be_bb_index, be_bb_since_high, bar_index + 10, be_bb_since_low, bgcolor=be_bb_color, border_color=be_bb_border_color, text=h0 > h1 ? "Be-BB" : "Be-MB", text_color=be_bb_text_color, text_halign=text.align_right, text_size=text_size1) array.push(be_ob_boxes, be_ob) array.push(be_bb_boxes, be_bb) for bull_ob in bu_ob_boxes bottom = box.get_bottom(bull_ob) if close < bottom box.delete(bull_ob) else if array.size(bu_ob_boxes) == 5 box.delete(array.shift(bu_ob_boxes)) else box.set_right(bull_ob, bar_index + 10) for bear_ob in be_ob_boxes top = box.get_top(bear_ob) if close > top box.delete(bear_ob) else if array.size(be_ob_boxes) == 5 box.delete(array.shift(be_ob_boxes)) else box.set_right(bear_ob, bar_index + 10) for bear_bb in be_bb_boxes top = box.get_top(bear_bb) if close > top box.delete(bear_bb) else if array.size(be_bb_boxes) == 5 box.delete(array.shift(be_bb_boxes)) else box.set_right(bear_bb, bar_index + 10) for bull_bb in bu_bb_boxes bottom = box.get_bottom(bull_bb) if close < bottom box.delete(bull_bb) else if array.size(bu_bb_boxes) == 5 box.delete(array.shift(bu_bb_boxes)) else box.set_right(bull_bb, bar_index + 10) if ta.change(alert_market) != 0 alert("MSB", alert.freq_once_per_bar) // } // Imbalance { var color purpco = color.new(color.purple, 50) TopImbalance = low[2] <= open[1] and high[0] >= close[1] TopImbalancesize = low[2] - high[0] if Imbalance and TopImbalance and TopImbalancesize > 0 BOX1 = box.new(left=bar_index[1], top=low[2], right=bar_index[0], bottom=high[0]) box.set_bgcolor(BOX1, purpco) box.set_border_color(BOX1, purpco) BottomInbalance = high[2] >= open[1] and low[0] <= close[1] BottomInbalancesize = low[0] - high[2] if Imbalance and BottomInbalance and BottomInbalancesize > 0 BOX2 = box.new(left=bar_index[1], top=low[0], right=bar_index[0], bottom=high[2]) box.set_bgcolor(BOX2, purpco) box.set_border_color(BOX2, purpco) // } // HTF Liquidity Levels { var START_OFFSET = 0 var END_OFFSET = 25 var PURGED_COLOR = color.gray var PURGED_STYLE = line.style_dotted var g_indicator = "HTF Liquidity" i_isDailyEnabled = input (true, "Daily", inline="Daily", group=g_indicator) i_dailyAboveLiquidityColor = input (color.new(color.green, 30), "", inline="Daily", group=g_indicator) i_dailyBelowLiquidityColor = input (color.new(#f23645, 30), "", inline="Daily", group=g_indicator) i_dailyWidth = input (1, "Width", inline="Daily", group=g_indicator) i_isWeeklyEnabled = input (true, "Weekly", inline="Weekly", group=g_indicator) i_weelyAboveLiquidityColor = input (color.new(color.lime, 70), "", inline="Weekly", group=g_indicator) i_weelyBelowLiquidityColor = input (color.new(color.red, 70), "", inline="Weekly", group=g_indicator) i_weeklyWidth = input (5, "Width", inline="Weekly", group=g_indicator) i_isMonthlyEnabled = input (true, "Monthly", inline="Monthly", group=g_indicator) i_monthlyAboveLiquidityColor = input (color.new(#87fe07, 90), "", inline="Monthly", group=g_indicator) i_monthlyBelowLiquidityColor = input (color.new(color.orange, 90), "", inline="Monthly", group=g_indicator) i_monthlyWidth = input (10, "Width", inline="Monthly", group=g_indicator) var highsArray = array.new_float() var lowsArray = array.new_float() var highLinesArray = array.new_line() var lowLinesArray = array.new_line() var float dayHigh = na var float dayLow = na [prevDayHigh, prevDayLow] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead=barmerge.lookahead_on) [prevWeekHigh, prevWeekLow] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead=barmerge.lookahead_on) [prevMonthHigh, prevMonthLow] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead=barmerge.lookahead_on) f_drawLine(float _y, color _c, int _w=1) => line.new(bar_index, _y, bar_index, _y, color=_c, width=_w) f_create(float _high, float _low, color _upperColor, color _lowerColor, int _linewidth) => array.push(highsArray, _high) array.push(lowsArray, _low) array.push(highLinesArray, f_drawLine(_high, _upperColor, _linewidth)) array.push(lowLinesArray, f_drawLine(_low, _lowerColor, _linewidth)) f_update(array _levels) => for _line in _levels line.set_x1(_line, bar_index + START_OFFSET) line.set_x2(_line, bar_index + END_OFFSET) f_cleanUpperLevels(float _high, array _highs, array _levels) => while array.min(_highs) < _high for [_index, _value] in _highs if _high > _value line.delete(array.remove(_levels, _index)) array.remove(_highs, _index) f_cleanLowerLevels(float _low, array _lows, array _levels) => while array.max(_lows) > _low for [_index, _value] in _lows if _low < _value line.delete(array.remove(_levels, _index)) array.remove(_lows, _index) f_highlightUpperLevels(float _high, array _highs, array _levels) => for [_index, _value] in _highs if _high > _value _line = array.get(_levels, _index) line.set_color(_line, PURGED_COLOR) line.set_style(_line, PURGED_STYLE) f_highlightLowerLevels(float _low, array _lows, array _levels) => for [_index, _value] in _lows if _low < _value _line = array.get(_levels, _index) line.set_color(_line, PURGED_COLOR) line.set_style(_line, PURGED_STYLE) if htfonoff and i_isDailyEnabled and ta.change(time("D")) f_create(prevDayHigh, prevDayLow, i_dailyAboveLiquidityColor, i_dailyBelowLiquidityColor, i_dailyWidth) if htfonoff and i_isWeeklyEnabled and ta.change(time("W")) f_create(prevWeekHigh, prevWeekLow, i_weelyAboveLiquidityColor, i_weelyBelowLiquidityColor, i_weeklyWidth) if htfonoff and i_isMonthlyEnabled and ta.change(time("M")) f_create(prevMonthHigh, prevMonthLow, i_monthlyAboveLiquidityColor, i_monthlyBelowLiquidityColor, i_monthlyWidth) if barstate.islast f_update(highLinesArray) f_update(lowLinesArray) if ta.change(time("D")) dayHigh := high dayLow := low if high > dayHigh dayHigh := high if low < dayLow dayLow := low if barstate.islast f_highlightUpperLevels(dayHigh, highsArray, highLinesArray) f_highlightLowerLevels(dayLow, lowsArray, lowLinesArray) if ta.change(time("D")) f_cleanUpperLevels(prevDayHigh, highsArray, highLinesArray) f_cleanLowerLevels(prevDayLow, lowsArray, lowLinesArray) // } // Swing Failure Pattern { swingHistory = input.int(10, title='Swing history:', minval=1, group='SWING FAILURE PATTERN') plotSwings = input(false, title='Plot swings', group='SWING FAILURE PATTERN') plotFirstSFPOnly = input(true, title='Plot only first SFP candle', group='SWING FAILURE PATTERN') plotStrongerSFPs = input.int(10, title='Plot stronger SFPs:', minval=0, group='SWING FAILURE PATTERN') isSwingHigh = false isSwingLow = false swingHigh = high[swingHistory] swingLow = low[swingHistory] range_1 = swingHistory * 2 for i = 0 to range_1 by 1 isSwingHigh := true if i < swingHistory if high[i] > swingHigh isSwingHigh := false break if i > swingHistory if high[i] >= swingHigh isSwingHigh := false break for i = 0 to range_1 by 1 isSwingLow := true if i < swingHistory if low[i] < swingLow isSwingLow := false break if i > swingHistory if low[i] <= swingLow isSwingLow := false break isSwingHighFailure = false isSwingLowFailure = false var lastSwingHigh = float(na) var lastSwingLow = float(na) lastSwingHigh := isSwingHigh ? swingHigh : lastSwingHigh lastSwingLow := isSwingLow ? swingLow : lastSwingLow strengthOfHighSFP = 0 if lastSwingHigh < high and lastSwingHigh > close and ta.barssince(lastSwingHigh) <= swingHistory isSwingHighFailure := true if plotFirstSFPOnly lastSwingHigh := na lastSwingHigh else for i = 0 to plotStrongerSFPs by 1 if isSwingHighFailure[i] strengthOfHighSFP += 1 // it will be at least 1 strengthOfHighSFP else if high[i] > high strengthOfHighSFP -= 1 strengthOfHighSFP strengthOfLowSFP = 0 if lastSwingLow > low and lastSwingLow < close and ta.barssince(lastSwingLow) <= swingHistory isSwingLowFailure := true if plotFirstSFPOnly lastSwingLow := na lastSwingLow else for i = 0 to plotStrongerSFPs by 1 if isSwingHighFailure[i] strengthOfLowSFP += 1 // it will be at least 1 strengthOfLowSFP else if low[i] < low strengthOfLowSFP -= 1 strengthOfLowSFP alertcondition(condition=isSwingHighFailure, title='SFP: Swing High Failure', message='Swing High Failure') alertcondition(condition=isSwingLowFailure, title='SFP: Swing Low Failure', message='Swing Low Failure') alertcondition(condition=isSwingHighFailure or isSwingLowFailure, title='SFP: Any Swing Failure Pattern', message='Any Swing Failure Pattern') plotshape(series=plotSwings ? isSwingHigh and sfpon : na, style=shape.triangledown, text='SH', color=color.new(color.red, 30), textcolor=color.new(color.gray, 0), location=location.abovebar, size=size.tiny, offset=-swingHistory) plotshape(series=plotSwings ? isSwingLow and sfpon : na, style=shape.triangleup, text='SL', color=color.new(color.green, 30), textcolor=color.new(color.gray, 0), location=location.belowbar, size=size.tiny, offset=-swingHistory) plotshape(series=isSwingHighFailure and sfpon and strengthOfHighSFP <= 1, style=shape.triangledown, text='SFP', color=color.new(color.red, 30), textcolor=color.new(color.gray, 0), location=location.abovebar, size=size.tiny) plotshape(series=isSwingHighFailure and sfpon and strengthOfHighSFP >= 3, style=shape.triangledown, text='SFPs', color=color.new(color.red, 30), textcolor=color.new(color.gray, 0), location=location.abovebar, size=size.tiny) plotshape(series=isSwingLowFailure and sfpon and strengthOfLowSFP <= 1, style=shape.triangleup, text='SFPs', color=color.new(color.green, 30), textcolor=color.new(color.gray, 0), location=location.belowbar, size=size.tiny) plotshape(series=isSwingLowFailure and sfpon and strengthOfLowSFP >= 3, style=shape.triangleup, text='SFP', color=color.new(color.green, 30), textcolor=color.new(color.gray, 0), location=location.belowbar, size=size.tiny) // } // vPOC Period { var bool is_first_candle = true var diff = 0.0 float maxV = 0.0 int maxV_index = 0 int last_time = 0 margin = 0.0 ys = 0.0 int bar_offset = 0 var is_first_inRange = false period_time = input.int(defval=10, title='Number of days (Min: 3, Max: 500)', minval=3, maxval=500, group='vPOC Days Period') resolution = input.int(defval=500, title='calculation resolution (Min: 400, Max: 700)', minval=400, maxval=700, group='vPOC Days Period') show_from = input.int(defval=3, title='show support/resistance since (Min: 2, Max: 45)', minval=2, maxval=45, group='vPOC Days Period') show_volume_bars = input(defval=true, title='Show volume bars (If selected, maximum days are 17)', group='vPOC Days Period') show_vpoc_line = input(defval=true, title='Show VPOC line', group='vPOC Days Period') show_support_line = input(defval=false, title='Show support line', group='vPOC Days Period') show_res_line = input(defval=false, title='Show resistance line', group='vPOC Days Period') show_H_line = input(defval=false, title='Show high line', group='vPOC Days Period') show_L_line = input(defval=false, title='Show low line', group='vPOC Days Period') show_labels = input(defval=true, title='Show from days label', group='vPOC Days Period') vpoc_color = input(defval=color.new(color.yellow, 10), title='VPOC color', group='vPOC Days Period') high_low_color = input(defval=color.new(color.blue, 50), title='High-low lines color', group='vPOC Days Period') volume_bars_color = input(defval=color.new(color.green, 70), title='Volume bars color', group='vPOC Days Period') sup_color = input(defval=color.new(color.red, 10), title='Support line color', group='vPOC Days Period') res_color = input(defval=color.new(color.green, 10), title='Resistance line color', group='vPOC Days Period') range_prices = array.new_float(resolution + 1, 0.0) partial_vol = array.new_float(resolution, 0.0) total_vol = array.new_float(resolution, 0.0) var all_ys = array.new_float(show_from, 0.0) var ys_time = array.new_float(show_from, 0.0) var is_support = array.new_bool(show_from, true) t = time('1440', session.regular) var int startTime = time int ncandles = 0 if vpoconoff and barstate.isfirst startTime := timenow - period_time * 86400000 startTime bar_offset := ta.barssince(is_first_inRange) is_first = na(t[1]) and not na(t) or t[1] < t is_first_inRange := is_first and t > startTime high_price = 0.0 low_price = 0.0 price_level = 0.0 if vpoconoff and is_first_inRange or barstate.islast last_time := t[1] ncandles := bar_offset current_low_price = 0.0 for i = 1 to ncandles by 1 current_low_price := low[i] if current_low_price < low_price or low_price == 0.0 low_price := current_low_price low_price current_high_price = 0.0 for i = 1 to ncandles by 1 current_high_price := high[i] if current_high_price > high_price or high_price == 0.0 high_price := current_high_price high_price diff := (high_price - low_price) / resolution for j = 0 to resolution by 1 array.set(range_prices, j, low_price + diff * (j + 1)) for i = 0 to ncandles by 1 int w_candle = 0 array.fill(partial_vol, 0.0) for j = 0 to resolution - 1 by 1 float current_price = array.get(range_prices, j) if high[i] > current_price and low[i] < current_price float j_partial_vol = array.get(partial_vol, j) float sum_vol = j_partial_vol + nz(volume[i]) array.set(partial_vol, j, sum_vol) w_candle += 1 w_candle for j = 0 to resolution - 1 by 1 float j_total_vol = array.get(total_vol, j) float j_partial_vol = array.get(partial_vol, j) float sum_partial_total = 0.0 if w_candle > 0 sum_partial_total := j_total_vol + j_partial_vol / w_candle sum_partial_total else sum_partial_total := j_total_vol sum_partial_total array.set(total_vol, j, sum_partial_total) maxV := array.max(total_vol) maxV_index := array.indexof(total_vol, maxV) if vpoconoff and is_first_inRange price_level := diff * maxV_index + low_price if high_price - price_level > price_level - low_price margin := high_price - price_level ys := price_level - margin ys else margin := price_level - low_price ys := price_level + margin ys if ys > high_price array.shift(is_support) array.push(is_support, false) else array.shift(is_support) array.push(is_support, true) array.shift(all_ys) array.push(all_ys, ys) array.shift(ys_time) array.push(ys_time, t) if vpoconoff and barstate.islast for i = 0 to show_from - 1 by 1 ys := array.get(all_ys, i) time_back = array.get(ys_time, i) if array.get(is_support, i) if show_support_line line.new(x1=int(time_back), y1=ys, x2=time + 86400000, y2=ys, color=sup_color, xloc=xloc.bar_time, extend=extend.none, width=2, style=line.style_dashed) else if show_res_line line.new(x1=int(time_back), y1=ys, x2=time + 86400000, y2=ys, color=res_color, xloc=xloc.bar_time, extend=extend.none, width=2, style=line.style_dashed) if show_labels label.new(int(time + 86400000), ys, text='From days: ' + str.tostring(show_from - i), xloc=xloc.bar_time) dif_time = 0.0 if vpoconoff and is_first_inRange or barstate.islast last_time := int(t[1]) dif_time := time - last_time if dif_time / 86400000 > 1.5 dif_time /= 9 dif_time else dif_time /= 3 dif_time diff_t = 0 x1 = 0.0 norm_vol = 0.0 proportion = resolution / 40 for i = 0 to resolution - 1 by 1 y = array.get(range_prices, i) current_vol = array.get(total_vol, i) norm_vol := current_vol / maxV x1 := dif_time * norm_vol diff_t := last_time + int(x1) if (i % int(proportion) == 0 or int(proportion) == 0) and show_volume_bars and vpoconoff line.new(x1=t[1], y1=y, x2=diff_t, y2=y, color=volume_bars_color, xloc=xloc.bar_time, extend=extend.none, width=2) if vpoconoff and show_L_line line.new(x1=t[1], y1=low_price, x2=time, y2=low_price, xloc=xloc.bar_time, color=high_low_color) if vpoconoff and show_vpoc_line line.new(x1=t[1], y1=diff * maxV_index + low_price, x2=time, y2=diff * maxV_index + low_price, color=vpoc_color, width=2, xloc=xloc.bar_time) if vpoconoff and show_H_line line.new(x1=t[1], y1=high_price, x2=time, y2=high_price, xloc=xloc.bar_time, color=high_low_color) // } // Support & Resistance Channel { prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='Support & Resistance Channel', tooltip='Pivot Noktaları hesaplanırken kullanılır, sol ve sağ çubukları kontrol eder') ppsrc = input.string(defval='High/Low', title='Source', options=['High/Low', 'Close/Open'], group='Support & Resistance Channel', tooltip='Pivot Noktaları için Kaynak') ChannelW = input.int(defval=5, title='Maximum Channel Width %', minval=1, maxval=8, group='Support & Resistance Channel', tooltip='300 barda En Yüksek/En Düşük seviyeler kullanılarak hesaplanmıştır') minstrength = input.int(defval=1, title='Minimum Strength', minval=1, group='Support & Resistance Channel', tooltip='Kanal en az 2 Pivot Noktası içermelidir') maxnumsr = input.int(defval=6, title='Maximum Number of S/R', minval=1, maxval=10, group='Support & Resistance Channel', tooltip='Gösterilecek Maksimum Destek/Direnç Kanalı Sayısı') - 1 loopback = input.int(defval=290, title='Loopback Period', minval=100, maxval=400, group='Support & Resistance Channel', tooltip='S/R seviyelerini hesaplarken Geri Döngü Döneminde Pivotları kontrol eder') res_col = input.color(defval=color.new(color.red, 75), title='Resistance Color', group='Support & Resistance Channel') sup_col = input.color(defval=color.new(color.lime, 75), title='Support Color', group='Support & Resistance Channel') inch_col = input.color(defval=color.new(color.gray, 75), title='Color When Price in Channel', group='Support & Resistance Channel') float src1 = ppsrc == 'High/Low' ? high : math.max(close, open) float src2 = ppsrc == 'High/Low' ? low : math.min(close, open) float ph = ta.pivothigh(src1, prd, prd) float pl = ta.pivotlow(src2, prd, prd) prdhighest = ta.highest(300) prdlowest = ta.lowest(300) cwidth = (prdhighest - prdlowest) * ChannelW / 100 var pivotvals = array.new_float(0) var pivotlocs = array.new_float(0) if SRchannel and ph or pl array.unshift(pivotvals, ph ? ph : pl) array.unshift(pivotlocs, bar_index) for x = array.size(pivotvals) - 1 to 0 by 1 if bar_index - array.get(pivotlocs, x) > loopback // remove old pivot points array.pop(pivotvals) array.pop(pivotlocs) continue break get_sr_vals(ind) => float lo = array.get(pivotvals, ind) float hi = lo int numpp = 0 for y = 0 to array.size(pivotvals) - 1 by 1 float cpp = array.get(pivotvals, y) float wdth = cpp <= hi ? hi - cpp : cpp - lo if SRchannel and wdth <= cwidth // fits the max channel width? if cpp <= hi lo := math.min(lo, cpp) lo else hi := math.max(hi, cpp) hi numpp += 20 // each pivot point added as 20 numpp [hi, lo, numpp] var suportresistance = array.new_float(20, 0) // min/max levels changeit(x, y) => tmp = array.get(suportresistance, y * 2) array.set(suportresistance, y * 2, array.get(suportresistance, x * 2)) array.set(suportresistance, x * 2, tmp) tmp := array.get(suportresistance, y * 2 + 1) array.set(suportresistance, y * 2 + 1, array.get(suportresistance, x * 2 + 1)) array.set(suportresistance, x * 2 + 1, tmp) if SRchannel and ph or pl supres = array.new_float(0) // number of pivot, strength, min/max levels stren = array.new_float(10, 0) for x = 0 to array.size(pivotvals) - 1 by 1 [hi, lo, strength] = get_sr_vals(x) array.push(supres, strength) array.push(supres, hi) array.push(supres, lo) for x = 0 to array.size(pivotvals) - 1 by 1 h = array.get(supres, x * 3 + 1) l = array.get(supres, x * 3 + 2) s = 0 for y = 0 to loopback by 1 if high[y] <= h and high[y] >= l or low[y] <= h and low[y] >= l s += 1 s array.set(supres, x * 3, array.get(supres, x * 3) + s) array.fill(suportresistance, 0) src = 0 for x = 0 to array.size(pivotvals) - 1 by 1 stv = -1. // value stl = -1 // location for y = 0 to array.size(pivotvals) - 1 by 1 if array.get(supres, y * 3) > stv and array.get(supres, y * 3) >= minstrength * 20 stv := array.get(supres, y * 3) stl := y stl if SRchannel and stl >= 0 hh = array.get(supres, stl * 3 + 1) ll = array.get(supres, stl * 3 + 2) array.set(suportresistance, src * 2, hh) array.set(suportresistance, src * 2 + 1, ll) array.set(stren, src, array.get(supres, stl * 3)) for y = 0 to array.size(pivotvals) - 1 by 1 if array.get(supres, y * 3 + 1) <= hh and array.get(supres, y * 3 + 1) >= ll or array.get(supres, y * 3 + 2) <= hh and array.get(supres, y * 3 + 2) >= ll array.set(supres, y * 3, -1) src += 1 if src >= 10 break for x = 0 to 8 by 1 for y = x + 1 to 9 by 1 if SRchannel and array.get(stren, y) > array.get(stren, x) tmp = array.get(stren, y) array.set(stren, y, array.get(stren, x)) changeit(x, y) get_level(ind) => float ret = na if SRchannel and ind < array.size(suportresistance) if SRchannel and array.get(suportresistance, ind) != 0 ret := array.get(suportresistance, ind) ret ret get_color(ind) => color ret = na if SRchannel and ind < array.size(suportresistance) if SRchannel and array.get(suportresistance, ind) != 0 ret := array.get(suportresistance, ind) > close and array.get(suportresistance, ind + 1) > close ? res_col : array.get(suportresistance, ind) < close and array.get(suportresistance, ind + 1) < close ? sup_col : inch_col ret ret var srchannels = array.new_box(10) for x = 0 to math.min(9, maxnumsr) by 1 box.delete(array.get(srchannels, x)) srcol = get_color(x * 2) if SRchannel and not na(srcol) array.set(srchannels, x, box.new(left=bar_index, top=get_level(x * 2), right=bar_index + 1, bottom=get_level(x * 2 + 1), border_color=srcol, border_width=1, extend=extend.both, bgcolor=srcol)) resistancebroken = false supportbroken = false not_in_a_channel = true for x = 0 to math.min(9, maxnumsr) by 1 if SRchannel and close <= array.get(suportresistance, x * 2) and close >= array.get(suportresistance, x * 2 + 1) not_in_a_channel := false not_in_a_channel if SRchannel and not_in_a_channel for x = 0 to math.min(9, maxnumsr) by 1 if close[1] <= array.get(suportresistance, x * 2) and close > array.get(suportresistance, x * 2) resistancebroken := true resistancebroken if close[1] >= array.get(suportresistance, x * 2 + 1) and close < array.get(suportresistance, x * 2 + 1) supportbroken := true supportbroken alertcondition(resistancebroken, title='Resistance Broken', message='Resistance Broken') alertcondition(supportbroken, title='Support Broken', message='Support Broken') // } // HH/HL/LH/LL { lefthh = input.int(5, minval=1, title='Pivot Length left', group='HH, LL, LH, HL', inline='1') righthh = input.int(5, minval=1, title='  |  Pivot Length right', group='HH, LL, LH, HL', inline='1') pvtLenL = lefthh pvtLenR = righthh pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR) pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR) pvthi = pvthi_ pvtlo = pvtlo_ valuewhen_1 = ta.valuewhen(pvthi, high[pvtLenR], 1) valuewhen_2 = ta.valuewhen(pvthi, high[pvtLenR], 0) higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na valuewhen_3 = ta.valuewhen(pvthi, high[pvtLenR], 1) valuewhen_4 = ta.valuewhen(pvthi, high[pvtLenR], 0) lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na valuewhen_5 = ta.valuewhen(pvtlo, low[pvtLenR], 1) valuewhen_6 = ta.valuewhen(pvtlo, low[pvtLenR], 0) higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na valuewhen_7 = ta.valuewhen(pvtlo, low[pvtLenR], 1) valuewhen_8 = ta.valuewhen(pvtlo, low[pvtLenR], 0) lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.triangledown, location=location.abovebar, color=color.new(color.green, 100), text='HH', textcolor=color.new(color.green, 0), offset=-pvtLenR) plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 100), text='HL', textcolor=color.new(color.green, 0), offset=-pvtLenR) plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 100), text='LH', textcolor=color.new(color.red, 0), offset=-pvtLenR) plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.triangleup, location=location.belowbar, color=color.new(color.red, 100), text='LL', textcolor=color.new(color.red, 0), offset=-pvtLenR) counthi = 0 countlo = 0 counthi := na(pvthi) ? nz(counthi[1]) + 1 : 0 countlo := na(pvtlo) ? nz(countlo[1]) + 1 : 0 pvthis = 0.0 pvtlos = 0.0 pvthis := na(pvthi) ? pvthis[1] : high[pvtLenR] pvtlos := na(pvtlo) ? pvtlos[1] : low[pvtLenR] hipc = pvthis != pvthis[1] ? na : color.new(color.red, 50) lopc = pvtlos != pvtlos[1] ? na : color.new(color.green, 50) // } // VWAP { hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings") var anchor = input.string(defval = "Session", title="Anchor Period", options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings") src = input(title = "Source", defval = hlc3, group="VWAP Settings") offset = input(0, title="Offset", group="VWAP Settings") showBand_1 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_1") stdevMult_1 = input(1.0, title="Bands Multiplier #1", group="Standard Deviation Bands Settings", inline="band_1") showBand_2 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_2") stdevMult_2 = input(2.0, title="Bands Multiplier #2", group="Standard Deviation Bands Settings", inline="band_2") showBand_3 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_3") stdevMult_3 = input(3.0, title="Bands Multiplier #3", group="Standard Deviation Bands Settings", inline="band_3") if vwaponoff and barstate.islast and ta.cum(volume) == 0 runtime.error("No volume is provided by the data vendor.") new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true) isNewPeriod = switch anchor "Earnings" => not na(new_earnings) "Dividends" => not na(new_dividends) "Splits" => not na(new_split) "Session" => timeframe.change("D") "Week" => timeframe.change("W") "Month" => timeframe.change("M") "Quarter" => timeframe.change("3M") "Year" => timeframe.change("12M") "Decade" => timeframe.change("12M") and year % 10 == 0 "Century" => timeframe.change("12M") and year % 100 == 0 => false isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits" if vwaponoff and na(src[1]) and not isEsdAnchor isNewPeriod := true float vwapValue = na float upperBandValue1 = na float lowerBandValue1 = na float upperBandValue2 = na float lowerBandValue2 = na float upperBandValue3 = na float lowerBandValue3 = na if vwaponoff and not (hideonDWM and timeframe.isdwm) [_vwap, _stdevUpper, _] = ta.vwap(src, isNewPeriod, 1) vwapValue := _vwap stdevAbs = _stdevUpper - _vwap upperBandValue1 := _vwap + stdevAbs * stdevMult_1 lowerBandValue1 := _vwap - stdevAbs * stdevMult_1 upperBandValue2 := _vwap + stdevAbs * stdevMult_2 lowerBandValue2 := _vwap - stdevAbs * stdevMult_2 upperBandValue3 := _vwap + stdevAbs * stdevMult_3 lowerBandValue3 := _vwap - stdevAbs * stdevMult_3 plot(vwapValue, title="VWAP", color=#2962FF, offset=offset) // } // Bullish Engulfing , Bearish Candle { bullEnHeight = input.int(title='Height', minval=1, maxval=100, step=1, defval=10, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='1') bullEnAbove = input.int(title=' | Above', minval=1, maxval=100, step=1, defval=3, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='1') bullEnBelow = input.int(title=' | Below', minval=1, maxval=100, step=1, defval=1, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='1') bearEnHeight = input.int(title='Height', minval=1, maxval=100, step=1, defval=10, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='2') bearEnAbove = input.int(title=' | Above', minval=1, maxval=100, step=1, defval=3, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='2') bearEnBelow = input.int(title=' | Below', minval=1, maxval=100, step=1, defval=1, confirm=false, group = 'BULLISH & BEARISH ENGULFING', inline='2') bullEngulfing = (open[1] - close[1]) / syminfo.mintick >= bullEnHeight and close > open and (close - open[1]) / syminfo.mintick >= bullEnAbove and (close[1] - open) / syminfo.mintick >= bullEnBelow bearEngulfing = (close[1] - open[1]) / syminfo.mintick >= bearEnHeight and close < open and (open - close[1]) / syminfo.mintick >= bearEnAbove and (open[1] - close) / syminfo.mintick >= bearEnBelow plotshape(bullbearEnOp ? bullEngulfing : na, title='Bull Engulfing', style=shape.cross, location=location.abovebar, color=color.new(color.green, 0), size=size.tiny, editable=true, text='️', offset=-1) plotshape(bullbearEnOp ? bearEngulfing : na, title='Bear Engulfing', style=shape.xcross, location=location.belowbar, color=color.new(color.red, 0), size=size.tiny, text='', offset=-1) // } // Filigran { title = input.string('BARBARIANS TRADING CLUB', 'Tittle', group='FILIGRAN') subtitle = input.string('www.barbarianstrading.com', 'Subtitle', group='FILIGRAN') symInfoCheck = input.bool(title='Show Symbol Info', defval=true, group='watermark position') symInfo = syminfo.ticker + ' | ' + timeframe.period + (timeframe.isminutes ? 'M' : na) date = str.tostring(dayofmonth(time_close)) + '/' + str.tostring(month(time_close)) + '/' + str.tostring(year(time_close)) textVPosition = input.string('top', 'Vertical', options=['top', 'middle', 'bottom'], group='watermark position') textHPosition = input.string('center', 'Horizontal', options=['left', 'center', 'right'], group='watermark position') symVPosition = input.string('bottom', 'Vertical', options=['top', 'middle', 'bottom'], group='symbol position') symHPosition = input.string('center', 'Horizontal', options=['left', 'center', 'right'], group='symbol position') width = input.int(0, 'Width', minval=0, maxval=100, tooltip='The width of the cell as a % of the indicator\'s visual space. Optional. By default, auto-adjusts the width based on the text inside the cell. Value 0 has the same effect.', group='cell size') height = input.int(0, 'Height', minval=0, maxval=100, tooltip='The height of the cell as a % of the indicator\'s visual space. Optional. By default, auto-adjusts the height based on the text inside of the cell. Value 0 has the same effect.', group='cell size') c_title = input.color(color.new(color.black, 0), 'Title Color', group='title settings') s_title = input.string('normal', 'Title Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='title settings') a_title = input.string('center', 'Title Alignment', options=['center', 'left', 'right'], group='title settings') c_subtitle = input.color(color.new(color.black, 30), 'Subitle Color', group='subtitle settings') s_subtitle = input.string('small', 'Subtitle Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='subtitle settings') a_subtitle = input.string('center', 'Subtitle Alignment', options=['center', 'left', 'right'], group='subtitle settings') c_symInfo = input.color(color.new(color.black, 30), 'Subitle Color', group='symbol settings') s_symInfo = input.string('small', 'Subtitle Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='symbol settings') a_symInfo = input.string('center', 'Subtitle Alignment', options=['center', 'left', 'right'], group='symbol settings') c_bg = input.color(color.new(color.blue, 100), 'Background', group='background') textWatermark = table.new(textVPosition + '_' + textHPosition, 1, 3) table.cell(textWatermark, 0, 0, title, width, height, c_title, a_title, text_size=s_title, bgcolor=c_bg) table.cell(textWatermark, 0, 1, subtitle, width, height, c_subtitle, a_subtitle, text_size=s_subtitle, bgcolor=c_bg) symWatermark = table.new(symVPosition + '_' + symHPosition, 5, 5) if filigran and symInfoCheck == true table.cell(symWatermark, 0, 1, symInfo, width, height, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg) table.cell(symWatermark, 0, 0, date, width, height, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg) // }