Hi everyone,
I am trying to write a simple script with 5 minutes Heiken Ashi Candles stored in a rolling window. However i am getting this error:
untime Error: This is a forward only indicator: HA(EURUSD_min) Input: 2018-07-01 17:00:00Z Previous: 2018-07-01 17:04:00Z (Open Stacktrace)
import numpy as np
import decimal as d
from datetime import timedelta, datetime
class FirstProject(QCAlgorithm):
def Initialize(self):
self.SetCash(100000)
self.SetStartDate(2018,7,1)
self.SetEndDate(2018,7,3)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.AddForex("EURUSD", Resolution.Minute, Market.Oanda).Symbol
self.HA = self.HeikinAshi("EURUSD",Resolution.Minute)
#rolling windows for actual price
self.price_window = RollingWindow[QuoteBar](10)
#rolling window for HA indicator
self.HA_open_win = RollingWindow[d.Decimal](10)
self.HA_close_win = RollingWindow[d.Decimal](10)
#Consolidate Heiken Ashi
fiveMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=5))
fiveMinuteConsolidator.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator('EURUSD', fiveMinuteConsolidator)
self.RegisterIndicator('EURUSD',self.HA, fiveMinuteConsolidator)
def OnData(self, data):
if not (self.HA.IsReady): return
def OnDataConsolidated(self, sender, data):
if not (self.HA.IsReady): return
self.price_window.Add(data['EURUSD'])
self.HA_open_win.Add(self.HA.Open.Current.Value)
self.HA_close_win.Add(self.HA.Close.Current.Value)
if not (self.price_window.IsReady):return
if not (self.HA_open_win.IsReady):return
if not (self.HA_close_win.IsReady):return
self.Log(self.price_window[0].Ask.Close)
self.Log(self.HA_open_win[0])
Jing Wu
"self.HeikinAshi("EURUSD",Resolution.Minute)" will be updated automatically with the specified minute resolution. To update the indicator with the consolidated bar, you should use the indicator constructor "HeikinAshi("EURUSD)" and update the indicator with self.RegisterIndicator().
In the helper method "OnDataConsolidated(self, sender, data)", data is the quote bar of 'EURUSD'. Instead of using data["EURUSD"], you should use "data" to update the rolling window.
Ww ee
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!