-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrat_CNTR.c
33 lines (24 loc) · 1.19 KB
/
Strat_CNTR.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
function tradeCounterTrend()
{
BarPeriod = 240;
// Counter trend trading is affected by market cycles and more sensitive to the bar period than trend trading
// Bar periods that are in sync with the worldwide markets - such as 4 or 8 hours - ...
// ... are especially profitable with this type of trading
LookBack = 500;
set(PARAMETERS);
StartDate = 2005;
NumWFOCycles = 10;
vars Price = series(price());
vars Filtered = series(BandPass(Price,optimize(30,20,40),0.5));
// BandPass is similar to LowPass + it dampens short cycles => curve with medium-period peaks and valleys
vars Signal = series(FisherN(Filtered,500)); // Normalisation in order to compare with threshold
var Threshold = optimize(1,0.5,1.5,0.1);
checkEquity(); // equity curve trading
// buy and sell
Stop = optimize(4,2,10) * ATR(100);
Trail = 4*ATR(100); // 4 average candles away from the current price
// Trailing often - not always - improves the profit of a strategy, ...
// but is almost always better than placing a profit target
if(crossUnder(Signal,-Threshold)) enterLong(); // price is supposedly close to the bottom of the main cycle
else if(crossOver(Signal,Threshold)) enterShort(); // price is closed to peak
}