-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInd - Elder Price Channel.pine
executable file
·36 lines (28 loc) · 1.62 KB
/
Ind - Elder Price Channel.pine
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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © owroc
//@version=5
indicator(title='Elder Price Channel', shorttitle='Elder Price Chanel', overlay=true, max_lines_count = 200, max_bars_back = 100)
//input values
//len is based on 3 month look back so 52wks / 4qtr = 13wks/qtr * 5 trading days/wk = 65 days
len = input.int(65, title='Days to Look Back', minval=1)
per = input(95, title='Percentage of Values')
ref = input(26, title='EMA Length')
src = input(close, title='Source')
float width = 0
//Calculate the number of values that will be included inside the envelope
valuesInChannel = int(per / 100 * len)
//Assign the slow ema value for the bar to a variable
centerLine = ta.ema(src, ref)
//define the array that will hold all the closing values for each bar
//remeber in pine that the current bar is 0 and array index represents earlier bars
a = array.new_float(0)
if bar_index > 70
//load the array with the last <len> values and sort
for i = 0 to len - 1 by 1
array.push(a, math.abs(src[i] - centerLine[i]))
array.sort(a, order.ascending)
width := array.max(array.slice(a, 0, valuesInChannel))
if barstate.islast
for i = 0 to valuesInChannel - 1
line.new(bar_index[i + 1], centerLine[i + 1] + width, bar_index[i], centerLine[i] + width, xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.blue, width=3)
line.new(bar_index[i + 1], centerLine[i + 1] - width, bar_index[i], centerLine[i] - width, xloc=xloc.bar_index, extend=extend.none, style=line.style_dotted, color=color.blue, width=3)