-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSI+Engulfing.pine
65 lines (44 loc) · 2.06 KB
/
RSI+Engulfing.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © abdullah2202
//@version=5
indicator(title="Engulfing", shorttitle="E", overlay=true)
prevCandles = input.int(2, title="No. Previous Candles")
// Identify engulfing candles
atr = ta.sma(ta.tr(true), 14)
bullishFlip = true
bearishFlip = true
for i=1 to prevCandles
if close[i] < open[i] and bullishFlip
bullishFlip := true
else
bullishFlip := false
if close[i] > open[i] and bearishFlip
bearishFlip := true
else
bearishFlip := false
bullishEC = close > open[1] and bullishFlip
bearishEC = close < open[1] and bearishFlip
//bullishEC = close > open[1] and close[1] < open[1] and close[2] < open[2] and close[3] < open[3]
//bearishEC = close < open[1] and close[1] > open[1] and close[2] > open[2] and close[3] > open[3]
// Get candle size - If engulfing candle is greater than 2x, dont do.
//BullishCZ = ((close - open) / (open[1] - close[1])) < 3
//BearishCZ = ((open - close) / (close[1] - open[1])) < 3
// Get Candle Size against ATR
candleATR = (high - low) > atr
// Calculate Wicks
bullishWickUp = high - close
bullishWickDown = open - low
bullishBody = close - open
bearishWickUp = high - open
bearishWickDown = close - low
bearishBody = open - close
// Make sure wicks are smaller than body of candle
bullishWicks = (bullishWickUp < bullishBody) and (bullishWickUp > 0) and (bullishWickDown > 0)
bearishWicks = (bearishWickDown < bearishBody) and (bearishWickDown > 0) and (bullishWickUp > 0)
bullishSignal = bullishEC and candleATR
bearishSignal = bearishEC and candleATR
// Plot signals to chart
plotshape(bullishSignal, title="Long", location=location.belowbar, color=color.green, style=shape.triangleup, text="Long")
plotshape(bearishSignal, title="Short", location=location.abovebar, color=color.red, style=shape.triangledown, text="Short")
// Send out an alert if this candle meets our conditions
alertcondition(bearishSignal or bullishSignal, title="Engulfing Trade Alert!", message="Engulfing Signal for XXX")