-
Notifications
You must be signed in to change notification settings - Fork 2
/
5MA_X_L.pine
109 lines (106 loc) · 3.43 KB
/
5MA_X_L.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
Script Name: 5MA_X_L
Author: FinTasticTrading
Description: This is a 5 day moving average crossing long strategy in 10 min. chart, used in short term momentum trading strategy.
Momentum trading Strategy: When S&P 500 index is at up trend (or above 60 sma ), buy 10+ stocks in top 20% stock RS ranking at equal weight using this MA5X_L strategy. Change stocks when any stock exited by algorithm.
Back test start since...
PineScript code:
Pine Script™ strategy
5MA_X_L
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
//@version=4
// © FinTasticTrading 2021/2/14
// This is a 5 day moving average crossing long strategy, used in short term momentum trading strategy.
// Momentum trading Strategy: When S&P 500 index is at up trend (or above 60 sma), buy 10+ stocks in top 20% stock RS ranking at equal weight using this MA5X_L strategy. Change stocks when any stock exited by algorithm.
// Back test start since 2020/7/1, each long entry for condition 1 is $30000, condition 2 is $20000, with max of 2 long positions.
// Setup: 10 minutes chart
// Buy condition 1) 3 wma cross up 180 wma (5day) 2) 3wma > 60wma > 180wma UP Trend Arrangement (UTA)
// Exit condition 1) 3 wma cross under 180 wma 2) position profit > 20% and 3 wma cross under 6 ATRs line (green)
//@version=4
strategy("MA5X_L", overlay=true, pyramiding=2,default_qty_type=strategy.cash, default_qty_value=100000)
s_len = input( 3 )
m_len = input( 78 ) // 2 day moving average
l_len = input( 195) // equal to 5 Day moving average
xl_len = input(390) // 10 day moving average
//Draw WMAs
s_ma = wma(close,s_len)
m_ma = wma(close,m_len)
l_ma = wma(close,l_len)
xl_ma = sma(close,xl_len)
plot(s_ma, color=color.yellow, linewidth=2)
plot(m_ma, color=color.fuchsia, linewidth=2)
plot(l_ma, color=color.blue, linewidth=2)
plot(xl_ma, color = color.gray, linewidth=2)
//ATR Stop Profit , length = 40 or 1 day
Periods = input(title="ATR Period", type=input.integer, defval=40)
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=6.0)
sl=hl2-(Multiplier*atr(Periods))
sl1 = nz(sl[1], sl)
sl := s_ma[1] > sl1 ? max(sl, sl1) : sl
plot(strategy.position_size > 0 ? sl:na, title="Stop Loss", style=plot.style_linebr, linewidth=2, color=color.green)
//Backtest since
condition100 = time>=timestamp(2020, 07, 01, 00, 00)
//Long Entry Condition 1 : s_ma Cross UP l_ma
if crossover(s_ma, l_ma) and condition100
strategy.entry("X Up", strategy.long, qty = 30000/close, comment="X Up")
//Long Entry Condition 2 : s_ma > m_ma > l_ma
condition31 = s_ma>m_ma and m_ma>l_ma
condition32 = condition31[1]==false and condition31 == true and condition100
strategy.entry("UTA", strategy.long, qty = 20000/close, when = condition32, comment="UTA")
//Long Exit Condition 1 : 3 wma cross under 180 wma
condition50 = crossunder(s_ma, l_ma)
strategy.close_all(when = condition50, comment="X Dn")
//Long Exit Condition 2 : position profit > 20% and 3 wma cross under 6 ATRs line (green)
strategy.close_all(when = crossunder(close,sl) and strategy.openprofit>30000*0.2, comment="Stop")
Expand (52 lines)