-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMenthorQScanner.pine
More file actions
executable file
·338 lines (297 loc) · 15.8 KB
/
MenthorQScanner.pine
File metadata and controls
executable file
·338 lines (297 loc) · 15.8 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
// @version=6
indicator("MenthorQ Scanner", overlay=true)
import TradingView/ta/9
// vim: syntax=pine
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 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", group="Scan List")
bool useNQ = input.bool(true, "Scan NASDAQ", group="Scan List")
bool useVIX = input.bool(true, "Scan VIX", group="Scan List")
bool useNDX = input.bool(false, "Scan NDX", group="Scan List")
bool useRTY = input.bool(false, "Scan Russell", group="Scan List")
bool usePLAT = input.bool(false, "Scan Platinum", group="Scan List")
bool useGC = input.bool(false, "Scan Gold", group="Scan List")
bool useSI = input.bool(false, "Scan Silver", group="Scan List")
bool useHG = input.bool(false, "Scan Copper", group="Scan List")
bool useCL = input.bool(false, "Scan Oil", group="Scan List")
bool useGAS = input.bool(false, "Scan Natural Gas", group="Scan List")
bool useCORN = input.bool(false, "Scan Corn", group="Scan List")
bool use2YNOTE = input.bool(false, "Scan 2 Year Note", group="Scan List")
bool use5YNOTE = input.bool(false, "Scan 5 Year Note", group="Scan List")
bool use10YNOTE = input.bool(false, "Scan 10 Year Note", group="Scan List")
bool useBOND = input.bool(false, "Scan BONDs", 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!"
silverSymbol = "COMEX:SI1!"
copperSymbol = "COMEX:HG1!"
platSymbol = "NYMEX:PL1!"
gasSymbol = "RUS:NG1!"
oilSymbol = "NYMEX:CL1!"
cornSymbol = "CBOT:ZC1!"
y5NoteSymbol = "CBOT:ZF1!"
y10NoteSymbol = "CBOT:ZN1!"
y2NoteSymbol = "CBOT:ZT1!"
bondSymbol = "CBOT:ZB1!"
mapMQ = map.new<float, string>()
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, "MenthorQ Alerts", text_color=txtC, bgcolor=bg, text_size=myFont)
table.cell(myTable, 3, 1, "SuperTrend", text_color=txtC, bgcolor=bg, text_size=myFont)
rowG = 2
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
ImLazy_SueMe_JustFoldIt(ouch_lol) =>
string sins = ""
sins := str.replace_all(ouch_lol, "J2025", "")
sins := str.replace_all(sins, "K2025", "")
sins := str.replace_all(sins, "L2025", "")
sins := str.replace_all(sins, "M2025", "")
sins := str.replace_all(sins, "N2025", "")
sins := str.replace_all(sins, "O2025", "")
sins := str.replace_all(sins, "P2025", "")
sins := str.replace_all(sins, "Q2025", "")
sins := str.replace_all(sins, "R2025", "")
sins := str.replace_all(sins, "S2025", "")
sins := str.replace_all(sins, "T2025", "")
sins := str.replace_all(sins, "U2025", "")
sins := str.replace_all(sins, "V2025", "")
sins := str.replace_all(sins, "W2025", "")
sins := str.replace_all(sins, "X2025", "")
sins := str.replace_all(sins, "Y2025", "")
sins := str.replace_all(sins, "Z2025", "")
sins := str.replace_all(sins, "A2026", "")
sins := str.replace_all(sins, "B2026", "")
sins := str.replace_all(sins, "C2026", "")
sins := str.replace_all(sins, "D2026", "")
sins := str.replace_all(sins, "E2026", "")
sins := str.replace_all(sins, "F2026", "")
sins := str.replace_all(sins, "G2026", "")
sins := str.replace_all(sins, "H2026", "")
sins := str.replace_all(sins, "I2026", "")
sins := str.replace_all(sins, "J2026", "")
sins := str.replace_all(sins, "K2026", "")
sins := str.replace_all(sins, "L2026", "")
sins := str.replace_all(sins, "M2026", "")
sins := str.replace_all(sins, "N2026", "")
sins := str.replace_all(sins, "O2026", "")
sins := str.replace_all(sins, "P2026", "")
sins := str.replace_all(sins, "Q2026", "")
sins := str.replace_all(sins, "R2026", "")
sins := str.replace_all(sins, "S2026", "")
sins := str.replace_all(sins, "T2026", "")
sins := str.replace_all(sins, "U2026", "")
sins := str.replace_all(sins, "V2026", "")
sins := str.replace_all(sins, "W2026", "")
sins := str.replace_all(sins, "X2026", "")
sins := str.replace_all(sins, "Y2026", "")
sins := str.replace_all(sins, "Z2026", "")
sins
updateTable(sym) =>
row = rowG
tf = timeframe.period
string[] xxx = str.split(sym, ":")
sins = str.replace_all(array.get(xxx, 1), "1!", "")
sins := ImLazy_SueMe_JustFoldIt(sins)
[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)
parseMQLines(sins, Close)
string homies = findMQMap(Close, Open, POpen, PClose, High, Low, PHigh, PLow)
log.info("parseMQLines homies = '" + homies + "'")
if (homies != '')
homies := "Bounced off " + 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 := 2
if(useES) // = input.bool(true, "Scan S&P 500", group="Scan List")
rowG := rowG + 1
updateTable(esSymbol)
if(useNQ) // = input.bool(true, "Scan NASDAQ", group="Scan List")
rowG := rowG + 1
updateTable(nqSymbol)
if(useVIX) // = input.bool(true, "Scan VIX", group="Scan List")
rowG := rowG + 1
updateTable(vixSymbol)
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(useGC) // = input.bool(false, "Scan Gold", group="Scan List")
rowG := rowG + 1
updateTable(goldSymbol)
if(useSI) // = input.bool(false, "Scan Silver", group="Scan List")
rowG := rowG + 1
updateTable(silverSymbol)
if(useHG) // = input.bool(false, "Scan Copper", group="CommScandities List")
rowG := rowG + 1
updateTable(copperSymbol)
if(useCL) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(oilSymbol)
if(usePLAT) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(platSymbol)
if(useGAS) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(gasSymbol)
if(useCORN) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(cornSymbol)
if(use5YNOTE) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(y5NoteSymbol)
if(use10YNOTE) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(y10NoteSymbol)
if(use2YNOTE) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(y2NoteSymbol)
if(useBOND) // = input.bool(false, "Scan Oil", group="Scan List")
rowG := rowG + 1
updateTable(bondSymbol)