-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathstrategy.py
68 lines (48 loc) · 1.33 KB
/
strategy.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a strategy file for you to refer,
this example is taking from TradeStation 程式交易全攻略,page 293, ISBN 978-957-0477-99-3
Author: TerryH, email: terryh.tp at gmail.com,
License: BSD
"""
PARAS={
"ran":82,
}
VARS = {
"longentry":99999,
"shortentry":0,
"longex":0,
"shortex":99999,
"count":0,
}
#MA2 = map(round,AverageFC(C,5))
if DATE[0] != DATE[1]:
#print "NEW DATE", DATE[0],TIME[0]
longentry = OPEN[0]+ran
shortentry = OPEN[0]-ran
if MARKETPOSITION == 0 and count == 0 and HH >= longentry:
BUY("BUY",HH)
if MARKETPOSITION == 0 and count == 0 and LL <= shortentry:
SELL("SELL",LL)
if MARKETPOSITION > 0 and HIGH[0]-ran > longentry:
longex = HIGH[0]-ran
count = 1
if MARKETPOSITION < 0 and LOW[0]+ran < shortentry:
shortex = LOW[0]+ran
count = 1
if MARKETPOSITION > 0 and count == 1 and LL <= longex:
EXITLONG("LONG EXIT",LL)
if MARKETPOSITION < 0 and count == 1 and HH >= shortex:
EXITSHORT("SHORT EXIT",HH)
if MARKETPOSITION == 0 and count == 1:
longentry = CLOSE[1]+ran
shortentry = CLOSE[0]-ran
longex = 0
shortex = 99999
count = 0
if TIME[0] >= 133000 and MARKETPOSITION != 0:
# print "Clear Market Position"
EXITLONG("GYXL",C[0])
EXITSHORT("GYXS",C[0])
print DATE[0],TIME[0],O[0],C[0],MKS