I'm not very interested by you "speaker" strategy ... for now... but maybe one day it could be useful...
I tried to play with a Python wrapper for TA-Lib
http://ta-lib.org/http://mrjbq7.github.io/ta-lib/this wrapper is total...
you just need to install cython, TA-Lib, and this wrapper
I just tried this out and wanted to plot the results so I dumped the data to some files and used Highstock.js to render the view.
import goxapi
from goxapi import OHLCV
import datetime
import numpy as np
import talib
import json
class OHLCV_Encoder(json.JSONEncoder):
"""JSONEncoder for class OHLCV()"""
def default(self, obj):
if isinstance(obj, OHLCV):
return [obj.tim, obj.opn, obj.hig, obj.low, obj.cls, obj.vol]
else:
return json.JSONEncoder.default(self, obj)
class Strategy(goxapi.BaseObject):
........
........
def slot_keypress(self, gox, (key)):
if key == ord("t"):
"""testing talib"""
candles = []
for c in reversed(self.gox.history.candles):
candles.append(
OHLCV(
# fix time for HighStock.js JSON import
c.tim * 1000,
# adjust values to be human readable
goxapi.int2float(c.opn, self.gox.currency),
goxapi.int2float(c.hig, self.gox.currency),
goxapi.int2float(c.low, self.gox.currency),
goxapi.int2float(c.cls, self.gox.currency),
goxapi.int2float(c.vol, "BTC")
)
)
self.debug("Test history with %d candles" % len(candles))
rng = range(len(candles))
iterable = (candles[i].cls for i in rng)
a_cls = np.fromiter(iterable, np.float)
iterable = (candles[i].tim for i in rng)
a_tim = np.fromiter(iterable, np.int64)
a_sma = talib.SMA(a_cls, 10)
a_wma = talib.WMA(a_cls, 25)
# create json compatible with HighStock.js
with open("talib_ohlcv.json", 'w') as outfile:
json.dump(candles, outfile, cls = OHLCV_Encoder)
with open("talib_sma.json", 'w') as outfile:
# first 10 elements contain Nan
json.dump(np.dstack((a_tim[10:], a_sma[10:])).tolist()[0], outfile)
with open("talib_wma.json", 'w') as outfile:
# first 25 elements contain Nan
json.dump(np.dstack((a_tim[25:], a_wma[25:])).tolist()[0], outfile)
with
BTC Highstock - Goxtool/TA-Lib Serve index.html up with
python -m SimpleHTTPServer 8080
EDIT: Using close instead of open for EMAs and added python server example