-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3-Signal Directional Trend Strategy for E-Minis.pine
134 lines (130 loc) · 2.84 KB
/
3-Signal Directional Trend Strategy for E-Minis.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Script Name: 3-Signal Directional Trend Strategy for E-Minis
Author: TradeStation
Description: This is a conceptual strategy intended for E-mini S&P 500 futures with hourly bars.
It uses three signals, going long or short when two or more change in the same direction.
First is MACD. A positive oscillator is considered a bullish signal and a falling oscillator is interpreted bearishly.
Next, stochastics are used as an overbought/oversold indicator....
PineScript code:
Pine Script™ strategy
3-Signal Directional Trend Strategy for E-Minis
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
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
// By TradeStation
//@version=5
strategy("Mov Avg Speed Strategy", overlay=true)
src = input(close, title="Source")
// MA Speed
avg_len = input.int(50, minval=1, title="Avg Length", group="MA Speed")
roc_len = input.int(1, minval=1, title="Rate of Change Length", group="MA Speed")
avg_roc_len = input.int(10, minval=1, title="Avg Rate of Change Length", group="MA Speed")
// Stochastic
stoch_len = input.int(14, minval=1, title="Stochastic Length", group="Stochastic")
smooth_k = input.int(3, minval=1, title="Stochastic Smooth K", group="Stochastic")
overbought = input.float(80, title="Stochastic Overbought", group="Stochastic")
oversold = input.float(20, title="Stochastic Oversold", group="Stochastic")
// MACD
fast_length = input(12, title="Fast Length", group="MACD")
slow_length = input(26, title="Slow Length", group="MACD")
macd_avg_length = input.int(9, title="MACD Avg Length", minval=1, group="MACD")
// MA Speed
avg = ta.sma(src, avg_len)
roc = ta.roc(avg, roc_len)
avg_roc = ta.sma(roc, avg_roc_len)
avg_roc_signal = avg_roc > 0 ? 1 : avg_roc < 0 ? -1 : 0
// Stochastic k
k = ta.sma(ta.stoch(close, high, low, stoch_len), smooth_k)
stochastic_signal = k <= oversold ? 1 : k >= overbought ? -1 : 0
// MACD
fast_ma = ta.ema(src, fast_length)
slow_ma = ta.ema(src, slow_length)
macd = fast_ma - slow_ma
macd_avg = ta.ema(macd, macd_avg_length)
macd_signal = macd_avg > macd_avg[1] ? 1 : macd_avg < macd_avg[1] ? -1 : 0
// set the signal couint
long_count = 0
short_count = 0
if macd_signal == 1
long_count += 1
else if macd_signal == -1
short_count += 1
if stochastic_signal == 1
long_count += 1
else if stochastic_signal == -1
short_count += 1
if avg_roc_signal == 1
long_count += 1
else if avg_roc_signal == -1
short_count += 1
if (long_count >= 2)
strategy.entry("Long", strategy.long)
if (short_count >= 2)
strategy.entry("Short", strategy.short)
Expand (67 lines)