Last active
June 28, 2020 09:07
-
-
Save saleh-old/4c04b166fd92815929d944de675aa7ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jesse.strategies import Strategy | |
import jesse.indicators as ta | |
from jesse import utils | |
class SampleTrendFollowing(Strategy): | |
def should_long(self) -> bool: | |
return self.short_ema > self.long_ema | |
def should_short(self) -> bool: | |
return self.short_ema < self.long_ema | |
def should_cancel(self) -> bool: | |
return True | |
def go_long(self): | |
entry = self.price | |
stop = entry - 3*self.atr | |
qty = utils.risk_to_qty(self.capital, 3, entry, stop, fee_rate=self.fee_rate) | |
profit_target = entry + 5*self.atr | |
self.buy = qty, entry | |
self.stop_loss = qty, stop | |
self.take_profit = qty, profit_target | |
def go_short(self): | |
entry = self.price | |
stop = entry + 3 * self.atr | |
qty = utils.risk_to_qty(self.capital, 3, entry, stop, fee_rate=self.fee_rate) | |
profit_target = entry - 5 * self.atr | |
self.sell = qty, entry | |
self.stop_loss = qty, stop | |
self.take_profit = qty, profit_target | |
@property | |
def long_ema(self): | |
return ta.ema(self.candles, 50) | |
@property | |
def short_ema(self): | |
return ta.ema(self.candles, 21) | |
@property | |
def atr(self): | |
return ta.atr(self.candles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment