-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrat_1NightStand.c
146 lines (123 loc) · 5.77 KB
/
Strat_1NightStand.c
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
135
136
137
138
139
140
141
142
143
144
145
146
// #define FULLY_OPTIM
// #define STOP_OPTIM
// #define SMA_OPTIM
// #define SMA_AND_STOP_OPTIM
// #define ONLY_REINV_OPTIM
#define NOT_OPTIM
function tradeOneNightStand()
{
#ifdef FULLY_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, optimize(10,5,20)));
vars SMALong = series(SMA(Price, optimize(40,30,80,5)));
Stop = optimize(100,100,500,10) * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
Margin = 0.1 * OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital);
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
Margin = 0.1 * OptimalFShort * Capital * sqrt(1 + ProfitClosed/Capital);
enterShort(0,SellStop);
}
}
#endif
#ifdef STOP_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, 10));
vars SMALong = series(SMA(Price, 40));
Stop = optimize(100,100,500,10) * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
enterShort(0,SellStop);
}
}
#endif
#ifdef SMA_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, optimize(10,5,20)));
vars SMALong = series(SMA(Price, optimize(40,30,80,5)));
Stop = 100 * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
enterShort(0,SellStop);
}
}
#endif
#ifdef SMA_AND_STOP_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, optimize(10,5,20)));
vars SMALong = series(SMA(Price, optimize(40,30,80,5)));
Stop = optimize(100,100,500,10) * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
enterShort(0,SellStop);
}
}
#endif
#ifdef ONLY_REINV_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, 10));
vars SMALong = series(SMA(Price, 40));
Stop = 100 * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
Margin = 0.1 * OptimalFLong * Capital * sqrt(1 + ProfitClosed/Capital);
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
Margin = 0.1 * OptimalFShort * Capital * sqrt(1 + ProfitClosed/Capital);
enterShort(0,SellStop);
}
}
#endif
#ifdef NOT_OPTIM
vars Price = series(price());
vars SMAShort = series(SMA(Price, 10));
vars SMALong = series(SMA(Price, 40));
Stop = 100 * PIP;
var BuyStop = HH(10) + 1*PIP;
var SellStop = LL(10) - 1*PIP;
if(between(tow(),42355,50005)) { // check the time interval around thursday midnight
if (SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong) && NumOpenLong == 0 && NumPendingLong == 0) {
enterLong(0,BuyStop);
}
else if (SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong) && NumOpenShort == 0 && NumPendingShort == 0) {
enterShort(0,SellStop);
}
}
#endif
if (dow() != 4 && dow() != 5 && dow() != 6) // exit on Monday morning's open, or Tuesday morning's open, if Monday is a holiday
{
exitShort();
exitLong();
}
}
function run()
{
set(LOGFILE|PLOTNOW);
// set(PARAMETERS,FACTORS,LOGFILE,PLOTNOW); // generate and use optimized parameters and factors
BarPeriod = 15;
// while(asset(loop("EUR/USD","USD/CHF","GBP/USD","USD/JPY")))
asset("USD/CHF");
tradeOneNightStand();
}