-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTurtleTrendFollowStrategy.easylanguage
59 lines (48 loc) · 1.29 KB
/
TurtleTrendFollowStrategy.easylanguage
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
inputs:
EntryLength(20),
ExitLength(10),
RiskPercentage(1),
ATRMultiplier(2),
ATRLength(20),
EnableFilter(false),
BenchmarkSymbol("SPX");
variables:
UpperChannel(0),
LowerChannel(0),
ExitLong(0),
Qty(0),
BenchmarkClose(0),
Filter(false),
BuyCondition(false),
SellCondition(false),
ATRValue(0);
// **********************************
// Functions
// **********************************
// **********************************
// Perform calculations and analysis
// **********************************
// Basic
UpperChannel = Highest(High[1], EntryLength);
LowerChannel = Lowest(Low[1], EntryLength);
ExitLong = Lowest(Low[1], ExitLength);
// Trade amount
ATRValue = AvgTrueRange(ATRLength);
Qty = ((RiskPercentage / 100) * NetProfit) / (ATRMultiplier * ATRValue);
// Filter
if EnableFilter then
BenchmarkClose = Close of data2;
Filter = BenchmarkClose[1] >= Average(Close of data2, 200)
else
Filter = true;
BuyCondition = Close crosses over UpperChannel and Filter;
SellCondition = Close crosses under ExitLong;
// **********************************
// Manage trade
// **********************************
// Entry
if BuyCondition then
Buy("Long") next bar at market;
// Exit
if SellCondition then
Sell("Long") next bar at market;