Skip to content

Commit cec49c1

Browse files
authored
Update parabolic_sar.pine
1 parent dd60049 commit cec49c1

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

‎trailing_stops/parabolic_sar.pine

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1-
//@version=4
1+
//@version=6
22
// Copyright (c) 2019-present, Alex Orekhov (everget)
33
// Parabolic SAR script may be freely distributed under the terms of the GPL-3.0 license.
4-
study("Parabolic SAR", shorttitle="PSAR", overlay=true)
4+
indicator('Parabolic SAR', shorttitle = 'PSAR', overlay = true)
55

6-
start = input(title="Start", type=input.float, step=0.001, defval=0.02)
7-
increment = input(title="Increment", type=input.float, step=0.001, defval=0.02)
8-
maximum = input(title="Maximum", type=input.float, step=0.01, defval=0.2)
9-
width = input(title="Point Width", type=input.integer, minval=1, defval=2)
10-
highlightStartPoints = input(title="Highlight Start Points ?", type=input.bool, defval=true)
11-
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
12-
highlightState = input(title="Highlight State ?", type=input.bool, defval=true)
6+
const string calcGroup = 'Calculation'
7+
start = input.float(0.02, step = 0.001, title = 'Start', group = calcGroup)
8+
increment = input.float(0.02, step = 0.001, title = 'Increment', group = calcGroup)
9+
maximum = input.float(0.2, step = 0.01, title = 'Maximum', group = calcGroup)
1310

14-
psar = sar(start, increment, maximum)
11+
const string visualGroup = 'Visuals'
12+
width = input.int(2, minval = 1, title = 'Point Width', group = visualGroup)
13+
showLabels = input.bool(true, title = 'Show Buy/Sell Labels', group = visualGroup)
14+
highlightStartPoints = input.bool(true, title = 'Highlight Start Points', group = visualGroup)
15+
highlightState = input.bool(true, title = 'Highlight State', group = visualGroup)
16+
17+
//---
18+
19+
psar = ta.sar(start, increment, maximum)
1520
dir = psar < close ? 1 : -1
1621

1722
psarColor = dir == 1 ? #3388bb : #fdcc02
18-
psarPlot = plot(psar, title="PSAR", style=plot.style_circles, linewidth=width, color=psarColor, transp=0)
23+
psarPlot = plot(psar, title = 'PSAR', style = plot.style_circles, linewidth = math.max(1, width), color = psarColor)
1924

20-
var color longColor = color.green
21-
var color shortColor = color.red
25+
const color textColor = color.white
26+
const color longColor = color.green
27+
const color shortColor = color.red
28+
const color longFillColor = color.new(color.green, 85)
29+
const color shortFillColor = color.new(color.red, 85)
2230

2331
buySignal = dir == 1 and dir[1] == -1
24-
plotshape(buySignal and highlightStartPoints ? psar : na, title="Long Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
25-
plotshape(buySignal and showLabels ? psar : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
32+
plotshape(buySignal and highlightStartPoints ? psar : na, title = 'Long Start', location = location.absolute, style = shape.circle, size = size.tiny, color = longColor)
33+
plotshape(buySignal and showLabels ? psar : na, title = 'Buy Label', text = 'Buy', location = location.absolute, style = shape.labelup, size = size.tiny, color = longColor, textcolor = textColor)
2634

2735
sellSignal = dir == -1 and dir[1] == 1
28-
plotshape(sellSignal and highlightStartPoints ? psar : na, title="Short Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
29-
plotshape(sellSignal and showLabels ? psar : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
36+
plotshape(sellSignal and highlightStartPoints ? psar : na, title = 'Short Start', location = location.absolute, style = shape.circle, size = size.tiny, color = shortColor)
37+
plotshape(sellSignal and showLabels ? psar : na, title = 'Sell Label', text = 'Sell', location = location.absolute, style = shape.labeldown, size = size.tiny, color = shortColor, textcolor = textColor)
3038

31-
midPricePlot = plot(ohlc4, title="", display=display.none)
39+
midPricePlot = plot(ohlc4, title = '', display = display.none, editable = false)
3240

33-
fillColor = highlightState ? (dir == 1 ? longColor : shortColor) : na
34-
fill(midPricePlot, psarPlot, title="Trade State Filling", color=fillColor)
41+
fillColor = highlightState ? (dir == 1 ? longFillColor : dir == -1 ? shortFillColor : na) : na
42+
fill(midPricePlot, psarPlot, title = 'Trade State Filling', color = fillColor)
3543

36-
changeCond = dir != dir[1]
37-
alertcondition(changeCond, title="Alert: PSAR Direction Change", message="PSAR has changed direction!")
38-
alertcondition(buySignal, title="Alert: PSAR Long", message="PSAR Long")
39-
alertcondition(sellSignal, title="Alert: PSAR Short", message="PSAR Sell")
44+
alertcondition(dir != dir[1], title = 'Direction Change', message = 'PSAR has changed direction, {{exchange}}:{{ticker}}')
45+
alertcondition(buySignal, title = 'Long', message = 'PSAR Long, {{exchange}}:{{ticker}}')
46+
alertcondition(sellSignal, title = 'Short', message = 'PSAR Sell, {{exchange}}:{{ticker}}')

0 commit comments

Comments
 (0)