-
Notifications
You must be signed in to change notification settings - Fork 0
/
study-ha-confluence.pine
79 lines (65 loc) · 3.9 KB
/
study-ha-confluence.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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) HA + Confluence", overlay = true, max_bars_back = 1000, max_lines_count = 400, max_labels_count = 400)
// Inputs //
tradeDirection = input(defval = "All", title = "Long, Short or All Setups?", options = ["All", "Longs", "Shorts"])
checkSupertrend = input(defval = "Yes", title = "Check Supertrend Indicator", options = ["Yes", "No"])
checkRsiIndicator = input(defval = "Yes", title = "Check RSI Div Indicator", options = ["Yes", "No"])
checkRsiLevel = input(defval = "Yes", title = "Check RSI Level", options = ["Yes", "No"])
rsiBullLevel = input(defval = 50, title = "RSI Bull Level", minval = 1, maxval = 100, step = 1)
rsiBearLevel = input(defval = 50, title = "RSI Bear Level", minval = 1, maxval = 100, step = 1)
// Supertrend
atrPeriod = input(10, "Supertrend ATR Length")
factor = input(3, "Supertrend Factor")
// RSI DIV
lenFast = input(5, minval=1, title="Length Fast RSI")
lenSlow = input(14, minval=1, title="Length Slow RSI")
// Inputs //
// Calculation HA Values
haopen = 0.0
haclose = ((open + high + low + close)/4)
haopen := na(haopen[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
hahigh = max(high, max(haopen, haclose))
halow = min(low, min(haopen, haclose))
// HA colors
hacolor = haclose > haopen ? color.green : color.red
// Signals
turnGreen = haclose > haopen and haclose[1] <= haopen[1]
turnRed = haclose <= haopen and haclose[1] > haopen[1]
plotshape(turnGreen, style = shape.arrowup, location = location.belowbar, color = color.green)
plotshape(turnRed, style = shape.arrowdown, location = location.abovebar, color = color.red)
// Supertrend Indicator
[supertrend, direction] = supertrend(factor, atrPeriod)
isSupertrendBullish = direction < 0
isSupertrendBearish = direction > 0
// Debug
// plotshape(isSupertrendBullish, style = shape.triangleup, location = location.belowbar, color = color.green)
// plotshape(isSupertrendBearish, style = shape.triangledown, location = location.abovebar, color = color.red)
// RSI DIV Indicator
upFast = rma(max(change(close), 0), lenFast)
downFast = rma(-min(change(close), 0), lenFast)
rsiFast = downFast == 0 ? 100 : upFast == 0 ? 0 : 100 - (100 / (1 + upFast / downFast))
upSlow = rma(max(change(close), 0), lenSlow)
downSlow = rma(-min(change(close), 0), lenSlow)
rsiSlow = downSlow == 0 ? 100 : upSlow == 0 ? 0 : 100 - (100 / (1 + upSlow / downSlow))
//plotfast = plot(rsiFast, color=blue)
//plotslow = plot(rsiSlow, color=orange)
divergence = rsiFast - rsiSlow
isDivBullish = divergence > 0
isDivBearish = divergence < 0
// plotdiv = plot(divergence, color = divergence > 0 ? color.lime: color.red, linewidth = 2)
//band1 = hline(70,color=green)
//band0 = hline(30,color=red)
// band = hline(0)
// Normal RSI
rsi = rsi(close, lenSlow)
// Conditions
goLong = turnGreen and (checkSupertrend == 'No' or (checkSupertrend == 'Yes' and isSupertrendBullish)) and (checkRsiIndicator == 'No' or (checkRsiIndicator == 'Yes' and isDivBullish)) and (tradeDirection == "All" or tradeDirection == "Longs") and (checkRsiLevel == "No" or (checkRsiLevel == "Yes" and rsi < rsiBullLevel))
goShort = turnRed and (checkSupertrend == 'No' or (checkSupertrend == 'Yes' and isSupertrendBearish)) and (checkRsiIndicator == 'No' or (checkRsiIndicator == 'Yes' and isDivBearish)) and (tradeDirection == "All" or tradeDirection == "Shorts") and (checkRsiLevel == "No" or (checkRsiLevel == "Yes" and rsi > rsiBearLevel))
// Shapes
plotshape(goShort, location=location.abovebar, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=color.white, transp=0)
plotshape(goLong, location=location.belowbar, style=shape.labelup, color=color.green, size=size.tiny, text="Buy", textcolor=color.white, transp=0)
// Alerts
alertcondition(goShort, title='Sell Signal', message='')
alertcondition(goLong, title='Buy Signal', message='')