-
Notifications
You must be signed in to change notification settings - Fork 5
/
SuperTrendFollowStrategy.easylanguage
54 lines (42 loc) · 1.2 KB
/
SuperTrendFollowStrategy.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
Inputs:
ATRPeriod(10),
Factor(3.0),
RiskPercentage(1.00),
ATRMultiplier(2),
ATRLength(20),
EnableFilter(true),
BenchmarkSymbol("SPX");
Vars:
BenchmarkClose(0),
Filter(True),
Qty(0),
SuperTrendValue(0),
Direction(0),
BuyCondition(False),
SellCondition(False);
// **********************************
// Functions
// **********************************
// **********************************
// Perform calculations and analysis
// **********************************
// Filter
if EnableFilter then
BenchmarkClose = Close of data2;
Filter = BenchmarkClose[1] >= Average(Close of data2, 200)
else
Filter = true;
// Calculate trade amount
Qty = (RiskPercentage/100 * Equity) / (ATRMultiplier * AvgTrueRange(ATRLength));
// Calculate SuperTrend and direction
SuperTrendValue = SuperTrend(Factor, ATRPeriod, Direction);
// Buy and sell conditions
BuyCondition = Change(Direction) < 0 and Filter;
SellCondition = Change(Direction) > 0;
// **********************************
// Manage trade
// **********************************
If BuyCondition Then
Buy Qty Shares Next Bar at Market;
If SellCondition Then
Sell All Shares Next Bar at Market;