Skip to content

Instantly share code, notes, and snippets.

@samchaaa
Created December 20, 2020 08:29
Show Gist options
  • Save samchaaa/9b8073e54670fc230027c0ad7726696b to your computer and use it in GitHub Desktop.
Save samchaaa/9b8073e54670fc230027c0ad7726696b to your computer and use it in GitHub Desktop.
def get_signals(close_time):
"""
Creates signals for pybacktest.
Note pybacktest specifically needs series named "buy", "sell", "short", "cover" to work.
Check out tutorial notebook: https://nbviewer.jupyter.org/github/ematvey/pybacktest/blob/master/examples/tutorial.ipynb
"""
bs = ohlc['C'] > ohlc['hb'] # sell signal
bb = ohlc['C'] < ohlc['lb'] # buy signal
nbs = ohlc['C'] > ohlc['hb'] # not sell signal
nbb = ohlc['C'] < ohlc['lb'] # not buy signal
buy = bb & nbb.shift()
sell = buy.shift(close_time)
short = bs & nbs.shift()
cover = short.shift(close_time)
return buy, cover, sell, short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment