13
13
14
14
class TV_RSI (Strategy ):
15
15
16
+ def hyperparameters (self ):
17
+ return [
18
+ {'name' :'rsi' , 'type' : int , 'min' : 10 , 'max' :30 , 'default' : 5 },
19
+ {'name' :'stop_loss' , 'type' : float , 'min' : .5 , 'max' : .99 , 'default' : .95 },
20
+ {'name' :'take_profit' , 'type' : float , 'min' : 1.1 , 'max' : 1.2 , 'default' : 1.1 },
21
+ {'name' :'xparam' , 'type' :int , 'min' : 60 , 'max' : 90 , 'default' : 75 }
22
+ ]
23
+
16
24
@property
17
25
def rsi (self ):
18
- return ta .rsi (self .candles , 14 , sequential = True )
26
+ return ta .rsi (self .candles , self . hp [ 'rsi' ] , sequential = True )
19
27
20
28
21
29
def should_long (self ):
@@ -34,13 +42,13 @@ def should_cancel(self):
34
42
def go_long (self ):
35
43
qty = utils .size_to_qty (self .capital , self .price , 3 , fee_rate = self .fee_rate )
36
44
self .buy = qty , self .price
37
- self .stop_loss = qty , (self .price * .95 ) # Willing to lose 5%
38
- self .take_profit = qty , (self .price * 1.10 ) # Take profits at 10%
45
+ self .stop_loss = qty , (self .price * self . hp [ 'stop_loss' ] ) # Willing to lose 5%
46
+ self .take_profit = qty , (self .price * self . hp [ 'take_profit' ] ) # Take profits at 10%
39
47
40
48
def go_short (self ):
41
49
pass
42
50
43
51
def update_position (self ):
44
- if utils .crossed (self .rsi , 75 , direction = "below" ) or utils .crossed (self .rsi , 10 , direction = "below" ):
52
+ if utils .crossed (self .rsi , self . hp [ 'xparam' ] , direction = "below" ) or utils .crossed (self .rsi , 10 , direction = "below" ):
45
53
self .liquidate ()
46
54
0 commit comments