-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicator.pine
110 lines (67 loc) · 3.43 KB
/
indicator.pine
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
//@version=5
indicator(title="NYSE New Highs vs New Lows", shorttitle="Hi vs Lo", overlay=false)
hi = input.symbol("higq")
lo = input.symbol("lowq")
length = input.int(2, "SMA Length")
res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])
source = input.source(close)
PlotCumulative = input(false, title='Plot Cumulative?', group="Basics")
newhi = request.security(hi, res, source)
newlo = -1*request.security(lo, res, source)
newhicalc = ta.sma(newhi,length)
newlocalc = ta.sma(newlo,length)
hi2 = request.security(hi, 'D', high[2], lookahead = barmerge.lookahead_on)
hi1 = request.security(hi, 'D', high[1], lookahead = barmerge.lookahead_on)
hi0 = request.security(hi, 'D', high, lookahead = barmerge.lookahead_on)
low2 = request.security(lo, 'D', low[2], lookahead = barmerge.lookahead_on)
low1 = request.security(lo, 'D', low[1], lookahead = barmerge.lookahead_on)
low0 = request.security(lo, 'D', low, lookahead = barmerge.lookahead_on)
trendLabel = 0
trendcolor = color.new(color.black, transp = 100)
if hi2 > low2 and hi1 > low1 and hi0 > low0
trendcolor := color.new(color.green, transp = 50)
trendLabel := 1
if hi2 < low2 and hi1 < low1 and hi0 < low0
trendcolor := color.new(color.red, transp = 50)
trendLabel := -1
count = (close < close[1] and volume > volume[1]) ? 1 : 0
for day = 1 to 9
if ((close[day] + (close[day] * 0.003)) < (close[day+1] ) ? true : false) and volume[day] > volume[day+1]
count += 1
above_ema_count = 0
if close > ta.ema(close, 10)
above_ema_count += 1
if close > ta.ema(close, 20)
above_ema_count += 1
if close > ta.ema(close, 50)
above_ema_count += 1
emaLabel = -1
if above_ema_count == 2
emaLabel := 0
if above_ema_count > 2
emaLabel := 1
distoLabel = -1
if count < 2
distoLabel := 1
if count == 2
distoLabel := 0
superLabel = "nn:" + trendLabel + "dds:" + distoLabel +"emas:" + emaLabel
// ///emacount
// label2 = label.new(bar_index, 20, style=label.style_solid, text = str.tostring(above_ema_count))
var cumulative = float(0)
bgcolor(trendcolor)
if PlotCumulative
cumulative := math.sum(newhi,length)+math.sum(newlo,length)
plot(cumulative, title="New High, Cumulative", style=plot.style_columns, color=color.silver)
plot(newhicalc, title="New High, Avg", style=plot.style_columns, color=color.from_gradient(newhicalc,10,150,color.yellow,color.green))
plot(newlocalc, title="New Low, Avg", style=plot.style_columns, color=color.from_gradient(newlocalc,-150,-10,color.red,color.yellow))
hline(0,linestyle=hline.style_solid,color=color.new(color.white,60))
//plot(ta.sma(newhi+newlo,length), style=plot.style_line, linewidth=2, color=color.white)
//Labels
var testTable = table.new(position = position.top_right, columns = 1, rows = 2, bgcolor = color.black, border_width = 1)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = " New Highs ", text_color=color.new(color.silver,20), bgcolor=color.new(color.teal,60))
table.cell(table_id = testTable, column = 0, row = 1, text = str.tostring(length)+"-"+str.tostring(res)+" Avg ", text_color=color.new(color.silver,20), bgcolor=color.new(color.teal,60))
var testTable2 = table.new(position = position.bottom_right, columns = 1, rows = 1, bgcolor = color.black, border_width = 1)
if barstate.islast
table.cell(table_id = testTable2, column = 0, row = 0, text = " New Lows ", text_color=color.new(color.silver,20), bgcolor=color.new(color.red,60))