Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Altcoin trading strategy

Hi, I'm working on implementing an altcoin trading strategy based on a DMI, CMF/OBV-EMA, CCI, %R-ATR indicator combo.

I combine bullish signals from these indicators as well as heiken ashi candlesticks to gauge momentum and detect trends, as well as trade ranging markets.

Problem is I'm no developer so you're gonna have to bear with me to get this done.
I intend to at least as a starting point, do something simpler and manage to backtest pre-existing strategies over the different alternative coin pairs found at www.bittrex.com, which is a bitcoin/altcoin exchange.

They have API documentation but I'm not sure how to retrieve their historical data into a .CSV file, nor how to import that here.

Another thing I'm curious about is if it'd be possible to develop a pattern scanner to spot potential trading opportunities, in case automating trading there is not possible.
The bare minimum I'd like to automate is iceberg orders and trailing stops, which these exchanges don't offer natively.

Thanks in advance!
Ivan.

4 responses

Hey Ivan,
If you want to backtest, importing a CSV is your first step. You can create a CSV just by creating a table in Excel or Google docs or whatever, then there is an export as CSV option. You'll need two columns, one with the date (or date and time if you want minutely data) and one with the closing price for that minute. I'm guessing in the cryptocurrency world there is a fair difference between the bid and ask price, i.e. sellers will typically want a little more than buyers. I'm not sure how this is accounted on those sites for but you can probably just average everything together and that should be good enough. Although they might just do that for you.

There's a few examples on how to use fetch_csv here.

Gus

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Gus, I found this: http://www.quandl.com/CRYPTOCHART/BTCDBTC-BTCD-BTC-Exchange-Rate

Historical data for one of many altcoin pairs...I'd like to include all the pairs in that page (89 pages of them) into my backtests. ( http://www.quandl.com/CRYPTOCHART?keyword=%20&page=1&code=CRYPTOCHART )

I found a code sample I like, can you help integrate the data into this algo below?

ATR+MA strategy (cloned it from a post here, really cool btw)

import talib

def initialize(context):
context.stock = symbol('aapl')
context.stopLoss = 0
context.signalZone = 0
context.bullish = 0
context.high_MA = 14
context.low_MA = 14
context.atr_window = 90
context.reg_window = 100
set_benchmark(context.stock)

def handle_data(context, data):
if get_open_orders(context.stock):
return

H = history(200, '1d', 'high')[context.stock]  
L = history(200, '1d', 'low')[context.stock]  
C = history(200, '1d', 'close_price')[context.stock]  

aapl_ma5 = C.iloc[-5::].mean()  
aapl_ma100 = C.iloc[-100::].mean()  
aapl_atr = talib.ATR(H, L, C, timeperiod=context.atr_window)[-1]  
# Unused variable  
# aapl_reg = talib.LINEARREG(C, timeperiod=context.reg_window)[-1]  
price = data[context.stock].price  
stop_loss = price - aapl_atr  
signal_zone = price + aapl_atr  

position = context.portfolio.positions[context.stock].amount

if aapl_ma5 > aapl_ma100 and position == 0:  
    order_target_percent(context.stock, 2.0)  
    context.stopLoss = stop_loss  
    context.signalZone = signal_zone  
elif (aapl_ma5 < aapl_ma100 and price > context.signalZone) or price < context.stopLoss and position != 0:  
    order_target(context.stock, 0)  


record(sgnal_zone=context.signalZone,  
       aapl_ma5=aapl_ma5,  
       aapl_ma100=aapl_ma100,  
       position=position,  
       price=price)

Other strategies I'd like to implement:

http://www.forexball.com/news/view/id/63

http://www.dailyfx.com/forex/education/trading_tips/daily_trading_lesson/2012/11/29/Three_Simple_Strategies_for_Trading_MACD.html

Let me know if you can help...thanks again!

Hey Ivan,
It looks like that data source only has 2 days of data in daily increments, so it only has 2 data points. What you need is minute-level data over a few months. A hard part of this is getting the data. You will need two things: history with minute-level detail to backtest accurately, ideally over at least a few recent months; and current streaming data from the most recent minute for when you actually want to trade. Using the streaming data is not currently possible on Quantopian, because we don't support importing something every minute in live trading (or logging, in your case). Only at the beginning on each day can a CSV file be imported. Therefore, you should probably use Zipline (sorry, I should have realized this before!). It looks like people have talked about this a little and there are a few examples: https://www.google.com/search?q=zipline+bitcoin

Zipline also has the advantage that it's much easier to import a custom price data source. Quantopian isn't really suited for dealing with what you want, but Zipline (which is Quantopian's backtester) is. You can also easily use most Quantopian strategies, like the one above, in Zipline. I wouldn't worry about the live data first — just focus on backtesting. If you have any questions about Zipline, you can ask them in the Google Group: https://groups.google.com/forum/#!forum/zipline

Gus

Ok, so zipline it is...as for the data, I'll try to get it myself somehow.
Might take me a while, but I'll post here if I have any doubts, or make progress.
Thanks!