-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathKillpipsScanner.pine
More file actions
executable file
·344 lines (301 loc) · 16.2 KB
/
KillpipsScanner.pine
File metadata and controls
executable file
·344 lines (301 loc) · 16.2 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// vim: syntax=pine
// @version=6
indicator("TO Futures Scanner v1.1", overlay=true)
import TradingView/ta/9
KPzones = input.text_area("", "Paste Killpips values (format: $NQ1: name,value ...)")
MQzones = input.text_area("", "Paste MenthorQ values (format: $NQ1: name,value ...)")
tP = input.string("Top Right", "Table Position", options=["Top Center","Bottom Center","Top Right", "Top Left", "Bottom Right", "Bottom Left"], group="Settings")
sFontSize = input.string(title="Font Size: ", options=["Tiny", "Small", "Normal", "Large"], defval="Small", group="Settings")
txtC = input.color(defval=color.new(color.white, 20),title = "Text Color", group="Settings")
greenC = input.color(defval=color.new(color.green, 50),title = "Green Color", group="Settings")
redC = input.color(defval=color.new(color.red, 50),title = "Red Color", group="Settings")
yellowC = input.color(defval=color.new(color.yellow, 50),title = "Yellow Color", group="Settings")
bool showKill = input.bool(true, "Show Killpips Status", group="Paid Lines")
bool showMQRev = input.bool(true, "Show MenthorQ Reversals", group="Paid Lines")
bool showMQWick = input.bool(true, "Show MenthorQ Wicks", group="Paid Lines")
bool showOnlyBB = input.bool(false, "ONLY Show MenthorQ when at BB extreme)", group="Paid Lines")
bool showVWAP = input.bool(false, "Show VWAP Status", group="Show Options")
bool showMACDPsar = input.bool(true, "Show MACD/Psar Status", group="Show Options")
bool showEMAs = input.bool(true, "Show EMA Status", group="Show Options")
bool showCH = input.bool(true, "Show Change Percent", group="Show Options")
bool showRSI = input.bool(false, "Show RSI Status", group="Show Options")
bool showBB = input.bool(false, "Show Bollinger Band Touches", group="Show Options")
bool useES = input.bool(true, "Scan S&P 500 Futures", group="Scan List")
bool useNQ = input.bool(true, "Scan NASDAQ Futures", group="Scan List")
bool useVIX = input.bool(true, "Scan VIX", group="Scan List")
bool useYM = input.bool(true, "Scan Dow Jones Futures", group="Scan List")
bool useNDX = input.bool(false, "Scan NDX", group="Scan List")
bool useRTY = input.bool(false, "Scan RTY", group="Scan List")
bool useFDAX = input.bool(false, "Scan FDAX", group="Scan List")
bool useGC = input.bool(false, "Scan Gold Futures", group="Scan List")
bool useSI = input.bool(false, "Scan Silver Futures", group="Scan List")
bool useHG = input.bool(false, "Scan Copper Futures", group="Scan List")
bool useCL = input.bool(false, "Scan Oil Futures", group="Scan List")
smEMA = input.int(21, "Standard EMA", minval=1, group="Indicator Settings")
bigEMA = input.int(200, "Longer EMA", minval=1, group="Indicator Settings")
stLength = input.int(11, "RSI Length", minval=1, group="Indicator Settings")
rsiOB = input.int(80, "RSI Overbought Value", minval=1, group="Indicator Settings")
rsiOS = input.int(20, "RSI Oversold Value", minval=1, group="Indicator Settings")
stMultiplier = input.int(2, "SuperTrend Multiplier", minval=0, step=1, group="Indicator Settings")
rsiLen = input.int(11, "SuperTrend Length", minval=1, group="Indicator Settings")
macd1 = input.int(12, "MACD Short", minval=1, group="Indicator Settings")
macd2 = input.int(26, "MACD Long", minval=1, group="Indicator Settings")
macd3 = input.int(9, "MACD Period", minval=1, group="Indicator Settings")
bbLength = input.int(20, "Bollinger Length", minval=1, group="Indicator Settings")
bbMultiplier = input.float(2, "Bollinger Multiplier", minval=0.1, step=0.1, group="Indicator Settings")
BBtouchTolerance = input.float(0.05, "BB Touch Tolerance (%)", minval=0, step=0.01, group="Indicator Settings") / 100
esSymbol = "CME_MINI:ES1!"
nqSymbol = "CME_MINI:NQ1!"
vixSymbol = "TVC:VIX"
ymSymbol = "CBOT_MINI:YM1!"
ndxSymbol = "NASDAQ:NDX"
rtySymbol = "CME_MINI:RTY1!"
fdaxSymbol = "EUREX:FDAX1!"
goldSymbol = "COMEX:GC1!"
oilSymbol = "NYMEX:CL1!"
silverSymbol = "COMEX:SI1!"
copperSymbol = "COMEX:HG1!"
mapKP = map.new<string, float>()
mapMQ = map.new<float, string>()
rowG = 1
bg = color.new(color.black, 100)
tPos = tP == "Top Left" ? position.top_left : tP == "Bottom Right" ? position.bottom_right : tP == "Bottom Left" ? position.bottom_left : tP == "Top Center" ? position.top_center : tP == "Bottom Center" ? position.bottom_center : position.top_right
myFont = sFontSize == "Tiny" ? size.tiny : sFontSize == "Small" ? size.small : sFontSize == "Normal" ? size.normal : sFontSize == "Large" ? size.large : size.auto
// Create Table
var table myTable = table.new(tPos, 17, 20, bgcolor = color.new(color.black, 100), frame_width = 1, frame_color = color.gray, border_width = 1, border_color = color.gray)
// Header
//table.cell(myTable, 1, 1, "Ticker", text_color=txtC, bgcolor=bg, text_size=myFont)
//table.cell(myTable, 2, 1, "Killpips Level", text_color=txtC, bgcolor=bg, text_size=myFont)
//table.cell(myTable, 3, 1, "Latest Alert", text_color=txtC, bgcolor=bg, text_size=myFont)
generateKPMap(comma) =>
map.clear(mapKP)
for i = 0 to array.size(comma) - 2 by 2
key = str.trim(array.get(comma, i))
valueStr = str.trim(array.get(comma, i+1))
valueNum = str.tonumber(valueStr)
map.put(mapKP, key, valueNum)
findKPMap(string a) =>
result = 0.0
if map.contains(mapKP, a)
result := map.get(mapKP, a)
result
getKillStatus(float fuc) =>
string result = ""
//log.info("KillStatus float = " + str.tostring(fuc))
if (fuc > findKPMap("HV") and fuc < findKPMap("RD0"))
result := "Long"
if (fuc > findKPMap("RD0") and fuc < findKPMap("RD1"))
result := "🡅 Long "
if (fuc > findKPMap("RD1") and fuc < findKPMap("RD2"))
result := "🡅🡅 Long "
if (fuc > findKPMap("RD2") and fuc < findKPMap("vix r1"))
result := "🡅🡅🡅 Long "
if (fuc > findKPMap("vix r1") and fuc < findKPMap("vix r2"))
result := "😧 Extreme Long 😧"
if (fuc > findKPMap("vix r2") and fuc < findKPMap("VAH"))
result := "⛔ Absolute TOP ⛔"
if (fuc < findKPMap("HV") and fuc > findKPMap("SD0"))
result := "Short"
if (fuc < findKPMap("SD0") and fuc > findKPMap("SD1"))
result := "🡇 Short "
if (fuc < findKPMap("SD1") and fuc > findKPMap("SD2"))
result := "🡇🡇 Short "
if (fuc < findKPMap("SD2") and fuc > findKPMap("vix s1"))
result := "🡇🡇🡇 Short "
if (fuc < findKPMap("vix s1") and fuc > findKPMap("vix s2"))
result := "😧 Extreme Short 😧"
if (fuc < findKPMap("vix s2") and fuc > findKPMap("VAL"))
result := "⛔ Absolute BOTTOM ⛔"
result
parseKPLines(sTicker, Close) =>
//log.info("parseKPLines = '" + sTicker + "'" + str.tostring(Close) + "'")
string[] _pair = str.split(KPzones, "\n")
string sw = ""
string commas = ""
string result = ""
for s in _pair
sw := s
if str.contains(s, "setting ")
string[] parts = str.split(s, "setting ")
sw := array.get(parts, 0)
if str.contains(sw, ":")
string[] parts = str.split(sw, ":")
// SD2, 5.0530, HV, 5.1130, VAH, 5.2195, VAL, 5.0060 setting 5k - 41k
sw := array.get(parts, 1)
// $HG1!:
sTick = array.get(parts, 0)
if str.contains(sTick, sTicker)
sw := str.trim(sw)
string[] comma = str.split(sw, ", ")
// vix r1, 5788, vix r2, 5793, vix s1, 5637, vix s2, 5632, RD0, 5727, RD1, 5740, RD2, 5768
generateKPMap(comma)
//log.info("Map contains " + str.tostring(map.size(mapKP)))
result := getKillStatus(Close)
//log.info("result 2 = " + result)
result
findMQMap(float Close, float Open, float POpen, float PClose, float High, float Low, float PHigh, float PLow) =>
log.info("findMQMap with array size " + str.tostring(map.size(mapMQ)))
result = ""
bRed = Close < Open
bGreen = Open < Close
bPRed = PClose < POpen
bPGreen = POpen < PClose
if showMQRev and not showMQWick
keys = map.keys(mapMQ)
for i = 0 to array.size(keys) - 1
keyValue = array.get(keys, i) // 1D Min, key=5659.67
if (bGreen and bPRed and High > keyValue and Low < keyValue and PHigh > keyValue and PLow < keyValue)
result := map.get(mapMQ, keyValue)
break
else if (bPGreen and bRed and High > keyValue and Low < keyValue and PHigh > keyValue and PLow < keyValue)
result := map.get(mapMQ, keyValue)
break
if showMQWick
keys = map.keys(mapMQ)
for i = 0 to array.size(keys) - 1
keyValue = array.get(keys, i) // 1D Min, key=5659.67
if ((High > keyValue and Close < keyValue) or (High > keyValue and Open < keyValue))
result := map.get(mapMQ, keyValue)
break
result
loadUpMQMap(comma) =>
log.info("loadUpMQMap started " + str.tostring(comma))
map.clear(mapMQ)
// $ES1!: HVL, 5725, 1D Min, 5659.67, HVL 0DTE, 5715, GEX 9, 5830, GEX 10, 5820
for i = 0 to array.size(comma) - 2 by 2
valueStr = str.trim(array.get(comma, i))
key = str.trim(array.get(comma, i+1))
valueNum = str.tonumber(key)
map.put(mapMQ, valueNum, valueStr)
log.info("loadUpMQMap finished with " + str.tostring(map.size(mapMQ)))
parseMQLines(string sTicker, float Close) =>
log.info("parseMQLines = '" + sTicker + "', close = " + str.tostring(Close))
string[] _pair = str.split(MQzones, "\n")
string result = ""
for s in _pair
sw = s
if str.contains(sw, ":")
string[] parts = str.split(sw, ":")
sTick = array.get(parts, 0) // $HG1!:
sw := array.get(parts, 1) // SD2, 5.0530, HV, 5.1130, VAH, 5.2195, VAL, 5.0060
if str.contains(sTick, sTicker)
sw := str.trim(sw)
string[] comma = str.split(sw, ", ") // vix r1, 5788, vix r2, 5793
loadUpMQMap(comma)
result
updateTable(sym) =>
row = rowG
tf = timeframe.period
string[] xxx = str.split(sym, ":")
sins = str.replace_all(array.get(xxx, 1), "1!", "")
sins := str.replace_all(sins, "M2025", "")
[basisBB, devBB, Open, Close, High, Low, POpen, PClose, PHigh, PLow, tickVWAP, tickSar, tickEma, tickEma200, tickRSI] = request.security(sym, tf, [ta.sma(close, bbLength), ta.stdev(close, bbLength), open, close, high, low, open-1, close-1, high-1, low-1, ta.vwap(close), ta.sar(start = 0.02, inc = 0.02, max=0.2), ta.ema(close, smEMA), ta.ema(close, bigEMA), ta.rsi(close, rsiLen)])
[yaa, tickST] = request.security(sym, tf, ta.supertrend(stLength, stMultiplier))
// Old school BB calculation, to avoid another request.security
//tickBBUpper = basisBB + devBB
//tickBBLower = basisBB - devBB
[middle, tickBBUpper, tickBBLower] = request.security(sym, tf, ta.bb(close, bbLength, bbMultiplier))
upWick50PercentLarger = Close > Open and math.abs(High - Close) > math.abs(Open - Close)
downWick50PercentLarger = Close < Open and math.abs(Low - Close) > math.abs(Open - Close)
//MACDLine = macdFast - macdSlow
//SignalLine = ta.ema(MACDLine, macd3)
//tickMacdHist = MACDLine - SignalLine
col = 1
sC = color.white
table.cell(myTable, col, row, sins, text_color=txtC, bgcolor=bg, text_size=myFont)
log.info("ticker '" + str.tostring(sins) + "' , tickClose " + str.tostring(Close))
if (showKill)
sKillStatus = parseKPLines(sins, Close)
//log.info("sKillStatus '" + sKillStatus + "'")
sC := str.contains(str.lower(sKillStatus), "long") ? greenC : str.contains(str.lower(sKillStatus), "short") ? redC : bg
col := col + 1
table.cell(myTable, col, row, sKillStatus, text_color=txtC, bgcolor=sC, text_size=myFont)
if (true)
parseMQLines(sins, Close)
string homies = findMQMap(Close, Open, POpen, PClose, High, Low, PHigh, PLow)
log.info("parseMQLines homies = '" + homies + "'")
if (homies != '')
homies := "Bounced off MQ " + homies
sC := Close > Open ? greenC : Close < Open ? redC : color.black
else
sC := color.black
col := col + 1
table.cell(myTable, col, row, homies, text_color=txtC, bgcolor=sC, text_size=myFont)
col := col + 1
sC := tickST < 0 ? greenC : redC
table.cell(myTable, col, row, "Trend", text_color=txtC, bgcolor=sC, text_size=myFont)
if (showVWAP)
col := col + 1
sC := close > tickVWAP ? greenC : redC
table.cell(myTable, col, row, "VWAP", text_color=txtC, bgcolor=sC, text_size=myFont)
if (showMACDPsar)
[tickM1, tickM2, tickMacdHist] = request.security(sym, tf, ta.macd(close, macd1, macd2, macd3))
col := col + 1
sC := tickMacdHist > 0 ? greenC : redC
table.cell(myTable, col, row, "MACD", text_color=txtC, bgcolor=sC, text_size=myFont)
col := col + 1
sC := tickSar < close ? greenC : redC
table.cell(myTable, col, row, "PSar", text_color=txtC, bgcolor=sC, text_size=myFont)
if (showEMAs)
col := col + 1
sC := close > tickEma ? greenC : redC
table.cell(myTable, col, row, "21 EMA", text_color=txtC, bgcolor=sC, text_size=myFont)
col := col + 1
sC := close > tickEma200 ? greenC : redC
table.cell(myTable, col, row, "200 EMA", text_color=txtC, bgcolor=sC, text_size=myFont)
if (showCH)
tickDayOpen = request.security(sym, "1D", open)
col := col + 1
percentChange = ta.changePercent(Close, tickDayOpen)
sC := percentChange > 0 ? greenC : redC
table.cell(myTable, col, row, "CH: " + str.tostring(percentChange, "#.##"), text_color=txtC, bgcolor=sC, text_size=myFont)
if (showRSI)
col := col + 1
sC := tickRSI > rsiOB ? greenC : tickRSI < rsiOS ? redC : color.black
colTTT = tickRSI > rsiOB ? txtC : tickRSI < rsiOS ? txtC : color.new(color.gray, 10)
table.cell(myTable, col, row, "RSI", text_color=colTTT, bgcolor=sC, text_size=myFont)
if (showBB)
col := col + 1
tickTouchingUpperBB = High > tickBBUpper //* BBtouchTolerance
tickTouchingLowerBB = Low < tickBBLower //* BBtouchTolerance
tickTouchingBB = tickTouchingUpperBB or tickTouchingLowerBB
sC := tickTouchingUpperBB ? greenC : tickTouchingLowerBB ? redC : bg
colTTT = tickTouchingBB ? txtC : color.new(color.gray, 10)
table.cell(myTable, col, row, "BB Touch", text_color=colTTT, bgcolor=sC, text_size=myFont)
if barstate.islast
string sw = ""
string commas = ""
rowG := 0
if(useES) // = input.bool(true, "Scan S&P 500 Futures", group="Scan List")
rowG := rowG + 1
updateTable(esSymbol)
if(useNQ) // = input.bool(true, "Scan NASDAQ Futures", group="Scan List")
rowG := rowG + 1
updateTable(nqSymbol)
if(useVIX) // = input.bool(true, "Scan VIX", group="Scan List")
rowG := rowG + 1
updateTable(vixSymbol)
if(useYM) // = input.bool(true, "Scan Dow Jones Futures", group="Scan List")
rowG := rowG + 1
updateTable(ymSymbol)
if(useNDX) // = input.bool(false, "Scan NDX", group="Scan List")
rowG := rowG + 1
updateTable(ndxSymbol)
if(useRTY) // = input.bool(false, "Scan RTY", group="Scan List")
rowG := rowG + 1
updateTable(rtySymbol)
if(useFDAX) // = input.bool(false, "Scan FDAX", group="Scan List")
rowG := rowG + 1
updateTable(fdaxSymbol)
if(useGC) // = input.bool(false, "Scan Gold Futures", group="Scan List")
rowG := rowG + 1
updateTable(goldSymbol)
if(useSI) // = input.bool(false, "Scan Silver Futures", group="Scan List")
rowG := rowG + 1
updateTable(silverSymbol)
if(useHG) // = input.bool(false, "Scan Copper Futures", group="CommScandities List")
rowG := rowG + 1
updateTable(copperSymbol)
if(useCL) // = input.bool(false, "Scan Oil Futures", group="Scan List")
rowG := rowG + 1
updateTable(oilSymbol)