-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChad's ATR.pine
67 lines (49 loc) · 2.54 KB
/
Chad's ATR.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
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
//@version=4
study("Chad'\s Average True Range [ATR] (@tradeprophet)","Chad\'s ATR (@tradeprophet)", true)
ds(str) => label.new(bar_index, high, str)
dsl(str) =>
if barstate.islast
ds(str)
d(val) => ds(tostring(val))
dl(val) => dsl(tostring(val))
period = input(20, "Period")
isOuterPlotShown = input(false, "Show Outer Plot?")
isOuterBandLinesShown = input(true, "Show Outer Band Lines?")
isATRLinesShown = input(true, "Show ATR Lines?")
outerMultiplier = input(2, "Outer Multiplier")
dailyOpen = security(syminfo.tickerid, "D", open)
atrPeriod = input(20, minval=1, title='ATR Period')
atrActual = security(syminfo.tickerid, "D", atr(atrPeriod))
outerSpread = atrActual * outerMultiplier
upperATRPrice = dailyOpen + atrActual
lowerATRPrice = dailyOpen - atrActual
// ATR Lines & Labels
upperATRLine = line.new(x1=bar_index-1, y1=upperATRPrice, x2=bar_index, y2=upperATRPrice, extend=extend.right, color=color.black)
line.delete(upperATRLine[1])
upperATRLabel = label.new(bar_index, upperATRPrice, text="D ATR", style=label.style_none)
label.delete(upperATRLabel[1])
lowerATRLine = line.new(x1=bar_index-1, y1=lowerATRPrice, x2=bar_index, y2=lowerATRPrice, extend=extend.right, color=color.black)
line.delete(lowerATRLine[1])
lowerATRLabel = label.new(bar_index, lowerATRPrice, text="D ATR", style=label.style_none)
label.delete(lowerATRLabel[1])
//
// Outer ATR Lines & Labels
//
// Upper
upperATRBandPrice = upperATRPrice + outerSpread
// upperATRBandPlot = plot(upperATRBandPrice, color=color.gray, linewidth=2, transp=100)
// upperATRPlot = plot(upperATRPrice, color=color.gray, linewidth=2, transp=100)
// fill(upperATRBandPlot, upperATRPlot, color.black)
upperATRBandLine = line.new(x1=bar_index-1, y1=upperATRBandPrice, x2=bar_index, y2=upperATRBandPrice, extend=extend.right, color=color.black)
line.delete(upperATRBandLine[1])
upperATRBandLabel = label.new(bar_index, upperATRBandPrice, text="D ATR BAND", style=label.style_none)
label.delete(upperATRBandLabel[1])
// Lower
lowerATRBandPrice = lowerATRPrice - outerSpread
// lowerATRBandPlot = plot(lowerATRBandPrice, color=color.gray, linewidth=2, transp=100)
// lowerATRPlot = plot(lowerATRPrice, color=color.gray, linewidth=2, transp=100)
// fill(lowerATRBandPlot, lowerATRPlot, color.black)
lowerATRBandLine = line.new(x1=bar_index-1, y1=lowerATRBandPrice, x2=bar_index, y2=lowerATRBandPrice, extend=extend.right, color=color.black)
line.delete(lowerATRBandLine[1])
lowerATRBandLabel = label.new(bar_index, lowerATRBandPrice, text="D ATR BAND", style=label.style_none)
label.delete(lowerATRBandLabel[1])