forked from GeorgeFreelanceDeveloper/trend-follow.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BollingerBandTrendFollowStrategy.easylanguage
56 lines (46 loc) · 1.88 KB
/
BollingerBandTrendFollowStrategy.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
Inputs:
Length(20), // Length for Bollinger Bands
MultiplierUpper(1), // Multiplier for the upper band
MultiplierLower(0.5), // Multiplier for the lower band
RiskPercentage(1.00), // Risk percentage per trade
ATRMultiplier(2), // ATR multiplier
ATRLength(20), // ATR length
EnableFilter(false), // Enable filter
BenchmarkSymbol("SPX"); // Benchmark symbol
Vars:
CentralMA(0), // Central moving average for Bollinger Bands
UpperBand(0), // Upper Bollinger Band
LowerBand(0), // Lower Bollinger Band
BenchmarkClose(0), // Closing price of the benchmark
Filter(false), // Filter condition
Qty(0), // Trade quantity
BuyCondition(false), // Buy condition
SellCondition(false); // Sell condition
// **********************************
// Functions
// **********************************
// **********************************
// Perform calculations and analysis
// **********************************
// Bollinger Bands calculations
CentralMA = Average(Close, Length);
UpperBand = CentralMA + MultiplierUpper * StdDev(Close, Length);
LowerBand = CentralMA - MultiplierLower * StdDev(Close, Length);
// Filter
If EnableFilter then
BenchmarkClose = Close of Data2;
Filter = BenchmarkClose >= Average(Close of Data2, 200);
else
Filter = true;
// Trade quantity
Qty = ((RiskPercentage / 100) * I_OpenEquity) / (ATRMultiplier * AvgTrueRange(ATRLength));
// Entry and exit conditions
BuyCondition = Close crosses over UpperBand and Filter;
SellCondition = Close crosses under LowerBand;
// **********************************
// Manage trade
// **********************************
If BuyCondition then
Buy("Long") Qty shares next bar at market;
If SellCondition then
Sell("Long") Qty shares next bar at market;