-
Notifications
You must be signed in to change notification settings - Fork 0
/
study-st-bounce.pine
52 lines (42 loc) · 2.03 KB
/
study-st-bounce.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ossy1717
//@version=4
study("(Study) ST Bounce", overlay = true)
// Inputs //
tradeDirection = input(defval = "All", title = "Long, Short or All Setups?", options = ["All", "Longs", "Shorts"])
stAtrPeriod = input(10, "ATR Length")
stFactor = input(3, "Factor")
gap = input(defval = 1, title = "Price Gap Factor", minval = 0, maxval = 100, step = .1, tooltip="Gap between price and ST line") / 100
// Inputs //
// ST
[supertrend, direction] = supertrend(stFactor, stAtrPeriod)
// Helpers
calculate_price_gap(isLong) =>
retValue = false
// If gap factor is 0, means entering when bar touches the ST line
if(isLong)
retValue := low <= supertrend * (1 + gap)
else
retValue := high >= supertrend * (1 - gap)
retValue
// Conditions
upTrend = direction < 0
downTrend = direction > 0
goLong = upTrend and calculate_price_gap(true) and (tradeDirection == "All" or tradeDirection == "Longs")
goShort = downTrend and calculate_price_gap(false) and (tradeDirection == "All" or tradeDirection == "Shorts")
// Visuals
// Debug //
// bodyMiddle = plot((open + close) / 2, display=display.none)
// upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
// downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)
// fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
// fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
// Debug //
// Shapes
if(goLong)
label.new(x = bar_index, y = low, yloc = yloc.belowbar, text="Enter", textcolor=color.white, color = color.green, style = label.style_label_up, size = size.small)
if(goShort)
label.new(x = bar_index, y = high, yloc = yloc.abovebar, text="Enter", textcolor=color.white, color = color.red, style = label.style_label_down, size = size.small)
// Alerts
alertcondition(goLong, title='Buy Signal', message='')
alertcondition(goShort, title='Sell Signal', message='')