|
1 |
| -//@version=4 |
| 1 | +//@version=6 |
2 | 2 | // Copyright (c) 2019-present, Alex Orekhov (everget)
|
3 | 3 | // 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) |
5 | 5 |
|
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) |
13 | 10 |
|
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) |
15 | 20 | dir = psar < close ? 1 : -1
|
16 | 21 |
|
17 | 22 | 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) |
19 | 24 |
|
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) |
22 | 30 |
|
23 | 31 | 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) |
26 | 34 |
|
27 | 35 | 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) |
30 | 38 |
|
31 |
| -midPricePlot = plot(ohlc4, title="", display=display.none) |
| 39 | +midPricePlot = plot(ohlc4, title = '', display = display.none, editable = false) |
32 | 40 |
|
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) |
35 | 43 |
|
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