-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSharkWaveTrend Pine5.pine
More file actions
executable file
·163 lines (122 loc) · 8.44 KB
/
SharkWaveTrend Pine5.pine
File metadata and controls
executable file
·163 lines (122 loc) · 8.44 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
//@version=5
indicator(title = 'SharkWaveTrend', shorttitle = 'SharkWaveTrend v1.3')
wtChannelLen = input.int(9, title = 'WT Channel Length', group="SharkWaveTrend")
wtAverageLen = input.int(12, title = 'WT Average Length', group="SharkWaveTrend")
wtMASource = input.source(hlc3, title = 'WT MA Source', group="SharkWaveTrend")
wtMALen = input.int(3, title = 'WT MA Length', group="SharkWaveTrend")
c_intense_red = color.new(color.rgb(255, 35, 35), transp=30)
c_regular_red = color.new(color.red, transp=60)
c_intense_green = color.new(color.lime, transp=30)
c_regular_green = color.new(color.green, transp=60)
obLevel = input.int(53, title = 'WT Overbought Level 1', group="SharkWaveTrend")
osLevel = input.int(-53, title = 'WT Oversold Level 1', group="SharkWaveTrend")
wtDivOBLevel = input.int(45, title = 'WT Bearish Divergence min', group="SharkWaveTrend")
wtDivOSLevel = input.int(-65, title = 'WT Bullish Divergence min', group="SharkWaveTrend")
wtDivOBLevel_add = input.int(15, title = 'WT 2nd Bearish Divergence', group="SharkWaveTrend")
wtDivOSLevel_add = input.int(-40, title = 'WT 2nd Bullish Divergence 15 min', group="SharkWaveTrend")
rsiMFIperiod = input.int(60,title = 'MFI Period', group="SharkWaveTrend")
rsiMFIMultiplier = input.int(150, title = 'MFI Area multiplier', group="SharkWaveTrend")
rsiMFIPosY = input.float(2.5, title = 'MFI Area Y Pos', group="SharkWaveTrend")
rsiSRC = input.source(close, title = 'RSI Source', group="SharkWaveTrend")
rsiLen = input.int(14, title = 'RSI Length', group="SharkWaveTrend")
rsiOversold = input.int(30, title = 'RSI Oversold', minval = 0, maxval = 50, group="SharkWaveTrend")
rsiOverbought = input.int(60, title = 'RSI Overbought', minval = 50, maxval = 100, group="SharkWaveTrend")
rsiDivOBLevel = input.int(60, title = 'RSI Bearish Divergence min', group="SharkWaveTrend")
rsiDivOSLevel = input.int(30, title = 'RSI Bullish Divergence min', group="SharkWaveTrend")
stochSRC = input.source(close, title = 'Stochastic RSI Source', group="SharkWaveTrend")
stochLen = input.int(14, title = 'Stochastic RSI Length', group="SharkWaveTrend")
stochRsiLen = input.int(14, title = 'RSI Length ', group="SharkWaveTrend")
stochKSmooth = input.int(3, title = 'Stochastic RSI K Smooth', group="SharkWaveTrend")
stochDSmooth = input.int(3, title = 'Stochastic RSI D Smooth', group="SharkWaveTrend")
colorRed = #ff0000
colorGreen = #3fff00
f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
f_findDivs(src, topLimit, botLimit, useLimits) =>
fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na
fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na
highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]
highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]
lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]
lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]
bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev
bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev
bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev
bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev
[fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden]
f_rsimfi(_period, _multiplier, _tf) => request.security(syminfo.tickerid, _tf, ta.sma(((close - open) / (high - low)) * _multiplier, _period) - rsiMFIPosY)
f_wavetrend(src, chlen, avg, malen, tf) =>
tfsrc = request.security(syminfo.tickerid, tf, src)
esa = ta.ema(tfsrc, chlen)
de = ta.ema(math.abs(tfsrc - esa), chlen)
ci = (tfsrc - esa) / (0.015 * de)
wt1 = request.security(syminfo.tickerid, tf, ta.ema(ci, avg))
wt2 = request.security(syminfo.tickerid, tf, ta.sma(wt1, malen))
wtVwap = wt1 - wt2
wtOversold = wt2 <= osLevel
wtOverbought = wt2 >= obLevel
wtCross = ta.cross(wt1, wt2)
wtCrossUp = wt2 - wt1 <= 0
wtCrossDown = wt2 - wt1 >= 0
wtCrosslast = ta.cross(wt1[2], wt2[2])
wtCrossUplast = wt2[2] - wt1[2] <= 0
wtCrossDownlast = wt2[2] - wt1[2] >= 0
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]
f_stochrsi(_src, _stochlen, _rsilen, _smoothk, _smoothd, _log, _avg) =>
src = _log ? math.log(_src) : _src
rsi = ta.rsi(src, _rsilen)
kk = ta.sma(ta.stoch(rsi, rsi, rsi, _stochlen), _smoothk)
d1 = ta.sma(kk, _smoothd)
avg_1 = math.avg(kk, d1)
k = _avg ? avg_1 : kk
[k, d1]
rsi = ta.rsi(rsiSRC, rsiLen)
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)
[stochK, stochD] = f_stochrsi(stochSRC, stochLen, stochRsiLen, stochKSmooth, stochDSmooth, true, true)
[wtFractalTop, wtFractalBot, wtLow_prev, wtBearDiv, wtBullDiv, wtBearDivHidden, wtBullDivHidden] = f_findDivs(wt2, wtDivOBLevel, wtDivOSLevel, true)
[wtFractalTop_add, wtFractalBot_add, wtLow_prev_add, wtBearDiv_add, wtBullDiv_add, wtBearDivHidden_add, wtBullDivHidden_add] = f_findDivs(wt2, wtDivOBLevel_add, wtDivOSLevel_add, true)
[wtFractalTop_nl, wtFractalBot_nl, wtLow_prev_nl, wtBearDiv_nl, wtBullDiv_nl, wtBearDivHidden_nl, wtBullDivHidden_nl] = f_findDivs(wt2, 0, 0, false)
[rsiFractalTop, rsiFractalBot, rsiLow_prev, rsiBearDiv, rsiBullDiv, rsiBearDivHidden, rsiBullDivHidden] = f_findDivs(rsi, rsiDivOBLevel, rsiDivOSLevel, true)
[rsiFractalTop_nl, rsiFractalBot_nl, rsiLow_prev_nl, rsiBearDiv_nl, rsiBullDiv_nl, rsiBearDivHidden_nl, rsiBullDivHidden_nl] = f_findDivs(rsi, 0, 0, false)
[stochFractalTop, stochFractalBot, stochLow_prev, stochBearDiv, stochBullDiv, stochBearDivHidden, stochBullDivHidden] = f_findDivs(stochK, 0, 0, false)
buySignal = wtCross and wtCrossUp and wtOversold
buySignalDiv = (wtBullDiv or wtBullDiv_add or stochBullDiv or rsiBullDiv)
sellSignal = wtCross and wtCrossDown and wtOverbought
sellSignalDiv = wtBearDiv or wtBearDiv_add or stochBearDiv or rsiBearDiv
plotchar(buySignal ? -107 : na, title = 'Buy circle', char='•', color = color.new(#82ff2f, 0), location = location.absolute, size = size.small)
plotchar(sellSignal ? 105 : na , title = 'Sell circle', char='•', color = color.new(#ff2727, 0), location = location.absolute, size = size.small)
plotchar(buySignalDiv ? -106 : na, title = 'Divergence buy circle', char='*', color = color.new(#82ff2f, 0), location = location.absolute, size = size.small, offset = -2)
plotchar(sellSignalDiv ? 106 : na, title = 'Divergence sell circle', char='*', color = color.new(#ff2727, 0), location = location.absolute, size = size.small, offset = -2)
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="Shark")
rsiSourceInput = input.source(close, "Source", group="Shark")
length2 = input.int(30, minval=1, group="Shark")
src = input.source(close, title="Source", group="Shark")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group="Shark")
offset = input.int(0, "Offset", minval = -500, maxval = 500, group="Shark")
HighlightBreaches = input.bool(true, title="Highlight Oversold/Overbought", group="Shark")
bApply25and75 = input.bool(true, title="Apply 25/75 RSI rule", group="Shark")
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
ema400 = ta.ema(close, 400)
ema800 = ta.ema(close, 800)
wapwap = ta.vwap(close)
bTouchedLine = (ema50<high and ema50>low) or (ema200<high and ema200>low) or (ema400<high and ema400>low) or (ema800<high and ema800>low) or (wapwap<high and wapwap>low)
upTR = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
downTR = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsiM = downTR == 0 ? 100 : upTR == 0 ? 0 : 100 - (100 / (1 + upTR / downTR))
basis = ta.sma(rsiM, length2)
dev = mult * ta.stdev(rsiM, length2)
upper = basis + dev
lower = basis - dev
bBelow25 = rsiM < 26
bAbove75 = rsiM > 74
if not bApply25and75
bBelow25 := true
bAbove75 := true
b_color = (rsiM > upper and bAbove75) ? c_regular_red : (rsiM < lower and bBelow25) ? c_regular_green : na
if bTouchedLine and b_color == color.new(color.red, transp=60)
b_color := c_intense_red
if bTouchedLine and b_color == color.new(color.green, transp=60)
b_color := c_intense_green
bgcolor(HighlightBreaches ? b_color : na)