-
Notifications
You must be signed in to change notification settings - Fork 2
/
AVG Stochastic Strategy [M30 Backtesting].pine
122 lines (121 loc) · 2.34 KB
/
AVG Stochastic Strategy [M30 Backtesting].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
Script Name: AVG Stochastic Strategy [M30 Backtesting]
Author: inno14
Description: 1. AVG Stochastic Calculate
1.1 AVG %K is calculated by apply EMA with smooth K period on Average of Original Stochastic %k & %d
+ avg_k=ema((%k+%d)/2,smoothK)
1.2 AVG %D is calculated by apply EMA with %d period on AVG %K
+ avg_d=ema(avg_k,periodD)
2. Parameter
+ %K Length: 21
+ %K Smoothing: 3
+ %D Smoothing: 3
+ Symbol: BTC/USDT
+ Timeframe: M30
+ Pyramiding:...
PineScript code:
Pine Script™ strategy
AVG Stochastic Strategy [M30 Backtesting]
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
//@version=5
//1. AVG Stochastic Calculate
//1.1 AVG %K is calculated by apply EMA with smooth K period on Average of Original Stochastic %k & %d
//+ avg_k=ema((%k+%d)/2,smoothK)
//1.2 AVG %D is calculated by apply EMA with %d period on AVG %K
//+ avg_d=ema(avg_k,periodD)
//2. Parameter
//+ %K Length: 21
//+ %K Smoothing: 3
//+ %D Smoothing: 3
//+ Symbol: BTC/USDT
//+ Timeframe: M30
//+ Pyramiding: Maximum 3 orders at the same direction.
//3. Signal
//3.1 Buy Signal
//+ Entry: AVG %K crossover AVG %D and AVG %D < 20
//+ Exit: AVG %D > 80
//3.2 Sell Signal
//+ Entry: AVG %K crossunder AVG %D and AVG %D > 80
//+ Exit: AVG %D < 20
strategy(title="AVG Stochastic Strategy [M30 Backtesting]", overlay=true, pyramiding=3)
periodK = input.int(21, title="%K Length", minval=1)
smoothK = input.int(3, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
_avg_k=ta.ema(math.avg(k,d),smoothK)
_avg_d=ta.ema(_avg_k,periodD)
up=
_avg_k[1]<_avg_d[1]
and _avg_k>_avg_d
and _avg_d<20
dn=
_avg_k[1]>_avg_d[1]
and _avg_k<_avg_d
and _avg_d>80
var arr_val=0
if up
arr_val:=1
strategy.entry("Long", strategy.long)
if dn
arr_val:=-1
strategy.entry("Short", strategy.short)
if up[1] or dn[1]
arr_val:=0
plotarrow(arr_val,title="Signal",colorup=color.green,colordown=color.red)
if _avg_d>80
strategy.close("Long")
if _avg_d<20
strategy.close("Short")
//EOF
Expand (51 lines)