During the algorithm initialization, the following exception has occurred: Please register to receive data for symbol ' ' using the AddSecurity() function.
private const string _symbol = "EURUSD";
// properties
ExponentialMovingAverage _emaFast;
ExponentialMovingAverage _emaSlow;
public override void Initialize()
{
// Backtest only
SetStartDate(2017, 5, 1);
SetEndDate(2017, 5, 31);
SetCash(100000);
_emaFast = EMA(_symbol, 20);
_emaSlow = EMA(_symbol, 40);
// Find more symbols here: http://quantconnect.com/data
AddForex(_symbol, Resolution.Minute, Market.Oanda);
AddSecurity(SecurityType.Forex, _symbol, Resolution.Minute);
Securities[_symbol].SetDataNormalizationMode(DataNormalizationMode.Raw);
SetBrokerageModel(BrokerageName.OandaBrokerage);
}
Alexandre Catarino
Please call AddForex before EMA.
Rule of thumb:
First call methods which name starts with Set, then Add, then methods where one of the parameters is a Symbol.
The reason for that error is that EMA needs to know which data subscription is associated with the symbol and the subscription is created when you add the security. Also, the "mapping" (implicit conversion) between the ticker (string) and the Symbol (object) is done after we call add security. Before that you cannot use "EURUSD" instead of the Symbol object that represents EURUSD.
Bunyamin Sakar
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!