-
Notifications
You must be signed in to change notification settings - Fork 14
/
CandlestickPatterns-HOLP-LOHP.pine
52 lines (45 loc) · 2.99 KB
/
CandlestickPatterns-HOLP-LOHP.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
//@version=5
indicator('Candlestick Patterns - HOLP-LOHP', shorttitle='HOLP-LOHP', format=format.price, precision=0, overlay=true)
bool enableHOLPLOHP = input.bool(true, 'Enable HOLP/LOHP signal')
bool _bPivot = input.bool(false, 'Enable Pivot Point')
_p = input.int(title='Lookback Periods', defval=10, minval=2)
_b2bar = input.bool(false, 'Trigger bar needs to close below/above pivot bar and its prior bar?')
var _boolNewLow = 0
_sessionLow = 0.0
lastLoBar = -ta.lowestbars(low, _p + 1)
if low[0] < ta.lowest(_p)[1]
_sessionLow := low
_boolNewLow := 1
_arrowHOLP = 0.0
_conditionHOLP = if _b2bar
_boolNewLow == 1 and close[0] > high[lastLoBar] and close[0] > high[lastLoBar + 1] // The HOLP needs to close above the highs of session low bar and its prior bar, hence it's name
else
_boolNewLow == 1 and close[0] > high[lastLoBar] // The HOLP needs to close above the highs of session low bar
if _conditionHOLP
_arrowHOLP := close
_boolNewLow := 0
if _bPivot
label.new(bar_index[lastLoBar], na, "▲\n" + str.tostring(low[lastLoBar], format.mintick), yloc = yloc.belowbar, style = label.style_none, textcolor = color.black, size = size.normal)
var _boolNewHigh = 0
_sessionHigh = 0.0
lastHiBar = -ta.highestbars(high, _p + 1)
if high[0] > ta.highest(_p)[1]
_sessionHigh := high
_boolNewHigh := 1
_arrowLOHP = 0.0
_conditionLOHP = if _b2bar
_boolNewHigh == 1 and close[0] < low[lastHiBar] and close[0] < low[lastHiBar + 1]
else
_boolNewHigh == 1 and close[0] < low[lastHiBar]
if _conditionLOHP
_arrowLOHP := close
_boolNewHigh := 0
if _bPivot
label.new(bar_index[lastHiBar], na, str.tostring(high[lastHiBar], format.mintick) + "\n▼", yloc = yloc.abovebar, style = label.style_none, textcolor = color.black, size = size.normal)
plotshape(enableHOLPLOHP?_conditionLOHP:na, title = 'LOHP', style=shape.diamond, location=location.abovebar, offset=0, color=color.new(color.yellow, 50), size=size.small, display = enableHOLPLOHP?display.all:display.data_window)
plotshape(enableHOLPLOHP?_conditionHOLP:na, title = 'HOLP', style=shape.diamond, location=location.belowbar, offset=0, color=color.new(color.yellow, 50), size=size.small, display = enableHOLPLOHP?display.all:display.data_window)
plotshape(_sessionLow, title = 'Session Low', style=shape.xcross, location=location.belowbar, offset=0, color=color.new(color.maroon, 0), size=size.small, display=display.none)
plotshape(_sessionHigh, title = 'Session High', style=shape.xcross, location=location.abovebar, offset=0, color=color.new(color.maroon, 0), size=size.small, display=display.none)
// If ploting circles are confusing on the chart, use char instead
// plotchar(enableHOLPLOHP?_conditionLOHP:na, title = 'LOHP', char = '⌉', location = location.abovebar, color=color.new(color.maroon, 50), size=size.small, display=display.all)
// plotchar(enableHOLPLOHP?_conditionHOLP:na, title = 'HOLP', char = '⌋', location = location.belowbar, color=color.new(color.maroon, 50), size=size.small, display=display.all)