-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtles.pine
42 lines (33 loc) · 1.34 KB
/
turtles.pine
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
//@version=2
//original idea from «Way of the Turtle: The Secret Methods that Turned Ordinary People into Legendary Traders» (2007) CURTIS FAITH
strategy("Turtles", shorttitle = "Turtles", overlay=true, pyramiding=0, default_qty_type = strategy.percent_of_equity, default_qty_value = 80)
// strategy.risk.max_drawdown(10, strategy.percent_of_equity)
enter_fast = input(20, minval=1)
exit_fast = input(10, minval=1)
enter_slow = input(20, minval=1)
exit_slow = input(10, minval=1)
fastL = highest(enter_fast)
fastLC = lowest(exit_fast)
fastS = lowest(enter_fast)
fastSC = highest(exit_fast)
slowL = highest(enter_slow)
slowLC = lowest(exit_slow)
slowS = lowest(enter_slow)
slowSC = highest(exit_slow)
enterL1 = high > fastL[1]
exitL1 = low <= fastLC[1]
enterS1 = low < fastS[1]
exitS1 = high >= fastSC[1]
enterL2 = high > slowL[1]
exitL2 = low <= slowLC[1]
enterS2 = low < slowS[1]
exitS2 = high >= slowSC[1]
bgcolor(exitL1 or exitL2? red: enterL1 or enterL2? navy:white)
strategy.entry("fast L", strategy.long, when = enterL1)
strategy.entry("fast S", strategy.short, when = enterS1)
strategy.close("fast L", when = exitL1)
strategy.close("fast S", when = exitS1)
strategy.entry("slow L", strategy.long, when = enterL2)
strategy.entry("slow S", strategy.short, when = enterS2)
strategy.close("slow L", when = exitL2)
strategy.close("slow S", when = exitS2)