Skip to content

Instantly share code, notes, and snippets.

View saleh-old's full-sized avatar

Saleh O saleh-old

View GitHub Profile
# trading routes
routes = [
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'),
]
# in case your strategy required extra candles, timeframes, ...
extra_candles = [
('Bitfinex', 'BTCUSD', '1D'),
]
# trading routes
routes = [
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'),
]
# in case your strategy required extra candles, timeframes, ...
extra_candles = [
]
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
# 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)
)
@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:
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:
class ExampleStrategy(Strategy):
def should_long(self):
return False
def should_short(self):
return False
def should_cancel(self):
return False
# trading routes
routes = [
('Bitfinex', 'BTCUSD', '6h', 'SampleTrendFollowing'),
]
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 should_long(self) -> bool:
return self.short_ema > self.long_ema
def should_short(self) -> bool:
return self.short_ema < self.long_ema