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
# trading routes | |
routes = [ | |
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'), | |
] | |
# in case your strategy required extra candles, timeframes, ... | |
extra_candles = [ | |
('Bitfinex', 'BTCUSD', '1D'), | |
] |
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
# trading routes | |
routes = [ | |
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'), | |
] | |
# in case your strategy required extra candles, timeframes, ... | |
extra_candles = [ | |
] |
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
def should_long(self) -> bool: | |
return self.short_ema > self.long_ema and self.anchor_trend == 1 | |
def should_short(self) -> bool: | |
return self.short_ema < self.long_ema and self.anchor_trend == -1 |
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
# instead of | |
anchor_candles = self.get_candles( | |
'Bitfinex', 'BTCUSD', utils.anchor_timeframe('4h') | |
) | |
# I wrote | |
anchor_candles = self.get_candles( | |
self.exchange, self.symbol, utils.anchor_timeframe(self.timeframe) | |
) |
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
@property | |
def anchor_trend(self): | |
# use self.get_candles() to get the candles for the anchor timeframe | |
anchor_candles = self.get_candles( | |
self.exchange, self.symbol, utils.anchor_timeframe(self.timeframe) | |
) | |
ema = ta.ema(anchor_candles, 100) | |
if self.price > ema: |
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: |
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
class ExampleStrategy(Strategy): | |
def should_long(self): | |
return False | |
def should_short(self): | |
return False | |
def should_cancel(self): | |
return False | |
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
# trading routes | |
routes = [ | |
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'), | |
] |
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
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 |
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
def should_long(self) -> bool: | |
return self.short_ema > self.long_ema | |
def should_short(self) -> bool: | |
return self.short_ema < self.long_ema |