-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAbdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4.pine
79 lines (78 loc) · 2.4 KB
/
Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4.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
Script Name: Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4
Author: MasAbdoli
Description: This simple strategy is just based of a single indicator, my dear Heikin Ashi Smoothed!
Just try and enjoy it ;)
PineScript code:
Pine Script™ strategy
Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4
Copy code
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
//Masoud Abdoli
//Heikin Ashi Smoothed Buy & Sell Strategy Rev.4
//Date: 01-Oct-2021
//@version=4
strategy(title="Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4", shorttitle="Heikin-Ashi Smoothed Rev.4", overlay=true,
initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
MaPeriod = input (title="Moving Average Period?", type=input.integer, defval=65, minval=5, maxval=100, step=5)
maOpen = ema(open , MaPeriod)
maHigh = ema(high , MaPeriod)
maLow = ema(low , MaPeriod)
maClose = ema(close, MaPeriod)
haClose = (maOpen+maHigh+maLow+maClose)/4
haOpen = 0.0
haOpen:= na(haOpen[1]) ? (maOpen[1]+maClose[1])/2 : (haOpen[1]+haClose[1])/2
haHigh = max(maHigh, max(haClose, haOpen))
haLow = min(maLow , max(haClose, haOpen))
plotcandle(haOpen, haHigh, haLow, haClose, title="heikin-Ashi smoothed", color=haOpen>haClose ? color.orange : color.blue)
B0 = haClose - haOpen
B1 = haClose[1] - haOpen[1]
B2 = haClose[2] - haOpen[2]
BuyCondition = B0 > 0.0 and B1 > 0.0 and B2 > 0.0 and haClose > haClose[1] and haClose[1] > haClose[2]
SellCondition= B0 < 0.0 and B1 < 0.0 and B2 < 0.0 and haClose < haClose[1] and haClose[1] < haClose[2]
last_signal = 0
Buy_final = BuyCondition and (nz(last_signal[1]) == 0 or nz(last_signal[1]) ==-1)
Sell_final = SellCondition and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
last_signal := Buy_final ? 1 : Sell_final ? -1 : last_signal[1]
plotshape(Buy_final , style=shape.labelup , location=location.belowbar, color=color.blue, title="Buy label" , text="BUY" , textcolor=color.white)
plotshape(Sell_final, style=shape.labeldown, location=location.abovebar, color=color.red , title="Sell label", text="SELL", textcolor=color.white)
strategy.entry("Buy", strategy.long, when=Buy_final)
strategy.close("Buy", when=Sell_final)
Expand (39 lines)