-
Notifications
You must be signed in to change notification settings - Fork 45
/
highest-lowest-visual.txt
52 lines (38 loc) · 2.54 KB
/
highest-lowest-visual.txt
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
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator("Donald - Highest-Lowest Visual", shorttitle = "Donald - Highest-Lowest Visual", overlay = true)
import jdehorty/KernelFunctions/2 as kernels
/// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎 ///
int length = input(6, group = "Settings")
int offset = input(4, group = "Settings")
series float src = input(close, group = "Settings")
bool Use_High_and_Low = input(false, group = "Settings")
// Visual
bool bar_color = input(false, group = "Visual")
color color_up = input(color.blue, group = "Visual")
color color_dn = input(color.red, group = "Visual")
// Kernel Settings
lookbackWindow = input.int(8, "Lookback Window", tooltip="The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50", group="Kernel Settings")
relativeWeighting = input.float(8., "Relative Weighting", step=0.25, tooltip="Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25", group="Kernel Settings")
startBar = input.int(25, "Start Regression at Bar", tooltip="Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25", group="Kernel Settings")
highestHigh = kernels.rationalQuadratic(ta.highest(low, length), lookbackWindow, relativeWeighting, startBar)
lowestLow = kernels.rationalQuadratic(ta.lowest(high, length), lookbackWindow, relativeWeighting, startBar)
/// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉 ///
var series float hlt = 0.0
series float upper = highestHigh
series float lower = lowestLow
hlt := src > upper ?
lower : src < lower ?
upper : nz(hlt)
/// 𝙋𝙇𝙊𝙏 ///
color color = src >= hlt
? color_up
: color_dn
p1 = plot(hlt,
color = color,
style = plot.style_cross
)
p2 = plot(src, display = display.none)
fill(p1, p2, color = color.new(color, 80))
// Bar color
barcolor(bar_color ? color : na)