Hi there,
Maybe some of you are familiar with autochartist, a service which provides trading signals. I wrote an algo which downloads the trading signals in their favourite section and invests accordingly.
It is rough and very unpythonic in places. Keep in mind I only started with Quantconnect and Python a month or so ago and had no previous programming experience.
You need a Oanda API token for it to work.
As you cannot access historical chartpatterns, real backtesting is not possible, only use with papertrading or an oanda demo account
I have a lot of idea's how to refine this and increase the performance significantly. I cannot express those idea's very well in Python yet.
If someone is interested to work with me on this to our mutual benefit, please let me know.
Tristan VDB
import json import time class FxAutochartist(QCAlgorithm): secidlist=[] def Initialize(self): self.SetStartDate(2021, 1, 20) #Set Start Date #self.SetEndDate(2020, 12, 31) #Set End Date self.SetCash(2000) #Set Strategy Cash self.SetBrokerageModel(BrokerageName.OandaBrokerage) self.resol = Resolution.Hour self.fxlist =["AUDCAD", "AUDCHF", "AUDHKD", "AUDJPY", "AUDNZD", "AUDSGD", "AUDUSD", "CADCHF", "CADHKD", "CADJPY", "CADSGD", "CHFHKD", "CHFJPY", "CHFZAR", "EURAUD", "EURCAD", "EURCHF", "EURCZK", "EURDKK", "EURGBP", "EURHKD", "EURHUF", "EURJPY", "EURNOK", "EURNZD", "EURPLN", "EURSEK", "EURSGD", "EURTRY", "EURUSD", "EURZAR", "GBPAUD", "GBPCAD", "GBPCHF", "GBPHKD", "GBPJPY", "GBPNZD", "GBPPLN", "GBPSGD", "GBPUSD", "GBPZAR", "HKDJPY", "NZDCAD", "NZDCHF", "NZDHKD", "NZDJPY", "NZDSGD", "NZDUSD", "SGDCHF", "SGDHKD", "SGDJPY", "TRYJPY", "USDCAD", "USDCHF", "USDCNH", "USDCZK", "USDDKK", "USDHKD", "USDHUF", "USDJPY", "USDMXN", "USDNOK", "USDPLN", "USDSEK", "USDSGD", "USDTHB", "USDTRY", "USDZAR", "ZARJPY"] for i in self.fxlist: self.AddForex(i, self.resol, Market.Oanda) def OnData(self, data): accesstoken = "Bearer yourtokenhere" headers = { 'Authorization' : str(accesstoken)} url = self.Download("https://api-fxtrade.oanda.com/labs/v1/signal/autochartist?direction=bullish", headers) if url !="{}" and url != "": self.result = json.loads(url) datalist = self.result["signals"] weight = 1/len(self.fxlist) for i in datalist: secid = i ["id"] pairoanda = i ["instrument"] self.symbol = (pairoanda.replace('_','')) datadict = i["data"] metadict = i ["meta"] probability = metadict ["probability"] interval = metadict ["interval"] completed = metadict ["completed"] if completed == 1 and interval == 60: predictiondict = datadict ["prediction"] pricepredictlow = predictiondict ["pricelow"] timefrom = predictiondict ["timefrom"] currenttime = time.time() if self.symbol in self.fxlist: currenttime < timefrom currentprice = data[self.symbol].Price if not self.Portfolio[self.symbol].Invested: if pricepredictlow > currentprice: if secid not in self.secidlist: quantity = self.CalculateOrderQuantity(self.symbol, weight) self.MarketOrder(self.symbol, quantity) self.stopMarketTicket = self.StopMarketOrder(self.symbol, -quantity, 0.998 * currentprice) self.limitTicket = self.LimitOrder(self.symbol, -quantity, pricepredictlow) self.secidlist.append(secid) self.Debug (self.secidlist) def OnOrderEvent(self, orderEvent): order = self.Transactions.GetOrderById(orderEvent.OrderId) ### Cancel remaining order if limit order or stop loss order is executed if order.Status == OrderStatus.Filled: if order.Type == OrderType.Limit or OrderType.StopLimit: self.Transactions.CancelOpenOrders(order.Symbol) if order.Status == OrderStatus.Canceled: self.Log(str(orderEvent))
Derek Melchin
Hi Tristan,
Thanks for sharing with the community!
Best,
Derek Melchin
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.
Tristan VDB
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!