-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3_supertrend_strategy
58 lines (45 loc) · 2.48 KB
/
3_supertrend_strategy
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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MarketShree
//@version=4
strategy("Supertrend Strategy", overlay=true, default_qty_value=15)
closs_all=input(title="Close_all_Position", type=input.bool, defval=false)
cancel=input(title="Check To Cancel", type=input.bool, defval=false)
atrPeriod1 = input(7, "ATR Length-1")
factor1 = input(1.5,"Factor-1",type=input.float)
atrPeriod2 = input(10, "ATR Length-2")
factor2 = input(2, "Factor-2")
atrPeriod3 = input(20, "ATR Length-3")
factor3 = input(3, "Factor-3")
[superTrend1, direction1] = supertrend(factor1, atrPeriod1)
[superTrend2, direction2] = supertrend(factor2, atrPeriod2)
[superTrend3, direction3] = supertrend(factor3, atrPeriod3)
if change(direction1) < 0
strategy.entry("LONG", strategy.long)
if change(direction1) > 0
strategy.entry("SHORT", strategy.short)
strategy.close_all(when=closs_all,comment ="All postion are closed")
strategy.cancel_all(when=cancel)
if change(direction2) < 0
strategy.entry("LONG", strategy.long)
if change(direction2) > 0
strategy.entry("SHORT", strategy.short)
strategy.close_all(when=closs_all,comment ="All postion are closed")
strategy.cancel_all(when=cancel)
if change(direction3) < 0
strategy.entry("LONG", strategy.long)
if change(direction3) > 0
strategy.entry("SHORT", strategy.short)
strategy.close_all(when=closs_all,comment ="All postion are closed")
strategy.cancel_all(when=cancel)
colResistance = direction1 == 1 and direction1 == direction1[1] ? color.new(color.red, 0) : color.new(color.red, 100)
colSupport = direction1 == -1 and direction1 == direction1[1] ? color.new(color.green, 0) : color.new(color.green, 100)
plot(superTrend1, color = colResistance, linewidth=2)
plot(superTrend1, color = colSupport, linewidth=2)
colResistance1 = direction2 == 1 and direction2 == direction2[1] ? color.new(color.red, 0) : color.new(color.red, 100)
colSupport1 = direction2 == -1 and direction2 == direction2[1] ? color.new(color.green, 0) : color.new(color.green, 100)
plot(superTrend2, color = colResistance, linewidth=2)
plot(superTrend2, color = colSupport, linewidth=2)
colResistance2 = direction3 == 1 and direction3 == direction3[1] ? color.new(color.red, 0) : color.new(color.red, 100)
colSupport2 = direction3 == -1 and direction3 == direction3[1] ? color.new(color.green, 0) : color.new(color.green, 100)
plot(superTrend3, color = colResistance1, linewidth=2)
plot(superTrend3, color = colSupport1, linewidth=2)