AlgoRyze Pro-Sol

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 23

//@version=5

Indicator = '📈 AlgoRyze Pro'


indicator(Indicator, shorttitle=Indicator, overlay = true, max_labels_count = 500,
max_boxes_count = 500, max_lines_count = 500, max_bars_back = 1000)

Mode = input.string("Scalp", "Trade Mode", options = ["Swing", "Scalp",


"Manual"], group = 'Signals')
Swing = Mode == "Swing"
Scalp = Mode == "Scalp"

// INDICATOR SETTINGS
show_weak = input.bool (false, 'Weak Buys/Sells (Swing Mode)',
group = 'Signals')
swing_length = 10 //input.int (10, 'Swing High/Low Length', group =
'Settings', minval = 1, maxval = 50)

show_sd = input.bool (true, 'Supply/Demand Zones',


group = 'Supply/Demand Zones', inline='1')
extend_zone = input.bool (false, 'Extend',
group = 'Supply/Demand Zones', inline='1')
supply_col = input.color(color.new(#ca006d,80), 'Supply ',
group = 'Supply/Demand Zones', inline = '3')
sup_out_col = input.color(color.new(#ca006d, 100), 'Outline',
group = 'Supply/Demand Zones', inline = '3')
demand_col = input.color(color.new(#00FFFF,80), 'Demand',
group = 'Supply/Demand Zones', inline = '4')
dem_out_col = input.color(color.new(#00FFFF,100), 'Outline',
group = 'Supply/Demand Zones', inline = '4')
box_width = input.float (10, 'Width', minval=1, maxval=20, step=1,
group = 'Supply/Demand Zones')
hist_to_keep = input.int (20, 'History To Keep', minval=5, maxval=50,
group = 'Supply/Demand Zones')

// AlgoRyz Oscillator Settings


OB1 = 53 //input.float (53, 'OB Levels', minval=-100, maxval=100,
inline="ob levels", group='AlgoRyze Oscillator')
OB2 = 88 //input.float (88, '', minval=-100, maxval=100, inline="ob
levels", group='AlgoRyze Oscillator')
OS1 = -58 //input.float (-58, 'OS Levels', minval=-100, maxval=100,
inline="os levels", group='AlgoRyze Oscillator')
OS2 = -93 //input.float (-93, '', minval=-100, maxval=100, inline="os
levels" , group='AlgoRyze Oscillator')

// INDICATOR VISUAL SETTINGS


show_zigzag = input.bool (false, 'Zig Zag', group =
'Price Action', inline = '1')
zigzag_col = input.color (color.gray, '', group =
'Price Action', inline = '1')
show_pa_labels = input.bool( false, 'Price Action Labels', group =
'Price Action', inline = '2')
show_broken = input.bool (false, "Broken Levels", group =
'Break of Structure', inline = '1')
bos_color_top = input.color (color.new(#ca006d,75), "Resistance", group =
'Break of Structure', inline = '2')
bos_color_bot = input.color (color.new(#00FFFF,75), "Support", group =
'Break of Structure', inline = '2')
bos_label_col = input.color (color.gray, 'Label', group =
'Break of Structure', inline = '2')
s_poi_label_col = color.red //input.color(color.red, 'POI Labels', group =
'Price Action', inline = '7')
d_poi_label_col = color.green //input.color(color.green, '', group =
'Price Action', inline = '7')

//swing_type_col = input.color(color.orange, 'Swing Label', group =


'Price Action', inline = '8')
ma_src = input.source (close, "Source",
group="Moving Averages")
show_ma1 = input.bool (true, "",
group="Moving Averages", inline="ma1")
ma1_length = input.int (50, "MA",
group="Moving Averages", inline="ma1")
ma1_type = input.string ("EMA", "Type", options=["SMA", "EMA", "VWMA",
"WMA", "HMA", "RMA"],
group="Moving Averages", inline="ma1", tooltip="Main")
show_ma2 = input.bool (true, "",
group="Moving Averages", inline="ma2")
ma2_length = input.int (150, "MA",
group="Moving Averages", inline="ma2")
ma2_type = input.string("EMA", "Type", options=["SMA", "EMA", "VWMA", "WMA",
"HMA", "RMA"],
group="Moving Averages", inline="ma2", tooltip="Main")
show_fill = true //input.bool (true, "Fill ",
group="Moving Averages")
ma1_color_up = input.color (color.new(#4caf50, 60), "",
group="Moving Averages", inline="ma1")
ma2_color_up = input.color (color.new(#2962ff, 60), "",
group="Moving Averages", inline="ma2")
ma1_color_dn = input.color (color.new(#e91e63, 60), "",
group="Moving Averages", inline="ma1")
ma2_color_dn = input.color (color.new(#673ab7, 60), "",
group="Moving Averages", inline="ma2")

diff_len = 500 // input.int(500, "Difference Calculation Length",


group="Moving Averages")
mult = 1.5 // input.float(1.5, "Standard Deviation Multiplier", step=.1,
group="Moving Averages")

table_size = input.string ("Large", 'Size', group =


'AlgoRyze Multi-TF Table', inline = '10', options=["Small", "Large", "Disable"])
TableSize = table_size == "Small" ? size.small : size.normal
table_text = "Simple" // input.string("Simple", title="Table Values",
options=["Simple", "Advanced"])

//-----<WTO>-------------------------------------------------//
//Swing = input.bool(true, 'Show Algo Osc Signals', group='Oscillator
Divergence')
wto_channel = 10 //input.int(10, 'ARO Channel', minval=1, group='Oscillator
Divergence')
wto_len = 21 //input.int(21, 'ARO Length', minval=1, group='Oscillator
Divergence')
RightBars = 5 //input.int(5, 'Right Bars', minval=1, group='Oscillator
Divergence')
LeftBars = 5 //input.int(5, 'Left Bars', minval=1, group='Oscillator
Divergence')
show_reg_div = input.bool (true, "Regular ",
group='Divergences', inline="Divergence")
show_hid_lab = input.bool (false, "Hidden ",
group='Divergences', inline="Divergence")

Extend_Zone = extend_zone ? extend.both : extend.right

//////////Colors
color ForrestGreen = color.new(#228B22,0)
color Lime = color.new(#00FF00,0)
color Red = color.new(#FF0000,0)
color Crimson = color.new(#DC143C,0)
AR_Down_Dark = color.new(#1da11f, 0)
AR_Down_Bright = color.new(#1ddd33, 0)
AR_Up_Dark = color.new(#8a00ff, 0)
AR_Up_Bright = color.new(#be80ff, 0)
AgloRyzeColor = color.new(#6FC4AF, 0)
color sw_color_up = Crimson
color sw_color_down = ForrestGreen

//END SETTINGS

//VARS/FUNCTIONS
var int Trend = 0

// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY


f_array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)

// FUNCTION SWING H & L LABELS


f_sh_sl_labels(array, swing_type) =>

var string label_text = na


if swing_type == 1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HH'
else
label_text := 'LH'
//label.new(bar_index - swing_length, array.get(array,0), text =
label_text, style=label.style_label_down, textcolor = swing_type_col, color =
color.new(swing_type_col, 100), size = size.small)
label.new(bar_index - swing_length, array.get(array,0), text = label_text,
style=label.style_label_down, textcolor = sw_color_up, color =
color.new(sw_color_up, 100), size = size.normal)

else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
//label.new(bar_index - swing_length, array.get(array,0), text =
label_text, style=label.style_label_up, textcolor = swing_type_col, color =
color.new(swing_type_col, 100), size = size.small)
label.new(bar_index - swing_length, array.get(array,0), text = label_text,
style=label.style_label_up, textcolor = sw_color_down, color =
color.new(sw_color_down,100), size = size.normal)

// FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING


f_check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true

for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2

upper_boundary = poi + atr_threshold


lower_boundary = poi - atr_threshold

if new_poi >= lower_boundary and new_poi <= upper_boundary


okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw

// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE


f_supply_demand(value_array, bn_array, box_array, line_array, box_type, atr) =>

atr_buffer = atr * (box_width / 10)


box_left = array.get(bn_array, 0)
box_right = bar_index

var float box_top = 0.00


var float box_bottom = 0.00
var float poi = 0.00

if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2

okay_to_draw = f_check_overlapping(poi, box_array, atr)


//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = sup_out_col,
bgcolor = supply_col, extend = Extend_Zone, text = '▼ SUPPLY ▼',
text_halign = text.align_right, text_valign = text.align_center, text_color =
s_poi_label_col, text_size = size.small, xloc = xloc.bar_index))

line.delete( array.get(line_array, array.size(line_array) - 1) )


f_array_add_pop(line_array, line.new(x1 = box_left, y1 = poi, x2 =
box_right, y2 = poi, color = color.new(supply_col,0),
extend = Extend_Zone, xloc = xloc.bar_index, style=line.style_dotted))

else if box_type == -1 and okay_to_draw


box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = dem_out_col,
bgcolor = demand_col, extend = Extend_Zone, text = '▲ DEMAND ▲',
text_halign = text.align_right, text_valign = text.align_center, text_color =
d_poi_label_col, text_size = size.small, xloc = xloc.bar_index))

line.delete( array.get(line_array, array.size(line_array) - 1) )


f_array_add_pop(line_array, line.new(x1 = box_left, y1 = poi, x2 =
box_right, y2 = poi, color = color.new(demand_col,0),
extend = Extend_Zone, xloc = xloc.bar_index, style=line.style_dotted))

// FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN


f_sd_to_bos(box_array, bos_array, line_array, zone_type) =>

if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
// if ta.crossover(close, level_to_break)
if close >= level_to_break
if show_broken
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_border_color(array.get(bos_array,0), bos_color_top)
box.set_bgcolor(array.get(bos_array,0), bos_color_top)
box.set_border_style(array.get(bos_array,0), line.style_dotted)
// box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_col)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_right)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
line.delete(array.get(line_array, i))

if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
// if ta.crossunder(close, level_to_break)
if close <= level_to_break
if show_broken
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_border_color(array.get(bos_array,0), bos_color_bot)
box.set_bgcolor(array.get(bos_array,0), bos_color_bot)
box.set_border_style(array.get(bos_array,0), line.style_dotted)
// box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_col)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_right)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
line.delete(array.get(line_array, i))

// FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT


f_Extend_Zone_endpoint(box_array) =>

for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 100)
//END FUNCTIONS

//CALCULATIONS

// CALCULATE ATR
atr = ta.atr(50)

// CALCULATE SWING HIGHS & SWING LOWS


swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)

// ARRAYS FOR SWING H/L & BN


var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)

var swing_high_bns = array.new_int(5,0)


var swing_low_bns = array.new_int(5,0)

// ARRAYS FOR SUPPLY / DEMAND


var current_supply_box = array.new_box(hist_to_keep, na)
var current_demand_box = array.new_box(hist_to_keep, na)

// ARRAYS FOR SUPPLY / DEMAND POI LABELS


var current_supply_poi = array.new_line(hist_to_keep, na)
var current_demand_poi = array.new_line(hist_to_keep, na)

// ARRAYS FOR BOS


var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
//
//END CALCULATIONS
//

// NEW SWING HIGH


if not na(swing_high)

//MANAGE SWING HIGH VALUES


f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index[swing_length])
if show_pa_labels
f_sh_sl_labels(swing_high_values, 1)
if show_sd
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box,
current_supply_poi, 1, atr)

// NEW SWING LOW


else if not na(swing_low)

//MANAGE SWING LOW VALUES


f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index[swing_length])
if show_pa_labels
f_sh_sl_labels(swing_low_values, -1)

if show_sd
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box,
current_demand_poi, -1, atr)

if show_sd
f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)

f_Extend_Zone_endpoint(current_supply_box)
f_Extend_Zone_endpoint(current_demand_box)

//ZIG ZAG
h = ta.highest(high, swing_length * 2 + 1)
l = ta.lowest(low, swing_length * 2 + 1)
f_isMin(len) =>
l == low[len]
f_isMax(len) =>
h == high[len]

var dirUp = false


var lastLow = high * 100
var lastHigh = 0.0
var timeLow = bar_index
var timeHigh = bar_index
var line li = na

f_drawLine() =>
_li_color = show_zigzag ? zigzag_col : color.new(#ffffff,100)
line.new(timeHigh - swing_length, lastHigh, timeLow - swing_length, lastLow,
xloc.bar_index, color=_li_color, width=2)

if dirUp
if f_isMin(swing_length) and low[swing_length] < lastLow
lastLow := low[swing_length]
timeLow := bar_index
line.delete(li)
li := f_drawLine()
li

if f_isMax(swing_length) and high[swing_length] > lastLow


lastHigh := high[swing_length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li

if not dirUp
if f_isMax(swing_length) and high[swing_length] > lastHigh
lastHigh := high[swing_length]
timeHigh := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMin(swing_length) and low[swing_length] < lastHigh
lastLow := low[swing_length]
timeLow := bar_index
dirUp := true
li := f_drawLine()
if f_isMax(swing_length) and high[swing_length] > lastLow
lastHigh := high[swing_length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li

ma_type(_src, _len, _type)=>


float output = 0.0
if _type == "SMA"
output := ta.sma(_src, _len)
else if _type == "EMA"
output := ta.ema(_src, _len)
else if _type == "VWMA"
output := ta.vwma(_src, _len)
else if _type == "WMA"
output := ta.wma(_src, _len)
else if _type == "HMA"
output := ta.hma(_src, _len)
else if _type == "RMA"
output := ta.rma(_src, _len)
ma1 = ma_type(ma_src, ma1_length, ma1_type)
ma2 = ma_type(ma_src, ma2_length, ma2_type)

ma1_color = close > ma1[1] ? ma1_color_up : ma1_color_dn


ma2_color = close > ma2[1] ? ma2_color_up : ma2_color_dn

plot_ma1 = plot(show_ma1 ? ma1 : na, "ma1", color=color.new(ma1_color, 0))


plot_ma2 = plot(show_ma2 ? ma2 : na, "ma2", color=color.new(ma2_color, 0))

Moving_Average_Distance(_ma1, _ma2, _len, _mult, _ma1_color_up, _ma1_color_dn,


_ma2_color_up, _ma2_color_dn)=>
_ma_difference = _ma1-_ma2
_ma_diff_avg = ta.sma(_ma_difference, _len)
_ma_diff_stdev = ta.stdev(_ma_difference, _len)*_mult
_ma_top_val = _ma1 > _ma2 ? _ma2+_ma_diff_stdev : _ma2
_ma_bot_val = _ma1 > _ma2 ? _ma2 : _ma2-_ma_diff_stdev
_ma_top_top_color = _ma1_color_up
_ma_top_bottom_color = _ma2_color_up
_ma_bottom_top_color = _ma2_color_dn
_ma_bottom_bottom_color = _ma1_color_dn
_bullish_bearish = _ma1 > _ma2 ? 1 : -1
_color = color.from_gradient(_ma1, _ma_bot_val, _ma_top_val, bottom_color =
_bullish_bearish == 1 ? _ma_top_bottom_color : _ma_bottom_bottom_color,
top_color=_bullish_bearish == 1 ? _ma_top_top_color : _ma_bottom_top_color)
_change = _ma1 > _ma1[1] ? 1 : _ma1 < _ma1[1] ? -1 : 0
[_ma_difference, _color, _bullish_bearish, _change]

ma2_difference = ma1-ma2
ma2_diff_avg = ta.sma(ma2_difference, diff_len)
ma2_diff_stdev = ta.stdev(ma2_difference, diff_len)*mult
ma2_top_val = ma1 > ma2 ? ma2+ma2_diff_stdev : ma2
ma2_bot_val = ma1 > ma2 ? ma2 : ma2-ma2_diff_stdev
ma2_top_top_color = ma1_color_up
ma2_top_bottom_color = ma2_color_up
ma2_bottom_top_color = ma2_color_dn
ma2_bottom_bottom_color = ma1_color_dn
bullish_bearish = ma1 > ma2 ? 1 : -1
change = ma1 > ma1[1] ? 1 : ma1 < ma1[1] ? -1 : 0
chart_color = color.from_gradient(ma1, ma2_bot_val, ma2_top_val, bottom_color =
bullish_bearish == 1 ? ma2_top_bottom_color : ma2_bottom_bottom_color,
top_color=bullish_bearish == 1 ? ma2_top_top_color : ma2_bottom_top_color)

//WTO stuff
wtSource =hlc3
wt(ap,n1,n2) =>
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1,4)
//scale to 0-100
wt3 = math.avg(wt2,wt1)

[wt1,wt2, wt3]
[wt1,wt2, wt3] = wt(wtSource,wto_channel,wto_len)

//Signals
Trend := ma1 > ma2 ? 1 : ma1 < ma2 ? -1 : Trend

isOverbought = wt1 > OB1


isOversold = wt1 < OS1

wt_xOver = ta.crossover(wt1, wt2)


wt_xUnder = ta.crossunder(wt1, wt2)

Scalp_BUY = Scalp and wt_xOver and not isOverbought


Scalp_SELL = Scalp and wt_xUnder and not isOversold

Swing_BUY = Swing and Trend == 1 and ta.crossover(wt1, wt2) and not


isOverbought
Swing_SELL = Swing and Trend == -1 and ta.crossunder(wt1, wt2) and not
isOversold

Swing_SELL_W = Swing and Trend == 1 and ta.crossunder(wt1, wt2) and not


isOversold and show_weak
Swing_BUY_W = Swing and Trend == -1 and ta.crossover(wt1, wt2) and not
isOverbought and show_weak

//plot(wt1, "wt1", color=color.yellow)


//plot(wt2, "wt2", color=color.aqua)

// '♦'
// '△' '▽'

plotchar(Swing_BUY, "Swing Buy", color = color.green, location =


location.belowbar, size = size.small, char = '▲')
plotchar(Swing_SELL, "Swing Sell", color = color.rgb(204, 36, 226), location =
location.abovebar, size = size.small, char = '▼')

plotchar(Swing_BUY_W, "Swing Buy", color = color.green, location =


location.belowbar, size = size.small, char = '△')
plotchar(Swing_SELL_W,"Swing Sell", color = color.rgb(202, 30, 174), location =
location.abovebar, size = size.small, char = '▽')

plotchar(Scalp_BUY, "Scalp Buy", color = color.green, location =


location.belowbar, size = size.small, char = '❖')
plotchar(Scalp_SELL, "Scalp Sell", color = color.rgb(184, 33, 159), location =
location.abovebar, size = size.small, char = '❖')

//alerts
// alertcondition(Swing_BUY, title='Swing Buy', message='Swing Buy')
// alertcondition(Swing_SELL, title='Swing Sell', message='Swing Sell')
// alertcondition(Swing_BUY_W, title='Weak Swing Buy', message='Weak Swing Buy')
// alertcondition(Swing_SELL_W,title='Weak Swing Sell',message='Weak Swing Sell')

scalp_test = close > close[1]


// alertcondition(scalp_test, title='scalp_test', message='scalp_test')
// alertcondition(Scalp_BUY, title='Scalp Buy', message='Scalp Buy')
// alertcondition(Scalp_SELL, title='Scalp Sell', message='Scalp Sell')

//Alerts
alertSwings = input.bool (true, 'Swing Buy/Sell',
group='Alerts')
alertWeaK = input.bool (false, 'Weak Swing Buy/Sell',
group='Alerts')
alertScalps = input.bool (false, 'Scalp Buy/Sell',
group='Alerts')

if Swing_BUY and alertSwings


alert("Swing Buy", alert.freq_once_per_bar_close)
if Swing_SELL and alertSwings
alert("Swing Sell", alert.freq_once_per_bar_close)
if Swing_BUY_W and alertWeaK
alert("Swing Buy W", alert.freq_once_per_bar_close)
if Swing_SELL_W and alertWeaK
alert("Swing Sell W", alert.freq_once_per_bar_close)
if Scalp_BUY and alertScalps
alert("Scalp Buy", alert.freq_once_per_bar_close)
if Scalp_SELL and alertScalps
alert("Scalp Sell", alert.freq_once_per_bar_close)

fill(plot_ma1, plot_ma2, show_fill ? ma2_top_val : na, show_fill ? ma2_bot_val :


na, top_color=ma1 > ma2 ? ma2_top_top_color : ma2_bottom_top_color,
bottom_color=ma1 > ma2 ? ma2_top_bottom_color : ma2_bottom_bottom_color)

type bar
float difference
color color_gradient
int direction
int change

bar_1m = bar.new()
bar_3m = bar.new()
bar_5m = bar.new()
bar_15m = bar.new()
bar_30m = bar.new()
bar_60m = bar.new()
bar_120m = bar.new()
bar_240m = bar.new()
bar_360m = bar.new()
bar_720m = bar.new()
bar_1440m = bar.new()
bar_1m_lower_string = (timeframe.isminutes and timeframe.multiplier > 1) or
timeframe.isdaily ? "1" : na
[diff_1m_array, color_1m_array, bb_1m_array, change_1m_array] =
request.security_lower_tf(syminfo.tickerid, bar_1m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_1m_higher_string = timeframe.isminutes and timeframe.multiplier <= 1 or
timeframe.isseconds ? "1" : na
[diff_1m_value, color_1m_value, bb_1m_value, change_1m_value] =
request.security(syminfo.tickerid, bar_1m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_3m_lower_string = (timeframe.isminutes and timeframe.multiplier > 3) or


timeframe.isdaily ? "3" : na
[diff_3m_array, color_3m_array, bb_3m_array, change_3m_array] =
request.security_lower_tf(syminfo.tickerid, bar_3m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_3m_higher_string = timeframe.isminutes and timeframe.multiplier <= 3 or
timeframe.isseconds ? "3" : na
[diff_3m_value, color_3m_value, bb_3m_value, change_3m_value] =
request.security(syminfo.tickerid, bar_3m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_5m_lower_string = (timeframe.isminutes and timeframe.multiplier > 5) or


timeframe.isdaily ? "5" : na
[diff_5m_array, color_5m_array, bb_5m_array, change_5m_array] =
request.security_lower_tf(syminfo.tickerid, bar_5m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_5m_higher_string = timeframe.isminutes and timeframe.multiplier <= 5 or
timeframe.isseconds ? "5" : na
[diff_5m_value, color_5m_value, bb_5m_value, change_5m_value] =
request.security(syminfo.tickerid, bar_5m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_15m_lower_string = (timeframe.isminutes and timeframe.multiplier > 15) or


timeframe.isdaily ? "15" : na
[diff_15m_array, color_15m_array, bb_15m_array, change_15m_array] =
request.security_lower_tf(syminfo.tickerid, bar_15m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_15m_higher_string = timeframe.isminutes and timeframe.multiplier <= 15 or
timeframe.isseconds ? "15" : na
[diff_15m_value, color_15m_value, bb_15m_value, change_15m_value] =
request.security(syminfo.tickerid, bar_15m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_30m_lower_string = (timeframe.isminutes and timeframe.multiplier > 30) or


timeframe.isdaily ? "30" : na
[diff_30m_array, color_30m_array, bb_30m_array, change_30m_array] =
request.security_lower_tf(syminfo.tickerid, bar_30m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_30m_higher_string = timeframe.isminutes and timeframe.multiplier <= 30 or
timeframe.isseconds ? "30" : na
[diff_30m_value, color_30m_value, bb_30m_value, change_30m_value] =
request.security(syminfo.tickerid, bar_30m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_60m_lower_string = (timeframe.isminutes and timeframe.multiplier > 60) or


timeframe.isdaily ? "60" : na
[diff_60m_array, color_60m_array, bb_60m_array, change_60m_array] =
request.security_lower_tf(syminfo.tickerid, bar_60m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_60m_higher_string = timeframe.isminutes and timeframe.multiplier <= 60 or
timeframe.isseconds ? "60" : na
[diff_60m_value, color_60m_value, bb_60m_value, change_60m_value] =
request.security(syminfo.tickerid, bar_60m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_120m_lower_string = (timeframe.isminutes and timeframe.multiplier > 120) or


timeframe.isdaily ? "120" : na
[diff_120m_array, color_120m_array, bb_120m_array, change_120m_array] =
request.security_lower_tf(syminfo.tickerid, bar_120m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_120m_higher_string = timeframe.isminutes and timeframe.multiplier <= 120 or
timeframe.isseconds ? "120" : na
[diff_120m_value, color_120m_value, bb_120m_value, change_120m_value] =
request.security(syminfo.tickerid, bar_120m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_240m_lower_string = (timeframe.isminutes and timeframe.multiplier > 240) or


timeframe.isdaily ? "240" : na
[diff_240m_array, color_240m_array, bb_240m_array, change_240m_array] =
request.security_lower_tf(syminfo.tickerid, bar_240m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_240m_higher_string = timeframe.isminutes and timeframe.multiplier <= 240 or
timeframe.isseconds ? "240" : na
[diff_240m_value, color_240m_value, bb_240m_value, change_240m_value] =
request.security(syminfo.tickerid, bar_240m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_360m_lower_string = (timeframe.isminutes and timeframe.multiplier > 360) or


timeframe.isdaily ? "360" : na
[diff_360m_array, color_360m_array, bb_360m_array, change_360m_array] =
request.security_lower_tf(syminfo.tickerid, bar_360m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_360m_higher_string = timeframe.isminutes and timeframe.multiplier <= 360 or
timeframe.isseconds ? "360" : na
[diff_360m_value, color_360m_value, bb_360m_value, change_360m_value] =
request.security(syminfo.tickerid, bar_360m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_720m_lower_string = (timeframe.isminutes and timeframe.multiplier > 720) or
timeframe.isdaily ? "720" : na
[diff_720m_array, color_720m_array, bb_720m_array, change_720m_array] =
request.security_lower_tf(syminfo.tickerid, bar_720m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_720m_higher_string = timeframe.isminutes and timeframe.multiplier <= 720 or
timeframe.isseconds ? "720" : na
[diff_720m_value, color_720m_value, bb_720m_value, change_720m_value] =
request.security(syminfo.tickerid, bar_720m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

bar_1440m_lower_string = (timeframe.isminutes and timeframe.multiplier > 1440) or


timeframe.isdaily ? "1440" : na
[diff_1440m_array, color_1440m_array, bb_1440m_array, change_1440m_array] =
request.security_lower_tf(syminfo.tickerid, bar_1440m_lower_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))
bar_1440m_higher_string = timeframe.isminutes and timeframe.multiplier <= 1440 or
timeframe.isseconds ? "1440" : na
[diff_1440m_value, color_1440m_value, bb_1440m_value, change_1440m_value] =
request.security(syminfo.tickerid, bar_1440m_higher_string,
Moving_Average_Distance(ma1, ma2, diff_len, mult, ma1_color_up, ma1_color_dn,
ma2_color_up, ma2_color_dn))

//TODO SECURITY SWAPS

if barstate.islast
if timeframe.isminutes or timeframe.isdaily
if (timeframe.multiplier > 1 or timeframe.isdaily) and
array.size(diff_1m_array) > 0
bar_1m := bar.new(array.last(diff_1m_array),
array.last(color_1m_array), array.last(bb_1m_array), array.last(change_1m_array))
if (timeframe.multiplier > 3 or timeframe.isdaily) and
array.size(diff_3m_array) > 0
bar_3m := bar.new(array.last(diff_3m_array),
array.last(color_3m_array), array.last(bb_3m_array), array.last(change_3m_array))
if (timeframe.multiplier > 5 or timeframe.isdaily) and
array.size(diff_5m_array) > 0
bar_5m := bar.new(array.last(diff_5m_array),
array.last(color_5m_array), array.last(bb_5m_array), array.last(change_5m_array))
if (timeframe.multiplier > 15 or timeframe.isdaily) and
array.size(diff_15m_array) > 0
bar_15m := bar.new(array.last(diff_15m_array),
array.last(color_15m_array), array.last(bb_15m_array),
array.last(change_15m_array))
if (timeframe.multiplier > 30 or timeframe.isdaily) and
array.size(diff_30m_array) > 0
bar_30m := bar.new(array.last(diff_30m_array),
array.last(color_30m_array), array.last(bb_30m_array),
array.last(change_30m_array))
if (timeframe.multiplier > 60 or timeframe.isdaily) and
array.size(diff_60m_array) > 0
bar_60m := bar.new(array.last(diff_60m_array),
array.last(color_60m_array), array.last(bb_60m_array),
array.last(change_60m_array))
if (timeframe.multiplier > 120 or timeframe.isdaily) and
array.size(diff_120m_array) > 0
bar_120m := bar.new(array.last(diff_120m_array),
array.last(color_120m_array), array.last(bb_120m_array),
array.last(change_120m_array))
if (timeframe.multiplier > 240 or timeframe.isdaily) and
array.size(diff_240m_array) > 0
bar_240m := bar.new(array.last(diff_240m_array),
array.last(color_240m_array), array.last(bb_240m_array),
array.last(change_240m_array))
if (timeframe.multiplier > 360 or timeframe.isdaily) and
array.size(diff_360m_array) > 0
bar_360m := bar.new(array.last(diff_360m_array),
array.last(color_360m_array), array.last(bb_360m_array),
array.last(change_360m_array))
if (timeframe.multiplier > 720 or timeframe.isdaily) and
array.size(diff_720m_array) > 0
bar_720m := bar.new(array.last(diff_720m_array),
array.last(color_720m_array), array.last(bb_720m_array),
array.last(change_720m_array))
if (timeframe.multiplier > 1440 or timeframe.isdaily) and
array.size(diff_1440m_array) > 0
bar_1440m := bar.new(array.last(diff_1440m_array),
array.last(color_1440m_array), array.last(bb_1440m_array),
array.last(change_1440m_array))

if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 1)


bar_1m := bar.new(diff_1m_value, color_1m_value, bb_1m_value,
change_1m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 3)
bar_3m := bar.new(diff_3m_value, color_3m_value, bb_3m_value,
change_3m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 5)
bar_5m := bar.new(diff_5m_value, color_5m_value, bb_5m_value,
change_5m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 15)
bar_15m := bar.new(diff_15m_value, color_15m_value, bb_15m_value,
change_15m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 30)
bar_30m := bar.new(diff_30m_value, color_30m_value, bb_30m_value,
change_30m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 60)
bar_60m := bar.new(diff_60m_value, color_60m_value, bb_60m_value,
change_60m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 120)
bar_120m := bar.new(diff_120m_value, color_120m_value, bb_120m_value,
change_120m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 240)
bar_240m := bar.new(diff_240m_value, color_240m_value, bb_240m_value,
change_240m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 360)
bar_360m := bar.new(diff_360m_value, color_360m_value, bb_360m_value,
change_360m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <= 720)
bar_720m := bar.new(diff_720m_value, color_720m_value, bb_720m_value,
change_720m_value)
if timeframe.isseconds or (timeframe.isminutes and timeframe.multiplier <=
1440)
bar_1440m := bar.new(diff_1440m_value, color_1440m_value, bb_1440m_value,
change_1440m_value)
build_text(string _text_input_style, _diff_value, _bb_value)=>
output_text = ""
if _text_input_style == "Simple"
output_text:=_bb_value > 0 ? "Bullish" : _bb_value < 0 ? "Bearish" :
"Error"
else
output_text:=str.tostring(_diff_value)
output_text

build_text_color(_bb_value)=>
color text_color = _bb_value > 0 ? color.lime : _bb_value < 0 ? color.red :
color.yellow
text_color

build_dot_color(_change_value, _bb_value)=>
dot_color = color.new(color.aqua, 0)
if _bb_value > 0
if _change_value > 0
dot_color := color.new(color.green, 0)
if _change_value < 0
dot_color := color.new(color.green, 75)
if _change_value == 0
dot_color:= color.new(color.yellow, 50)

if _bb_value < 0
if _change_value > 0
dot_color := color.new(color.red, 75)
if _change_value < 0
dot_color := color.new(color.red, 0)
if _change_value == 0
dot_color:= color.new(color.yellow, 50)
dot_color

//Position = table_size == "Small" ? position.middle_right : position.top_right


string Position = position.top_right
var Dashboard_table = table.new(Position, 3, 15, bgcolor=color.new(#252525, 25),
frame_color=color.black,frame_width=5, border_color=color.black)
if barstate.islast and table_size != "Disable"

//Table Header
//col row
table.cell(Dashboard_table, 0, 0, text="📈 Trend Table",
text_halign=text.align_center, text_color=AgloRyzeColor)
table.cell(Dashboard_table, 1, 0, text=na, text_halign=text.align_center,
text_color=color.white)
//Merge header to center title
table.merge_cells(Dashboard_table, 0, 0, 1, 0)

//Table sub header


table.cell(Dashboard_table, 0, 1, text_size=TableSize, text="TimeFrame",
text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 1, text_size=TableSize, text="Trends",
text_halign=text.align_center, text_color=color.white)

//Table Data

table.cell(Dashboard_table, 0, 5, text_size=TableSize, text="5 min:",


text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 5, text_size=TableSize,
text=build_text(table_text, bar_5m.difference, bar_5m.direction),
text_halign=text.align_center, bgcolor=bar_5m.color_gradient,
text_color=build_text_color(bar_5m.direction))
table.cell(Dashboard_table, 2, 5, text_size=TableSize, text="●",
text_halign=text.align_left, text_color=build_dot_color(bar_5m.change,
bar_5m.direction))

table.cell(Dashboard_table, 0, 6, text_size=TableSize, text="15 min:",


text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 6, text_size=TableSize,
text=build_text(table_text, bar_15m.difference, bar_15m.direction),
text_halign=text.align_center, bgcolor=bar_15m.color_gradient,
text_color=build_text_color(bar_15m.direction))
table.cell(Dashboard_table, 2, 6, text_size=TableSize, text="●",
text_halign=text.align_left, text_color=build_dot_color(bar_15m.change,
bar_15m.direction))

table.cell(Dashboard_table, 0, 8, text_size=TableSize, text="1 H:",


text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 8, text_size=TableSize,
text=build_text(table_text, bar_60m.difference, bar_60m.direction),
text_halign=text.align_center, bgcolor=bar_60m.color_gradient,
text_color=build_text_color(bar_60m.direction))
table.cell(Dashboard_table, 2, 8, text_size=TableSize, text="●",
text_halign=text.align_left, text_color=build_dot_color(bar_60m.change,
bar_60m.direction))

table.cell(Dashboard_table, 0, 10, text_size=TableSize, text="4 H:",


text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 10, text_size=TableSize,
text=build_text(table_text, bar_240m.difference, bar_240m.direction),
text_halign=text.align_center, bgcolor=bar_240m.color_gradient,
text_color=build_text_color(bar_240m.direction))
table.cell(Dashboard_table, 2, 10, text_size=TableSize, text="●",
text_halign=text.align_left, text_color=build_dot_color(bar_240m.change,
bar_240m.direction))

table.cell(Dashboard_table, 0, 13, text_size=TableSize, text="1 D:",


text_halign=text.align_center, text_color=color.white)
table.cell(Dashboard_table, 1, 13, text_size=TableSize,
text=build_text(table_text, bar_1440m.difference, bar_1440m.direction),
text_halign=text.align_center, bgcolor=bar_1440m.color_gradient,
text_color=build_text_color(bar_1440m.direction))
table.cell(Dashboard_table, 2, 13, text_size=TableSize, text="●",
text_halign=text.align_left, text_color=build_dot_color(bar_1440m.change,
bar_1440m.direction))

//Removed looping to reduce load on every bar update


//resize text
// for i = 0 to 13isOverbought
// table.cell_set_text_size(Dashboard_table, 0, i, TableSize)
// table.cell_set_text_size(Dashboard_table, 1, i, TableSize)
// table.cell_set_text_size(Dashboard_table, 2, i, TableSize)
// Calculate WTO
// wtSource =hlc3
// esa = ta.ema(wtSource, wto_channel)
// d = ta.ema(math.abs(wtSource - esa), wto_channel)
// ci = (wtSource - esa) / (0.015 * d)
// tci = ta.ema(ci, wto_len)
// wt1 = tci
// wt2 = ta.sma(wt1,4)
// //scale to 0-100
// wt3 = math.avg(wt2,wt1)

var ph_time = 0
var pl_time = 0

///////////////////Signals

// Pivots
PH = ta.pivothigh(wt3, LeftBars, RightBars)
PL = ta.pivotlow(wt3, LeftBars, RightBars)

PH_fn = fixnan(PH)
PL_fn = fixnan(PL)

PH_chart = not na(PH) ? high[RightBars] : na


PL_chart = not na(PL) ? low[RightBars] : na
PH_chart_fn = fixnan(PH_chart)
PL_chart_fn = fixnan(PL_chart)

//Divergence Logic https://cryptopotato.com/wp-content/uploads/2019/01/divergence-


sheet2-min.jpg
//Regular Bearish | oscillator highs decreasing, main chart highs increasing
div_RBear = PH < PH_fn[1] and high[RightBars] > PH_chart_fn[1]

//Regular Bullish | oscillator lows increasing, main chart lows decreasing


div_RBull = PL > PL_fn[1] and low[RightBars] < PL_chart_fn[1]

//Hidden Bearish | Oscillator highs increasing, main chart highs decreasing


div_HBear = PH > PH_fn[1] and high[RightBars] < PH_chart_fn[1]

//Hidden Bullish | Oscillator lows decreasing, main chart lows increasing


div_HBull = PL < PL_fn[1] and low[RightBars] > PL_chart_fn[1]

bear_color = ma1_color_dn
bull_color = ma1_color_up
regular_style = line.style_solid
hidden_style = line.style_dotted
// var divergence_lines = array.new_line(250)
var divergence_labels = array.new_label(100)

if not na(PH) //and Swing


ph_time:=time[RightBars]
if div_RBear
if show_reg_div
array.push(divergence_labels, label.new(
x = time[RightBars],
y = high[RightBars],
style=label.style_label_down,
size=size.small,
xloc=xloc.bar_time,
text="D\n \n ",
color=color.new(color.red, 80),
textcolor=color.silver))
label.delete(array.shift(divergence_labels))
if div_HBear
if show_hid_lab
array.push(divergence_labels, label.new(
x = time[RightBars],
y = high[RightBars],
style=label.style_label_down,
size=size.small,
xloc=xloc.bar_time,
text="hD\n \n ",
color=color.new(color.red, 80),
textcolor=color.silver))
label.delete(array.shift(divergence_labels))
if not na(PL)
pl_time:=time[RightBars]
if div_RBull
if show_reg_div
array.push(divergence_labels, label.new(
x = time[RightBars],
y = low[RightBars],
style=label.style_label_up,
size=size.small,
xloc=xloc.bar_time,
text="\n \n D",
color=color.new(color.green,88),
textcolor=color.silver))
label.delete(array.shift(divergence_labels))
if div_HBull
if show_hid_lab
array.push(divergence_labels, label.new(
x = time[RightBars],
y = low[RightBars],
style=label.style_label_up,
size=size.small,
xloc=xloc.bar_time,
text="\n \n hD",
color=color.new(color.green,88),
textcolor=color.silver))
label.delete(array.shift(divergence_labels))

//Temp fix to remove Supply/Demand


all_boxes = box.all
all_lines = line.all
//if not show_sd
//for [index,array_value] in all_boxes
//box.delete(array.get(all_boxes,index))
//for [index,array_value] in all_lines
//line.delete(array.get(all_lines,index))
//06/27/2023 -- Cleaned code//removed commented functions
//-----<Version
Info>------------------------------------------------------------------------------
------------------------------<>
Group = Indicator
version = input.string("v1.0", options=["v1.0"], inline="1",
group=Group)
date = input.string("07/04/2023", options=["07/04/2023"], inline="1",
group=Group)
//ABC Патерн
//---------------------------------------------------------------------------------
------------------------------------------------{

//---------------------------------------------------------------------------------
-------------------------------------------------}
//супер тренд + свечи
//---------------------------------------------------------------------------------
------------------------------------{
// ** ---> Inputs ------------- {
var bool positive = false
var bool negative = false
string RSI_group = "RMI Settings"
string mom_group = "Range Vales"
string visual = "Visuals"
int Length = input(14,"RMI Length ",inline = "RMI",group =
RSI_group)
int pmom = input(66," Positive above",inline =
"rsi1",group =RSI_group )
int nmom = input(30,"Negative below",inline =
"rsi1",group =RSI_group )
bool filleshow = input(false,"Show Range MA ",inline =
"002",group =visual )
color bull = input(#00bcd4,"",inline = "002",group =visual
)
color bear = input(#ff5252,"",inline = "002",group =visual
)
float BarRange = high - low

up = ta.rma(math.max(ta.change(close), 0), Length)


down = ta.rma(-math.min(ta.change(close), 0), Length)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
mf = ta.mfi(hlc3, Length)
rsi_mfi = math.avg(rsi,mf)

//------------------- }

bool p_mom = rsi_mfi[1] < pmom and


rsi_mfi > pmom and
rsi_mfi > nmom and
ta.change(ta.ema(close,5)) > 0

bool n_mom = rsi_mfi < nmom and


ta.change(ta.ema(close,5)) < 0
// // ---> Momentums ------------- {

if p_mom
positive:= true
negative:= false

if n_mom
positive:= false
negative:= true

//
method _Band(int len)=>
math.min (ta.atr (len) * 0.3, close * (0.3/100)) [20] /2 * 8

Band = _Band(30)

method rangeMA(float Range,Prd)=>


weight = Range / math.sum(Range, Prd)
sum = math.sum(close * weight, Prd)
tw= math.sum(weight, Prd)
sum / tw

// Calculate the RWMA


rwma = rangeMA(BarRange,20)

// Plotting the RWMA.


colour = positive ? bull : bear
RWMA = positive ? rwma - Band : negative ? rwma + Band : na
alpha = color.new(color.black, 100)

center = plot(filleshow ? RWMA : na, "RRTH", colour, editable = true)


plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 70), 2, editable = true)
plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 80), 3, editable = true)
plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 90), 4, editable = true)

max = RWMA + Band


min = RWMA - Band

top = plot(filleshow ? max: na, "RRTH", alpha)


bottom = plot(filleshow ? min: na, "RRTH", alpha)
fill(top, center, top_value = max, bottom_value = RWMA, bottom_color =
color.new(colour, 75), top_color = alpha, editable = true)
fill(center, bottom, top_value = RWMA, bottom_value = min, bottom_color = alpha,
top_color = color.new(colour, 75), editable = true)
Barcol = positive ? color.green:color.red

if negative and not negative[1]


label.new(bar_index,max+(Band/2),"",color = color.red,size=size.small)
if positive and not positive[1]
label.new(bar_index,min-(Band/2),"",color = color.green,size=size.small,style=
label.style_label_up)

plotcandle(open, high, low, close,color = Barcol,wickcolor = Barcol,bordercolor =


Barcol)
barcolor(color = Barcol)
//---------------------------------------------------------------------------------
------------------------------------}
//трендовая линия
//----------------{
//inputs
dtlColor = input.color(color.red, 'Down Trend Line Color', inline = '0')
utlColor = input.color(color.green, 'Up Trend Line Color', inline = '1')
pastColor = input.color(color.orange, 'Crossed Line Color', inline = '2')
extendLine = input.bool(false, 'Extend Lines Until Crossed', inline = '3')
onlyLast = input.bool(false, 'Most Recent Line Only', inline = '3', tooltip
= 'If multiple lines share pivot points, checking this will only show the most
recent line.')
hideCrossed = input.bool(false, 'Hide Crossed Lines', inline = '4')
showCross = input.bool(true, 'Show Crosses', inline ='4', tooltip = 'Hiding
crossed lines will only leave trend lines on the chart that have not been breached
by your selected source. Showing crosses will plot an "X" where price crosses the
trendline based on your selected source.')
crossDown = input.color(color.red, 'Cross Below Color', inline = '5')
crossUp = input.color(color.lime, 'Cross Above Color', inline = '5')
maxLines = input.int(4, 'Max Number of Crossed Lines to Show', step = 2,
minval = 0, maxval = 50)
crossSrc = input.string('Close', 'Cross Source', options = ['Close',
'High/Low'])
maxLineLen = input.int(252, 'Max Line Length', tooltip = 'Will remove line if
it is not crossed after selected amount of bars')
pivLen = input.int(9, 'Pivot Length', step = 1, minval = 1)
maxLines := hideCrossed ? 0 : maxLines
isLog = input.bool(false, 'Log Scale', tooltip = 'Select this option if
using a log chart.')

type pivot
string pivType
int x1
float y1
int x2
float y2

// arrays
var line[] dtlArray = array.new_line()
var line[] utlArray = array.new_line()

//functions
createLine(ptype, x1, y1, x2, y2)=>
piv = pivot.new(ptype, x1, y1, x2, y2)
trendline = line.new(x1, y1, x2, y2, extend = extendLine ? extend.right :
extend.none, color = ptype == 'ph' ? dtlColor : utlColor, width = 2)
if ptype == 'ph'
dtlArray.unshift(trendline)
else if ptype == 'pl'
utlArray.unshift(trendline)
piv

getSlope(line)=>
slopePh = (line.get_y2(line) - line.get_y1(line))/(line.get_x2(line) -
line.get_x1(line))
extendedPh = line.get_y2(line) - slopePh * (line.get_x2(line) - bar_index)
extendedPh

getSlopeLog(line)=>
slopePh = (math.log(line.get_y2(line)) -
math.log(line.get_y1(line)))/(line.get_x2(line) -line.get_x1(line))
extendedPh = math.exp(math.log(line.get_y2(line)) - slopePh *
(line.get_x2(line) - bar_index))
extendedPh

// variables
ph = ta.pivothigh(high, pivLen, pivLen)
pl = ta.pivotlow(low, pivLen, pivLen)
var int utlX1 = na, var float utlY1 = na
var int utlX2 = na, var float utlY2 = na
var int dtlX2 = na, var float dtlY2 = na
var int dtlX1 = na, var float dtlY1 = na

if pl
utlX1 := utlX2, utlY1 := utlY2
utlX2 := bar_index[pivLen], utlY2 := low[pivLen]
if utlY1 < utlY2
createLine('pl', utlX1, utlY1, utlX2, utlY2)

if ph
dtlX1 := dtlX2, dtlY1 := dtlY2
dtlX2 := bar_index[pivLen], dtlY2 := high[pivLen]
if dtlY1 > dtlY2
createLine('ph', dtlX1, dtlY1, dtlX2, dtlY2)

for l in utlArray
src = crossSrc == 'Close' ? close : low
first = l == utlArray.get(0)
extended = not isLog ? getSlope(l) : getSlopeLog(l)
l.set_xy2(bar_index, extended)
if l.get_x2() - l.get_x1() > maxLineLen
l.delete()
if src > line.get_price(l, bar_index) and not first and onlyLast
l.delete()
var line [] tempUtl = array.new_line(maxLines/2)
var label [] tempUL = array.new_label(maxLines/2)
if src < line.get_price(l, bar_index)
newLine = line.new(line.get_x1(l), line.get_y1(l), line.get_x2(l),
line.get_y2(l), color = pastColor, style = line.style_dashed, width = 1)
crossLabel = showCross ? label.new(bar_index, low, ' ', yloc =
yloc.belowbar, color = crossDown, style = label.style_xcross, size = size.tiny) :
na
alert(str.tostring(syminfo.ticker) + ' crossing below trendline',
alert.freq_once_per_bar)
line.delete(l)
tempUtl.unshift(newLine)
tempUL.unshift(crossLabel)
if tempUtl.size() > (maxLines/2)
line.delete(tempUtl.pop())
label.delete(tempUL.pop())

for l in dtlArray
first = l == dtlArray.get(0)
src = crossSrc == 'Close' ? close : high
extended = not isLog ? getSlope(l) : getSlopeLog(l)
l.set_xy2(bar_index, extended)
if l.get_x2() - l.get_x1() > maxLineLen
l.delete()
if src < line.get_price(l, bar_index) and not first and onlyLast
l.delete()
var line [] tempDtl = array.new_line(maxLines/2)
var label [] tempDL = array.new_label(maxLines/2)
if src > line.get_price(l, bar_index)
newLine = line.new(line.get_x1(l), line.get_y1(l), line.get_x2(l),
line.get_y2(l), color = pastColor, style = line.style_dashed, width = 1)
crossLabel = showCross ? label.new(bar_index, high, '', yloc =
yloc.abovebar, style = label.style_xcross, color = crossUp, size = size.tiny) : na
alert(str.tostring(syminfo.ticker) + ' crossing above trendline',
alert.freq_once_per_bar)
line.delete(l)
tempDtl.unshift(newLine)
tempDL.unshift(crossLabel)
if tempDtl.size() > (maxLines/2)
line.delete(tempDtl.pop())
label.delete(tempDL.pop())
//----------------}
//fib
//-----------------------------------------{
// Fibonacci Levels
fib_0 = input.float(0.382, "Fib Level 0")
fib_1 = input.float(0.618, "Fib Level 1")

// Calculate Fibonacci levels


fib_range = ta.highest(high, 2) - ta.lowest(low, 2)

fib_level_0 = ta.highest(high, 2) - (fib_range * fib_0)


fib_level_1 = ta.highest(high, 2) - (fib_range * fib_1)

// RSI
rsi_length = input(14, "RSI Length")
rsi_overbought = input(70, "RSI Overbought Level")
rsi_oversold = input(30, "RSI Oversold Level")

rsi_value = ta.rsi(close, rsi_length)

// Determine buy and sell conditions


buy_condition = ta.crossover(rsi_value, rsi_oversold) and close > fib_level_1
sell_condition = ta.crossunder(rsi_value, rsi_overbought) and close < fib_level_0

// Plot buy and sell signals


plotshape(buy_condition, title="Buy Signal", location=location.belowbar,
color=color.green, style=shape.labelup, text="BUY")
plotshape(sell_condition, title="Sell Signal", location=location.abovebar,
color=color.red, style=shape.labeldown, text="SELL")

//-----------------------------------------}

You might also like