-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy path[RS]Donchian Fans.pinescript
82 lines (69 loc) · 2.86 KB
/
[RS]Donchian Fans.pinescript
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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos
//@version=4
study(title="[RS]Donchian Fans", shorttitle="DF", overlay=true)
// Initiate bars:
var int b = -1, b := b + 1
//----------------------------------------------------------------------------------
// Required functions:
f_highest_bar(_source, _bars, _length)=>
float _h_value = _source
int _h_bar = _bars
for _i = 0 to max(_length-1, 0)
bool _isSourceOver = _source[_i] > _h_value
if _isSourceOver
_h_value := _source[_i]
_h_bar := _bars[_i]
[_h_value, _h_bar]
f_lowest_bar(_source, _bars, _length)=>
float _l_value = _source
int _l_bar = _bars
for _i = 0 to max(_length-1, 0)
bool _isSourceUnder = _source[_i] < _l_value
if _isSourceUnder
_l_value := _source[_i]
_l_bar := _bars[_i]
[_l_value, _l_bar]
f_line(_x1, _y1, _r, _color)=>
var line _li = na
line.delete(id=_li)
_li := line.new(x1=_x1-1, y1=_y1 - _r, x2=_x1, y2=_y1, xloc=xloc.bar_index, extend=extend.right, color=_color, style=line.style_dashed, width=1)
//----------------------------------------------------------------------------------
int length = input(defval=100, title='Channel length:', minval=1)
[h_price, h_bar] = f_highest_bar(high, b, length)
[l_price, l_bar] = f_lowest_bar(low, b, length)
float mid = (h_price + l_price) / 2
plot(series=h_price, title='H', color=color.black, linewidth=1, style=plot.style_line, transp=20)
plot(series=mid, title='M', color=color.black, linewidth=1, style=plot.style_line, transp=20)
plot(series=l_price, title='L', color=color.black, linewidth=1, style=plot.style_line, transp=20)
var float r = atr(length)
if change(mid) != 0
r := atr(length)
var line h_1_04 = na
var line h_1_08 = na
var line h_1_16 = na
var line h_1_32 = na
var line h_1_64 = na
var line l_1_04 = na
var line l_1_08 = na
var line l_1_16 = na
var line l_1_32 = na
var line l_1_64 = na
bool is_new_h = h_price > h_price[1]
bool is_new_l = l_price < l_price[1]
vhb = valuewhen(high >= h_price, h_bar, 0)
vhp = valuewhen(high >= h_price, h_price, 0)
vlb = valuewhen(low <= l_price, l_bar, 0)
vlp = valuewhen(low <= l_price, l_price, 0)
if is_new_l
h_1_04 := f_line(vhb, vhp, -r * (1. / 04.), color.black)
h_1_08 := f_line(vhb, vhp, -r * (1. / 08.), color.black)
h_1_16 := f_line(vhb, vhp, -r * (1. / 16.), color.black)
h_1_32 := f_line(vhb, vhp, -r * (1. / 32.), color.black)
h_1_64 := f_line(vhb, vhp, -r * (1. / 64.), color.black)
if is_new_h
l_1_04 := f_line(vlb, vlp, r * (1. / 04.), color.black)
l_1_08 := f_line(vlb, vlp, r * (1. / 08.), color.black)
l_1_16 := f_line(vlb, vlp, r * (1. / 16.), color.black)
l_1_32 := f_line(vlb, vlp, r * (1. / 32.), color.black)
l_1_64 := f_line(vlb, vlp, r * (1. / 64.), color.black)