-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOptim_Oversampling.c
130 lines (98 loc) · 3.37 KB
/
Optim_Oversampling.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
// #define FULLY_OPTIM
// #define STOP_OPTIM_NO_TAKEPROFIT
// #define STOP_TAKEPROFIT_OPTIM
// #define INDIC_OPTIM
#define NOT_OPTIM
void tradeRSI()
{
TimeFrame = 4; // 4-hourly trade filter
vars PriceH4 = series(price());
#ifdef FULLY_OPTIM
vars Filter = series(LowPass(PriceH4, 200));
TimeFrame = 1; //Entries/Exits on 1-hourly
vars PriceH1 = series(price());
vars rsi = series(RSI(PriceH1, 14));
int overbought = optimize(70,60, 90,5);
int oversold = optimize(30, 10, 40, 5);
Stop = optimize(4, 1, 12, 1)*ATR(100);
Trail = Stop;
TakeProfit = optimize(4, 1, 12, 1)*ATR(100);
if(crossOver(rsi, overbought) and PriceH1[0] < Filter[0] and NumOpenShort == 0) enterShort();
if(crossUnder(rsi, oversold) and PriceH1[0] > Filter[0] and NumOpenLong == 0) enterLong();
#endif
#ifdef STOP_OPTIM_NO_TAKEPROFIT
vars Filter = series(LowPass(PriceH4, 200));
TimeFrame = 1; //Entries/Exits on 1-hourly
vars PriceH1 = series(price());
vars rsi = series(RSI(PriceH1, 14));
int overbought = 70;
int oversold = 70;
Stop = Trail = optimize(4, 1, 12, 1)*ATR(100);
if(crossOver(rsi, overbought) and PriceH1[0] < Filter[0] and NumOpenShort == 0) enterShort();
if(crossUnder(rsi, oversold) and PriceH1[0] > Filter[0] and NumOpenLong == 0) enterLong();
#endif
#ifdef STOP_TAKEPROFIT_OPTIM
vars Filter = series(LowPass(PriceH4, 200));
TimeFrame = 1; //Entries/Exits on 1-hourly
vars PriceH1 = series(price());
vars rsi = series(RSI(PriceH1, 14));
int overbought = 70;
int oversold = 70;
Stop = optimize(4, 1, 12, 1)*ATR(100);
Trail = Stop;
TakeProfit = optimize(4, 1, 12, 1)*ATR(100);
if(crossOver(rsi, overbought) and PriceH1[0] < Filter[0] and NumOpenShort == 0) enterShort();
if(crossUnder(rsi, oversold) and PriceH1[0] > Filter[0] and NumOpenLong == 0) enterLong();
#endif
#ifdef INDIC_OPTIM
vars Filter = series(LowPass(PriceH4, 200));
TimeFrame = 1; //Entries/Exits on 1-hourly
vars PriceH1 = series(price());
vars rsi = series(RSI(PriceH1, 14));
int overbought = optimize(70,60, 90,5);
int oversold = optimize(30, 10, 40, 5);
Stop = TakeProfit = 4*ATR(100);
Trail = Stop;
if(crossOver(rsi, overbought) and PriceH1[0] < Filter[0] and NumOpenShort == 0) enterShort();
if(crossUnder(rsi, oversold) and PriceH1[0] > Filter[0] and NumOpenLong == 0) enterLong();
#endif
#ifdef NOT_OPTIM
vars Filter = series(LowPass(PriceH4, 200));
TimeFrame = 1; //Entries/Exits on 1-hourly
vars PriceH1 = series(price());
vars rsi = series(RSI(PriceH1, 14));
int overbought = 70;
int oversold = 30;
Stop = TakeProfit = 4*ATR(100);
Trail = Stop;
if(crossOver(rsi, overbought) and PriceH1[0] < Filter[0] and NumOpenShort == 0) enterShort();
if(crossUnder(rsi, oversold) and PriceH1[0] > Filter[0] and NumOpenLong == 0) enterLong();
#endif
}
void tradeDigi()
{
vars Price = series(price());
vars filter = series(Roof(Price, 50, 100));
Stop = optimize(3, 1, 6, 0.5)*ATR(100);
Trail = 0.5*Stop;
TrailLock = 10;
TrailSpeed = 200;
if(valley(filter)) reverseLong(1);
if(peak(filter)) reverseShort(1);
}
function run()
{
set(TESTNOW|PLOTNOW|PARAMETERS|FACTORS|ALLCYCLES);
StartDate= 2010;
NumWFOCycles = 10;
BarPeriod = 60;
LookBack = 150;
// NumSampleCycles = 4;
while(asset(loop("EUR/USD", "AUD/USD")))//, "NZD/USD")))
while(algo("rsi"))
// while(algo(loop("rsi", "digi")))
{
if(Algo == "rsi") tradeRSI();
else if(Algo == "digi") tradeDigi();
}
}