Skip to content

Commit d4a8e11

Browse files
Merge pull request jesse-ai#13 from xsa-dev/master
TV_RSI2 hyperparams injected
2 parents b3ccc86 + 0375a82 commit d4a8e11

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

TradingView_RSI/__init__.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313

1414
class TV_RSI(Strategy):
1515

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+
1624
@property
1725
def rsi(self):
18-
return ta.rsi(self.candles, 14, sequential=True)
26+
return ta.rsi(self.candles, self.hp['rsi'], sequential=True)
1927

2028

2129
def should_long(self):
@@ -34,13 +42,13 @@ def should_cancel(self):
3442
def go_long(self):
3543
qty = utils.size_to_qty(self.capital, self.price, 3, fee_rate=self.fee_rate)
3644
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%
3947

4048
def go_short(self):
4149
pass
4250

4351
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"):
4553
self.liquidate()
4654

0 commit comments

Comments
 (0)