Last active
July 2, 2017 19:08
-
-
Save jetstreamin/8db0ee5f2d072556cfac638d470ea984 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
# longIslandIcedTea.py | |
# btc_usd on bitfinex | |
# Mike Mahon | |
# [email protected] | |
# 07/02/2017 | |
# Interval Tests - 01-01-2016 to 06-02-2017 - Beg. Bal: $50 | |
# 1 min interval - End Bal: | |
# 15 min interval - End Bal: $223.32 | |
# 30 min interval - End Bal: $206.58 | |
import datetime | |
def initialize(): | |
storage.invested = False | |
storage.previous_value = 0 | |
storage.min_profit_pct = 0.0225 | |
storage.payday_inv_made = False | |
def tick(): | |
short_term = data.btc_usd.ma(30) | |
long_term = data.btc_usd.ma(100) | |
profit_loss_pct = calc_pl(data.btc_usd.close) | |
if(data.btc_usd.datetime.day == 1 or data.btc_usd.datetime.day == 15) and storage.payday_inv_made == False: | |
portfolio.usd = portfolio.usd + 50 | |
storage.payday_inv_made = True | |
elif(data.btc_usd.datetime.day == 2 or data.btc_usd.datetime.day == 16) and storage.payday_inv_made == True: | |
storage.payday_inv_made = False | |
portfolio.update() | |
if(info.tick == 0) : | |
storage.previous_value = 0 | |
if (short_term > long_term) and not storage.invested: | |
log('Buy BTC') | |
buy(pairs.btc_usd) | |
storage.invested = True | |
storage.previous_value = data.btc_usd.close | |
if storage.invested: | |
if(profit_loss_pct > storage.min_profit_pct) and (short_term < long_term): | |
log('P\L Pct: {0}'.format(profit_loss_pct)) | |
sell(pairs.btc_usd) | |
storage.invested = False | |
def calc_pl(current_value): | |
return (current_value - storage.previous_value) / current_value | |
def stop(): | |
if storage.invested: | |
log('Clearing our position by selling all BTC holdings') | |
sell(pairs.btc_usd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment