-
Notifications
You must be signed in to change notification settings - Fork 0
/
study-hma-trend.pine
44 lines (34 loc) · 1.93 KB
/
study-hma-trend.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
//@version=4
study("(Study) HMA Signals", overlay = true)
// Inputs
tradeDirection = input(defval = "All", title = "Backtest Only Long, Only Shorts or All Setups?", options = ["All", "Longs", "Shorts"])
enableTrailingStop = input(defval = "No", title = "Enable Trailing Stop?", options = ["Yes", "No"])
trailingStopPerc = input(defval = 2, title = "Trailing Stop Loss %", minval = .5, step = .5, maxval = 100) / 100
slPerc = input(defval = 2, title = "Stop Loss %", minval = 0.5, step = 0.5, maxval = 100) / 100
tpPerc = input(defval = 3, title = "Take Profit %", minval = 0.5, step = 0.5, maxval = 100) / 100
fromDate = input(title="From Date", type=input.time, defval=timestamp("01 Jan 2021 00:00 -0400"))
length = input(24)
src = input(hl2)
showcross = input(true, "Show cross over/under")
hma(_src, _length)=>
wma((2 * wma(_src, _length / 2)) - wma(_src, _length), round(sqrt(_length)))
hma3(_src, _length)=>
p = length/2
wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)
a = hma(src, length)
b = hma3(src, length)
c = b > a ? color.lime : color.red
p1 = plot(a,color=c,linewidth=1,transp=75)
p2 = plot(b,color=c,linewidth=1,transp=75)
fill(p1,p2,color=c,transp=55)
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]
// Conditions
buySignal = showcross and crossup and (tradeDirection == "All" or tradeDirection == "Longs")
sellSignal = showcross and crossdn and (tradeDirection == "All" or tradeDirection == "Shorts")
// Shapes
plotshape(showcross and crossdn ? a : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="[Sell]", textcolor=color.white, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.absolute, style=shape.labelup, color=color.green, size=size.tiny, text="[Buy]", textcolor=color.white, transp=0, offset=-1)
// Alerts
alertcondition(sellSignal, title='Sell Signal', message='')
alertcondition(buySignal, title='Buy Signal', message='')