-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore Indicator.pine
More file actions
256 lines (202 loc) · 8.15 KB
/
Copy pathCore Indicator.pine
File metadata and controls
256 lines (202 loc) · 8.15 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//@version=6
// Created by NCryptsion (https://github.com/ncryptsion)
indicator(title="NC Indicator", shorttitle="NC Indicator", overlay=true)
// EMA
len1 = input.int(14, minval=1, title="Fast EMA")
len2 = input.int(26, minval=1, title="Medium EMA")
len3 = input.int(50, minval=1, title="Slow EMA")
src1 = input.source(close, title="Source Fast")
src2 = input.source(close, title="Source Medium")
src3 = input.source(close, title="Source Slow")
ema1 = ta.ema(src1, len1)
ema2 = ta.ema(src2, len2)
ema3 = ta.ema(src3, len3)
plot(ema1, title="EMA Fast", color=color.yellow, linewidth=2)
plot(ema2, title="EMA Medium", color=color.orange, linewidth=2)
plot(ema3, title="EMA Slow", color=color.blue, linewidth=4)
// Daily High and Low
var line dayHighLine = na
var line dayLowLine = na
var line prevDayHighLine = na
var line prevDayLowLine = na
newDay = ta.change(time("D")) != 0
var float dayHigh = high
var float dayLow = low
var float prevDayHigh = na
var float prevDayLow = na
if newDay
prevDayHigh := dayHigh
prevDayLow := dayLow
dayHigh := high
dayLow := low
if not na(dayHighLine)
line.delete(dayHighLine)
if not na(dayLowLine)
line.delete(dayLowLine)
dayHighLine := line.new(bar_index, dayHigh, bar_index + 1, dayHigh, color=color.red, width=4, extend=extend.right)
dayLowLine := line.new(bar_index, dayLow, bar_index + 1, dayLow, color=color.blue, width=4, extend=extend.right)
if not na(prevDayHighLine)
line.delete(prevDayHighLine)
if not na(prevDayLowLine)
line.delete(prevDayLowLine)
if not na(prevDayHigh) and not na(prevDayLow)
prevDayHighLine := line.new(bar_index, prevDayHigh, bar_index + 1, prevDayHigh, color=color.red, width=2, style=line.style_dotted, extend=extend.right)
prevDayLowLine := line.new(bar_index, prevDayLow, bar_index + 1, prevDayLow, color=color.blue, width=2, style=line.style_dotted, extend=extend.right)
else
dayHigh := math.max(dayHigh, high)
dayLow := math.min(dayLow, low)
if not na(dayHighLine)
line.set_y1(dayHighLine, dayHigh)
line.set_y2(dayHighLine, dayHigh)
if not na(dayLowLine)
line.set_y1(dayLowLine, dayLow)
line.set_y2(dayLowLine, dayLow)
// Table Settings
tablePos = input.string("Top Right", "Table Location",
["Top Right","Middle Right","Bottom Right",
"Top Center","Middle Center","Bottom Center",
"Top Left","Middle Left","Bottom Left"],
group="Trend Table")
tableSize = input.string("Normal","Table Size",
["Auto","Huge","Large","Normal","Small","Tiny"],
group="Trend Table")
panelColor = input.color(color.new(color.blue,40),"Panel Color", group="Trend Table")
// Table Positions
loc(x)=>
y=str.split(str.lower(x)," ")
out=""
for i=0 to array.size(y)-1
out:=out+array.get(y,i)
if i!=array.size(y)-1
out:=out+"_"
out
// Functions (Trend Calculator, Trend Color)
trend(price, ema)=>
diff = math.abs(price-ema)
threshold = syminfo.mintick*50
string result="Consolidation"
if diff<threshold
result:="Consolidation"
else if price>ema
result:="Uptrend"
else
result:="Downtrend"
result
trendColor(t)=>
c=color.orange
if t=="Uptrend"
c:=color.green
else if t=="Downtrend"
c:=color.red
c
// Daily
dClose = request.security(syminfo.tickerid,"D",close)
dEMA = request.security(syminfo.tickerid,"D",ta.ema(close,14))
// Previous Day
pdClose = request.security(syminfo.tickerid,"D",close[1])
pdEMA = request.security(syminfo.tickerid,"D",ta.ema(close,14))[1]
// 4H
h4Close = request.security(syminfo.tickerid,"240",close)
h4EMA = request.security(syminfo.tickerid,"240",ta.ema(close,50))
// 30-minute
m30Close = request.security(syminfo.tickerid,"30",close)
m30EMA = request.security(syminfo.tickerid,"30",ta.ema(close,50))
// 4-hour (updated from 2-hour)
h4Close2 = request.security(syminfo.tickerid,"240",close)
h4EMA2 = request.security(syminfo.tickerid,"240",ta.ema(close,50))
todayTrend = trend(dClose,dEMA)
h4Trend = trend(h4Close,h4EMA)
prevTrend = trend(pdClose,pdEMA)
m30Trend = trend(m30Close,m30EMA)
h4Trend2 = trend(h4Close2,h4EMA2)
// ATH and ALT Candle Horizontal Line
var line allTimeHighLine = na
var line allTimeLowLine = na
var float allTimeHigh = high
var float allTimeLow = low
var int allTimeHighBar = bar_index
if high > allTimeHigh
allTimeHigh := high
allTimeLow := low
allTimeHighBar := bar_index
// Delete previous lines
if not na(allTimeHighLine)
line.delete(allTimeHighLine)
if not na(allTimeLowLine)
line.delete(allTimeLowLine)
// Core
allTimeHighLine := line.new(
x1 = allTimeHighBar, y1 = allTimeHigh,
x2 = allTimeHighBar, y2 = allTimeHigh,
color = color.purple, width = 2, extend = extend.right,
style=line.style_dotted
)
allTimeLowLine := line.new(
x1 = allTimeHighBar, y1 = allTimeLow,
x2 = allTimeHighBar, y2 = allTimeLow,
color = color.purple, width = 2, extend = extend.right,
style=line.style_dotted
)
// Last 30 minutes volume
lookbackMinutes = 30
tf_minutes = timeframe.ismonthly ? 43200 : timeframe.isweekly ? 10080 : timeframe.isdaily ? 1440 : timeframe.multiplier
bars30m = math.max(1, math.round(30 / tf_minutes))
var float buyVol = 0
var float sellVol = 0
buyVol := 0.0
sellVol := 0.0
for i = 0 to bars30m - 1
if i < bar_index
if close[i] > open[i]
buyVol += volume[i]
else if close[i] < open[i]
sellVol += volume[i]
totalVol = buyVol + sellVol
buyPerc = totalVol > 0 ? (buyVol / totalVol) * 100 : 0
sellPerc = totalVol > 0 ? (sellVol / totalVol) * 100 : 0
// Last 4 hours volume
lookbackMinutes4h = 240
bars4h = math.max(1, math.round(lookbackMinutes4h / tf_minutes))
var float buyVol4h = 0
var float sellVol4h = 0
buyVol4h := 0.0
sellVol4h := 0.0
for i = 0 to bars4h - 1
if i < bar_index
if close[i] > open[i]
buyVol4h += volume[i]
else if close[i] < open[i]
sellVol4h += volume[i]
totalVol4h = buyVol4h + sellVol4h
buyPerc4h = totalVol4h > 0 ? (buyVol4h / totalVol4h) * 100 : 0
sellPerc4h = totalVol4h > 0 ? (sellVol4h / totalVol4h) * 100 : 0
// Volume vs Trend
volumeTrendStatus(trendStr, buyP, sellP)=>
status = "Normal"
if trendStr == "Uptrend" and sellP > buyP
status := "Abnormal"
else if trendStr == "Downtrend" and buyP > sellP
status := "Abnormal"
status
volTrendToday = volumeTrendStatus(todayTrend, buyPerc, sellPerc)
volTrend4h = volumeTrendStatus(h4Trend2, buyPerc4h, sellPerc4h)
// Create Table
var tbl = table.new(loc(tablePos), 2, 9, frame_width=2, frame_color=panelColor, border_width=1, border_color=panelColor)
if barstate.islast
table.clear(tbl, 0, 0, 1, 8)
table.cell(tbl, 0, 0, "NC Table", text_color=color.black, bgcolor=color.gray, text_size=size.normal)
table.merge_cells(tbl, 0, 0, 1, 0)
table.cell(tbl, 0, 1, "Current Day", text_color=color.black)
table.cell(tbl, 1, 1, todayTrend, bgcolor=trendColor(todayTrend), text_color=color.black)
table.cell(tbl, 0, 2, "Volume vs Trend", text_color=color.black)
table.cell(tbl, 1, 2, volTrendToday, bgcolor=(volTrendToday=="Abnormal"?color.new(color.red,70):color.new(color.green,70)), text_color=color.black)
table.cell(tbl, 0, 3, "Last 30m", text_color=color.black)
table.cell(tbl, 1, 3, m30Trend, bgcolor=trendColor(m30Trend), text_color=color.black)
table.cell(tbl, 0, 4, "Last 4H", text_color=color.black)
table.cell(tbl, 1, 4, h4Trend2, bgcolor=trendColor(h4Trend2), text_color=color.black)
table.cell(tbl, 0, 5, "Previous Day", text_color=color.black)
table.cell(tbl, 1, 5, prevTrend, bgcolor=trendColor(prevTrend), text_color=color.black)
table.cell(tbl, 0, 6, "30m Volume %", text_color=color.black)
table.cell(tbl, 1, 6, "Buy: " + str.tostring(buyPerc,"#.0") + "%\nSell: " + str.tostring(sellPerc,"#.0") + "%", text_color=color.black, bgcolor=color.new(color.blue,70))
table.cell(tbl, 0, 7, "4H Volume %", text_color=color.black)
table.cell(tbl, 1, 7, "Buy: " + str.tostring(buyPerc4h,"#.0") + "%\nSell: " + str.tostring(sellPerc4h,"#.0") + "%", text_color=color.black, bgcolor=color.new(color.blue,70))