View difference between Paste ID: mbyRmNLs and AkRxD5xK
SHOW: | | - or go back to the newest paste.
1
//@version=4
2
study("SuperTrend TEST", overlay=true)
3
4
//This SuperTrend software is used on 15 minute chart. The second part of SuperTrend is for security on 120 minute timeframe.
5
//SuperTrend should give signal on 15 minute chart only when SuperTrend is in same direction of 120 minute timeframe.
6
length = input(title="ATR Period", type=input.integer, defval=7)
7
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=5)
8
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
9
10
atr = mult * atr(length)
11
12
longStop = hl2 - atr
13
longStopPrev = nz(longStop[1], longStop)
14
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
15
16
shortStop = hl2 + atr
17
shortStopPrev = nz(shortStop[1], shortStop)
18
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
19
20
dir = 1
21
dir := nz(dir[1], dir)
22
dir := dir == -1 and close > shortStopPrev ? 1 : 
23
   dir == 1 and close < longStopPrev ? -1 : dir
24
25
longColor = color.blue
26
shortColor = color.red
27
28
//---------------
29
//SuperTrend on 120 minute timeframe.
30
31
length120 = input(title="ATR Period", type=input.integer, defval=7)
32
mult120 = input(title="ATR Multiplier", type=input.float, step=0.1, defval=5)
33
34
atr120 = mult120 * atr(length120)
35
sechigh120 = security(syminfo.ticker, "120", (high), lookahead = barmerge.lookahead_on)
36
seclow120 = security(syminfo.ticker, "120", (low), lookahead = barmerge.lookahead_on)
37
secclose120 = security(syminfo.ticker, "120", (close), lookahead = barmerge.lookahead_on)
38
longStop120 = (sechigh120 + seclow120)/2 - atr120
39
longStopPrev120 = nz(longStop120[1], longStop120)
40
longStop120 := secclose120[1] > longStopPrev120 ? max(longStop120, longStopPrev120) : longStop120
41
42
shortStop120 = (sechigh120 + seclow120)/2 + atr120
43
shortStopPrev120 = nz(shortStop120[1], shortStop120)
44
shortStop120 := secclose120[1] < shortStopPrev120 ? min(shortStop120, shortStopPrev120) : shortStop120
45
46
dir120 = 1
47
dir120 := nz(dir120[1], dir120)
48
dir120 := dir120 == -1 and secclose120 > shortStopPrev120 ? 1 : 
49
   dir120 == 1 and secclose120 < longStopPrev120 ? -1 : dir120
50
51
longColor120 = color.blue
52
shortColor120 = color.red
53
54
//---------------
55
56
plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
57
buySignal15 = dir == 1 and dir[1] == -1
58
buySignal120 = dir120 == 1 and dir120[1] == -1
59
plotshape(buySignal15 and buySignal120 ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
60-
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)
60+
plotshape(buySignal15 and buySignal120 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)
61
62
plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
63
sellSignal15 = dir == -1 and dir[1] == 1
64
sellSignal120 = dir120 == -1 and dir120[1] == 1
65
plotshape(sellSignal15 and sellSignal120 ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
66-
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)
66+
plotshape(sellSignal15 and sellSignal120 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)