-
Notifications
You must be signed in to change notification settings - Fork 4
/
PivotReversalStrategy_v1.txt
63 lines (45 loc) · 1.58 KB
/
PivotReversalStrategy_v1.txt
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
53
54
55
56
57
58
59
60
61
62
63
//@version=4
strategy("QuantNomad - Significant Pivot Reversal Strategy", shorttitle = "SPPS", overlay=true)
// Inputs
leftBars = input(4, title = 'PP Left Bars')
rightBars = input(2, title = 'PP Right Bars')
atr_length = input(14, title = 'ATR Length')
atr_mult = input(0.1, title = 'ATR Mult')
// Pivot High Significant Function
pivotHighSig(left, right) =>
pp_ok = true
atr = atr(atr_length)
for i = 1 to left
if (high[right] < high[right+i] + atr * atr_mult)
pp_ok := false
for i = 0 to right-1
if (high[right] < high[i] + atr * atr_mult)
pp_ok := false
pp_ok ? high[right] : na
// Pivot Low Significant Function
pivotLowSig(left, right) =>
pp_ok = true
atr = atr(atr_length)
for i = 1 to left
if (low[right] > low[right+i] - atr * atr_mult)
pp_ok := false
for i = 0 to right-1
if (low[right] > low[i] - atr * atr_mult)
pp_ok := false
pp_ok ? low[right] : na
swh = pivotHighSig(leftBars, rightBars)
swl = pivotLowSig (leftBars, rightBars)
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = false
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])
if (le)
strategy.entry("PivRevLE", strategy.long, comment="PivRevLE", stop=hprice + syminfo.mintick)
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = false
se := swl_cond ? true : (se[1] and low < lprice ? false : se[1])
if (se)
strategy.entry("PivRevSE", strategy.short, comment="PivRevSE", stop=lprice - syminfo.mintick)