Repository navigation
Expand file tree
/
Copy pathcomponent-breadth-dashboard.pine
More file actions
112 lines (99 loc) · 5.64 KB
/
Copy pathcomponent-breadth-dashboard.pine
File metadata and controls
112 lines (99 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//@version=6
indicator("Component Breadth Dashboard", shorttitle = "Component Breadth", overlay = false, dynamic_requests = true)
// Pine cannot read an index's membership list automatically. The default basket
// is a liquid, diversified large-cap sample; replace the symbols with the actual
// constituents of the index or portfolio you want to measure.
string groupBasket = "Component basket"
string symbol01 = input.symbol("NASDAQ:AAPL", "01", group = groupBasket, inline = "r1")
string symbol02 = input.symbol("NASDAQ:MSFT", "02", group = groupBasket, inline = "r1")
string symbol03 = input.symbol("NASDAQ:NVDA", "03", group = groupBasket, inline = "r2")
string symbol04 = input.symbol("NASDAQ:AMZN", "04", group = groupBasket, inline = "r2")
string symbol05 = input.symbol("NASDAQ:META", "05", group = groupBasket, inline = "r3")
string symbol06 = input.symbol("NASDAQ:GOOGL", "06", group = groupBasket, inline = "r3")
string symbol07 = input.symbol("NASDAQ:AVGO", "07", group = groupBasket, inline = "r4")
string symbol08 = input.symbol("NYSE:BRK.B", "08", group = groupBasket, inline = "r4")
string symbol09 = input.symbol("NYSE:JPM", "09", group = groupBasket, inline = "r5")
string symbol10 = input.symbol("NYSE:LLY", "10", group = groupBasket, inline = "r5")
string symbol11 = input.symbol("NYSE:WMT", "11", group = groupBasket, inline = "r6")
string symbol12 = input.symbol("NYSE:XOM", "12", group = groupBasket, inline = "r6")
string symbol13 = input.symbol("NYSE:UNH", "13", group = groupBasket, inline = "r7")
string symbol14 = input.symbol("NYSE:V", "14", group = groupBasket, inline = "r7")
string symbol15 = input.symbol("NYSE:JNJ", "15", group = groupBasket, inline = "r8")
int highLowLookback = input.int(252, "New high/low lookback (sessions)", minval = 20, maxval = 500)
var array<string> basket = array.from(
symbol01, symbol02, symbol03, symbol04, symbol05,
symbol06, symbol07, symbol08, symbol09, symbol10,
symbol11, symbol12, symbol13, symbol14, symbol15)
int advances = 0
int declines = 0
int unchanged = 0
int newHighs = 0
int newLows = 0
int valid = 0
for i = 0 to array.size(basket) - 1
string symbol = array.get(basket, i)
[dailyClose, priorClose, priorWindowHigh, priorWindowLow] = request.security(
symbol, "D",
[close, close[1], ta.highest(high, highLowLookback)[1], ta.lowest(low, highLowLookback)[1]],
ignore_invalid_symbol = true)
if not na(dailyClose) and not na(priorClose)
valid += 1
if dailyClose > priorClose
advances += 1
else if dailyClose < priorClose
declines += 1
else
unchanged += 1
if not na(priorWindowHigh) and dailyClose > priorWindowHigh
newHighs += 1
if not na(priorWindowLow) and dailyClose < priorWindowLow
newLows += 1
float advancePercent = valid > 0 ? 100.0 * advances / valid : na
float declinePercent = valid > 0 ? 100.0 * declines / valid : na
float adDifference = advances - declines
float highLowDifference = newHighs - newLows
color breadthColor = na(advancePercent) ? color.gray :
advancePercent >= 60 ? color.lime :
advancePercent <= 40 ? color.red : color.orange
plot(
advancePercent,
"Advancing components (%)",
color = breadthColor,
style = plot.style_columns,
histbase = 50,
linewidth = 3)
plot(
50 + highLowDifference * 2,
"New highs minus new lows (centered)",
color = color.aqua,
linewidth = 2)
hline(50, "Breadth midpoint", color = color.new(color.gray, 45))
hline(60, "Broad participation", color = color.new(color.lime, 70), linestyle = hline.style_dotted)
hline(40, "Weak participation", color = color.new(color.red, 70), linestyle = hline.style_dotted)
var table dashboard = table.new(
position.top_right, 2, 8,
bgcolor = color.new(color.black, 8),
frame_color = color.new(color.gray, 45),
frame_width = 1,
border_color = color.new(color.gray, 75))
if barstate.islast
table.clear(dashboard, 0, 0, 1, 7)
color headerColor = color.rgb(35, 42, 55)
table.cell(dashboard, 0, 0, "Breadth measure", text_color = color.white, bgcolor = headerColor)
table.cell(dashboard, 1, 0, "Count", text_color = color.white, bgcolor = headerColor)
table.cell(dashboard, 0, 1, "Valid components", text_color = color.silver)
table.cell(dashboard, 1, 1, str.tostring(valid), text_color = color.white)
table.cell(dashboard, 0, 2, "Advances", text_color = color.lime)
table.cell(dashboard, 1, 2, str.tostring(advances) + " (" + str.tostring(advancePercent, "#.0") + "%)", text_color = color.lime)
table.cell(dashboard, 0, 3, "Declines", text_color = color.red)
table.cell(dashboard, 1, 3, str.tostring(declines) + " (" + str.tostring(declinePercent, "#.0") + "%)", text_color = color.red)
table.cell(dashboard, 0, 4, "Unchanged", text_color = color.silver)
table.cell(dashboard, 1, 4, str.tostring(unchanged), text_color = color.white)
table.cell(dashboard, 0, 5, "A/D difference", text_color = breadthColor)
table.cell(dashboard, 1, 5, str.tostring(adDifference), text_color = breadthColor)
table.cell(dashboard, 0, 6, "New " + str.tostring(highLowLookback) + "d highs", text_color = color.aqua)
table.cell(dashboard, 1, 6, str.tostring(newHighs), text_color = color.aqua)
table.cell(dashboard, 0, 7, "New " + str.tostring(highLowLookback) + "d lows", text_color = color.fuchsia)
table.cell(dashboard, 1, 7, str.tostring(newLows), text_color = color.fuchsia)
alertcondition(advancePercent >= 60, "Broad advance", "At least 60% of valid configured components are advancing.")
alertcondition(advancePercent <= 40, "Broad decline", "At most 40% of valid configured components are advancing.")