-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMacTastic.txt
More file actions
executable file
·76 lines (59 loc) · 3.03 KB
/
MacTastic.txt
File metadata and controls
executable file
·76 lines (59 loc) · 3.03 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
//@version=4
study(title="MacTastic", shorttitle="MacTastic", overlay=true)
// Idea from - https://www.youtube.com/watch?v=vI7Rpexh9X8
var isLong = false
var isShort = false
// CONFIG
rsiLengthInput = input(15, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input(close, "Source", group="RSI Settings")
periodK = input(14, title="%K Length", minval=1, group="Stochastic")
smoothK = input(1, title="%K Smoothing", minval=1, group="Stochastic")
fastMA = input(title="Fast moving average", defval=12, minval=7, group="MACD")
slowMA = input(title="Slow moving average", defval=26, minval=7, group="MACD")
signalLength = input(9,minval=1, group="MACD")
adxThreshold = input(title="ADX Threshold", defval=0, minval=0, group="ADX")
adxlen = input(14, title="ADX Smoothing", group="ADX")
dilen = input(14, title="DI Length", group="ADX")
// ADX
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// MACD
[currMacd,_,_] = macd(close[0], fastMA, slowMA, signalLength)
[prevMacd,_,_] = macd(close[1], fastMA, slowMA, signalLength)
signal = ema(currMacd, signalLength)
// RSI
up = rma(max(change(rsiSourceInput), 0), rsiLengthInput)
down = rma(-min(change(rsiSourceInput), 0), rsiLengthInput)
rsiM = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
// STOCHASTIC - 80/20 upper/lower bands
k = sma(stoch(close, high, low, periodK), smoothK)
stochOS = k[1] <= 20 or k[2] <= 20 or k[3] <= 20 or k[4] <= 20 or k[5] <= 20 or k[6] <= 20 or k[7] <= 20 or k[8] <= 20 or k[9] <= 20
stochOB = k[1] >= 80 or k[2] >= 80 or k[3] >= 80 or k[4] >= 80 or k[5] >= 80 or k[6] >= 80 or k[7] >= 80 or k[8] >= 80 or k[9] >= 80
weGoUp = sig > adxThreshold and not isLong and rsiM >= 50 and currMacd > signal and stochOS
weGoDown = sig > adxThreshold and not isShort and rsiM <= 50 and currMacd < signal and stochOB
upThrust = weGoUp and not weGoUp[1] and not weGoUp[2] and not weGoUp[3] and not weGoUp[4]
downThrust = weGoDown and not weGoDown[1] and not weGoDown[2] and not weGoDown[3] and not weGoDown[4]
// PLOT THE THINGS
plotshape(upThrust ? hl2 : na, title="MacTastic", text="MT", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.rgb(56, 182, 93), textcolor=color.white)
plotshape(downThrust ? hl2 : na, title="MacTastic", text="MT", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.rgb(145, 42, 61), textcolor=color.white)
if weGoUp
isLong := true
isShort := false
if weGoDown
isLong := false
isShort := true
// ALERTS
alertcondition(upThrust, title='MacTastic BUY', message='MacTastic BUY')
alertcondition(downThrust, title='MacTastic SELL', message='MacTastic SELL')