-
Notifications
You must be signed in to change notification settings - Fork 2
/
50-100-200 Moving Average Strategy.pine
53 lines (52 loc) · 1.33 KB
/
50-100-200 Moving Average Strategy.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
Script Name: 50-100-200 Moving Average Strategy
Author: Kushn1r
Description: Buy on 50SMA crossover 100 sell when 100 case under 200
PineScript code:
Pine Script™ strategy
50/100/200 Moving Average Strategy
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
//@version=5
strategy(title='50/100/200 Moving Average Strategy', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000000, currency=currency.USD)
// Only Enter Long Positions //
strategy.risk.allow_entry_in(strategy.direction.long)
// Create Inputs //
FastMA = ta.sma(close, 50)
MediumMA = ta.sma(close, 100)
SlowMA = ta.sma(close, 200)
// Backtest Start Date Inputs //
startDate = input.int(title='Start Date', defval=1, minval=1, maxval=31)
startMonth = input.int(title='Start Month', defval=1, minval=1, maxval=12)
startYear = input.int(title='Start Year', defval=2016, minval=1800, maxval=2100)
afterStartDate = time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)
// Submit Orders //
if afterStartDate and ta.crossover(FastMA, MediumMA)
strategy.entry(id='BUY', direction=strategy.long)
if afterStartDate and ta.crossunder(MediumMA, SlowMA)
strategy.entry(id='SELL', direction=strategy.short)
Expand (26 lines)