Skip to content

Commit 0bd9876

Browse files
committed
Add railing_stops folder
1 parent 9b71b5e commit 0bd9876

File tree

5 files changed

+303
-0
lines changed

5 files changed

+303
-0
lines changed

‎trailing_stops/chandelier_exit.pine

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@version=4
2+
// Copyright (c) 2019-present, Alex Orekhov (everget)
3+
// Chandelier Exit script may be freely distributed under the terms of the GPL-3.0 license.
4+
study("Chandelier Exit", shorttitle="CE", overlay=true)
5+
6+
length = input(title="ATR Period", type=input.integer, defval=22)
7+
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
8+
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
9+
useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)
10+
highlightState = input(title="Highlight State ?", type=input.bool, defval=true)
11+
12+
atr = mult * atr(length)
13+
14+
longStop = (useClose ? highest(close, length) : highest(length)) - atr
15+
longStopPrev = nz(longStop[1], longStop)
16+
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
17+
18+
shortStop = (useClose ? lowest(close, length) : lowest(length)) + atr
19+
shortStopPrev = nz(shortStop[1], shortStop)
20+
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
21+
22+
var int dir = 1
23+
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
24+
25+
var color longColor = color.green
26+
var color shortColor = color.red
27+
28+
longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
29+
buySignal = dir == 1 and dir[1] == -1
30+
plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
31+
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
32+
33+
shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
34+
sellSignal = dir == -1 and dir[1] == 1
35+
plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
36+
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
37+
38+
midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)
39+
40+
longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
41+
shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
42+
fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
43+
fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)
44+
45+
changeCond = dir != dir[1]
46+
alertcondition(changeCond, title="Alert: CE Direction Change", message="Chandelier Exit has changed direction!")
47+
alertcondition(buySignal, title="Alert: CE Buy", message="Chandelier Exit Buy!")
48+
alertcondition(sellSignal, title="Alert: CE Sell", message="Chandelier Exit Sell!")

‎trailing_stops/halftrend.pine

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//@version=4
2+
// Copyright (c) 2021-present, Alex Orekhov (everget)
3+
// HalfTrend script may be freely distributed under the terms of the GPL-3.0 license.
4+
study("HalfTrend", overlay=true)
5+
6+
amplitude = input(title="Amplitude", defval=2)
7+
channelDeviation = input(title="Channel Deviation", defval=2)
8+
showArrows = input(title="Show Arrows", defval=true)
9+
showChannels = input(title="Show Channels", defval=true)
10+
11+
var int trend = 0
12+
var int nextTrend = 0
13+
var float maxLowPrice = nz(low[1], low)
14+
var float minHighPrice = nz(high[1], high)
15+
16+
var float up = 0.0
17+
var float down = 0.0
18+
float atrHigh = 0.0
19+
float atrLow = 0.0
20+
float arrowUp = na
21+
float arrowDown = na
22+
23+
atr2 = atr(100) / 2
24+
dev = channelDeviation * atr2
25+
26+
highPrice = high[abs(highestbars(amplitude))]
27+
lowPrice = low[abs(lowestbars(amplitude))]
28+
highma = sma(high, amplitude)
29+
lowma = sma(low, amplitude)
30+
31+
if nextTrend == 1
32+
maxLowPrice := max(lowPrice, maxLowPrice)
33+
34+
if highma < maxLowPrice and close < nz(low[1], low)
35+
trend := 1
36+
nextTrend := 0
37+
minHighPrice := highPrice
38+
else
39+
minHighPrice := min(highPrice, minHighPrice)
40+
41+
if lowma > minHighPrice and close > nz(high[1], high)
42+
trend := 0
43+
nextTrend := 1
44+
maxLowPrice := lowPrice
45+
46+
if trend == 0
47+
if not na(trend[1]) and trend[1] != 0
48+
up := na(down[1]) ? down : down[1]
49+
arrowUp := up - atr2
50+
else
51+
up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
52+
atrHigh := up + dev
53+
atrLow := up - dev
54+
else
55+
if not na(trend[1]) and trend[1] != 1
56+
down := na(up[1]) ? up : up[1]
57+
arrowDown := down + atr2
58+
else
59+
down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
60+
atrHigh := down + dev
61+
atrLow := down - dev
62+
63+
ht = trend == 0 ? up : down
64+
65+
var color buyColor = color.blue
66+
var color sellColor = color.red
67+
68+
htColor = trend == 0 ? buyColor : sellColor
69+
htPlot = plot(ht, title="HalfTrend", linewidth=2, color=htColor)
70+
71+
atrHighPlot = plot(showChannels ? atrHigh : na, title="ATR High", style=plot.style_circles, color=sellColor)
72+
atrLowPlot = plot(showChannels ? atrLow : na, title="ATR Low", style=plot.style_circles, color=buyColor)
73+
74+
fill(htPlot, atrHighPlot, title="ATR High Ribbon", color=sellColor)
75+
fill(htPlot, atrLowPlot, title="ATR Low Ribbon", color=buyColor)
76+
77+
buySignal = not na(arrowUp) and (trend == 0 and trend[1] == 1)
78+
sellSignal = not na(arrowDown) and (trend == 1 and trend[1] == 0)
79+
80+
plotshape(showArrows and buySignal ? atrLow : na, title="Arrow Up", style=shape.triangleup, location=location.absolute, size=size.tiny, color=buyColor)
81+
plotshape(showArrows and sellSignal ? atrHigh : na, title="Arrow Down", style=shape.triangledown, location=location.absolute, size=size.tiny, color=sellColor)
82+
83+
alertcondition(buySignal, title="Alert: HalfTrend Buy", message="HalfTrend Buy")
84+
alertcondition(sellSignal, title="Alert: HalfTrend Sell", message="HalfTrend Sell")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//@version=4
2+
// Copyright (c) 2021-present, Alex Orekhov (everget)
3+
// Nick Rypock Trailing Reverse (NRTR) script may be freely distributed under the terms of the GPL-3.0 license.
4+
study("Nick Rypock Trailing Reverse", shorttitle="NRTR", overlay=true)
5+
6+
k = input(title="Coefficient of Correction, %", type=input.float, minval=0, maxval=100, step=0.1, defval=2)
7+
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
8+
applyRibbon = input(title="Apply Ribbon ?", type=input.bool, defval=true)
9+
10+
var int trend = 0
11+
var float hp = close
12+
var float lp = close
13+
float nrtr = close
14+
15+
percentage = k * 0.01
16+
17+
if trend >= 0
18+
if close > hp
19+
hp := close
20+
hp
21+
nrtr := hp * (1 - percentage)
22+
if close <= nrtr
23+
trend := -1
24+
lp := close
25+
nrtr := lp * (1 + percentage)
26+
nrtr
27+
else
28+
if close < lp
29+
lp := close
30+
lp
31+
nrtr := lp * (1 + percentage)
32+
if close > nrtr
33+
trend := 1
34+
hp := close
35+
nrtr := hp * (1 - percentage)
36+
nrtr
37+
38+
var color longColor = color.green
39+
var color shortColor = color.red
40+
var color textColor = color.white
41+
42+
longStopPlot = plot(trend == 1 ? nrtr : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
43+
buySignal = trend == 1 and trend[1] == -1
44+
plotshape(buySignal ? nrtr : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
45+
plotshape(buySignal and showLabels ? nrtr : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=textColor, transp=0)
46+
47+
shortStopPlot = plot(trend == 1 ? na : nrtr, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
48+
sellSignal = trend == -1 and trend[1] == 1
49+
plotshape(sellSignal ? nrtr : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
50+
plotshape(sellSignal and showLabels ? nrtr : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=textColor, transp=0)
51+
52+
midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)
53+
54+
longFillColor = applyRibbon ? (trend == 1 ? longColor : na) : na
55+
shortFillColor = applyRibbon ? (trend == -1 ? shortColor : na) : na
56+
fill(midPricePlot, longStopPlot, title="Long Ribbon", color=longFillColor)
57+
fill(midPricePlot, shortStopPlot, title="Short Ribbon", color=shortFillColor)
58+
59+
changeCond = trend != trend[1]
60+
alertcondition(changeCond, title="Alert: NRTR Direction Change", message="NRTR has changed direction!")
61+
alertcondition(buySignal, title="Alert: NRTR Buy", message="NRTR Buy!")
62+
alertcondition(sellSignal, title="Alert: NRTR Sell", message="NRTR Sell!")

‎trailing_stops/parabolic_sar.pine

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@version=4
2+
// Copyright (c) 2019-present, Alex Orekhov (everget)
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)
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)
13+
14+
psar = sar(start, increment, maximum)
15+
dir = psar < close ? 1 : -1
16+
17+
psarColor = dir == 1 ? #3388bb : #fdcc02
18+
psarPlot = plot(psar, title="PSAR", style=plot.style_circles, linewidth=width, color=psarColor, transp=0)
19+
20+
var color longColor = color.green
21+
var color shortColor = color.red
22+
23+
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)
26+
27+
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)
30+
31+
midPricePlot = plot(ohlc4, title="", display=display.none)
32+
33+
fillColor = highlightState ? (dir == 1 ? longColor : shortColor) : na
34+
fill(midPricePlot, psarPlot, title="Trade State Filling", color=fillColor)
35+
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")

‎trailing_stops/supertrend.pine

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//@version=4
2+
// Copyright (c) 2019-present, Alex Orekhov (everget)
3+
// SuperTrend script may be freely distributed under the terms of the GPL-3.0 license.
4+
study("SuperTrend", overlay=true)
5+
6+
length = input(title="ATR Period", type=input.integer, defval=22)
7+
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3)
8+
src = input(title="Source", type=input.source, defval=hl2)
9+
wicks = input(title="Take Wicks into Account ?", type=input.bool, defval=true)
10+
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
11+
highlightState = input(title="Highlight State ?", type=input.bool, defval=true)
12+
13+
atr = mult * atr(length)
14+
15+
highPrice = wicks ? high : close
16+
lowPrice = wicks ? low : close
17+
doji4price = open == close and open == low and open == high
18+
19+
longStop = src - atr
20+
longStopPrev = nz(longStop[1], longStop)
21+
22+
if longStop > 0
23+
if doji4price
24+
longStop := longStopPrev
25+
else
26+
longStop := (lowPrice[1] > longStopPrev ? max(longStop, longStopPrev) : longStop)
27+
else
28+
longStop := longStopPrev
29+
30+
shortStop = src + atr
31+
shortStopPrev = nz(shortStop[1], shortStop)
32+
33+
if shortStop > 0
34+
if doji4price
35+
shortStop := shortStopPrev
36+
else
37+
shortStop := (highPrice[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop)
38+
else
39+
shortStop := shortStopPrev
40+
41+
var int dir = 1
42+
dir :=
43+
dir == -1 and highPrice > shortStopPrev ? 1 :
44+
dir == 1 and lowPrice < longStopPrev ? -1 :
45+
dir
46+
47+
var color longColor = color.green
48+
var color shortColor = color.red
49+
50+
longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
51+
buySignal = dir == 1 and dir[1] == -1
52+
plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
53+
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
54+
55+
shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
56+
sellSignal = dir == -1 and dir[1] == 1
57+
plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
58+
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
59+
60+
midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)
61+
62+
longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
63+
shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
64+
fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
65+
fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)
66+
67+
changeCond = dir != dir[1]
68+
alertcondition(changeCond, title="Alert: SuperTrend Direction Change", message="SuperTrend has changed direction!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
69+
alertcondition(buySignal, title="Alert: SuperTrend Buy", message="SuperTrend Buy!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
70+
alertcondition(sellSignal, title="Alert: SuperTrend Sell", message="SuperTrend Sell!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")

0 commit comments

Comments
 (0)