Back

Trading bot using Heikin Ashi candles

I'm new to Quantconnect and I'm having a very hard time understanding the API. I tried to create a trading bot in Python to execute trades on GDAX 24/24 on BTC/EUR, ETH/EUR, BCH/EUR.

My strategy is to trade like this :

  • Use the Heikin Ashi candle on a 4h timeframe
  • If the previous Heikin Ashi candle is green and the last candle is red => create a sell limit order (with 50% of the holdings) with value = current_price + 0.0001
  • If the previous Heikin Ashi candle is red and the last candle is green => create a buy limit order (with 50% of the holdings) with value = current_price - 0.0001
I understood that I need to :
  • Create a 4-hour consolidator: consolidator = QuoteBarConsolidator(timedelta(hours = 4))
  • Create a HeikinAshi using the constructor:  self.heikin_ashi = HeikinAshi(name) 
  • Register the indicator: self.RegisterIndicator("BTCEUR", self.heikin_ashi, consolidator)
But after trying different ways it doesn't work.. I don't know how to orchestrate my code. Can someone please help ? :) 

Many thanks !

Guillaume

Update Backtest








Hello,

please define "does not work" further for somebody to be able to help you. An algo can not work as in not making money, or otherwise have a technical problem (e.g. not makethe intended trades), the former of which is way more difficult to solve than the other.

0

Dear Petter,

Thanks for your answer. It is a programming problem and not a "financial strategy" problem.

For the moment I have this piece of code and I was trying to just buy 100% of BTC at the start date to get familiar with the backtesting environment but the backtest is running for about 10 minutes and ends up saying "Runtime Error: System.Exception: Algorithm took longer than 10 minutes on a single time loop.".

from datetime import datetime, timedelta

class BasicTemplateAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2017, 12, 11) # Set Start Date
self.SetEndDate(2017, 12, 14) # Set End Date
self.SetCash(10000) # Set Strategy Cash
self.btc = self.AddCrypto("BTCEUR", Resolution.Hour).Symbol

consolidator = QuoteBarConsolidator(timedelta(hours = 4))
self.heikin_ashi = HeikinAshi("BTCEUR")


def OnData(self, data):

self.SetHoldings(self.btc, 100) # Buy 100% of Equity of BTCUSD

Moreover I don't know how to instruct my program to do this :

  • Use the Heikin Ashi candle on a 4h timeframe
  • If the previous Heikin Ashi candle is green and the last candle is red => create a sell limit order (with 50% of the holdings) with value = current_price + 0.0001
  • If the previous Heikin Ashi candle is red and the last candle is green => create a buy limit order (with 50% of the holdings) with value = current_price - 0.0001
I've been looking at the heikin ashi's functions in the API and I found no function that allows to use color switches.. Any help is very welcome ! Thanks ! Guillaume
0

Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed