Hello,
I'm new to QuantConnect. I try to deploy an algorithm live with Oanda but get systematic the same error:
During the algorithm initialization, the following exception has occurred: System.Exception: No default market set for security type: Future at QuantConnect.Algorithm.QCAlgorithm.AddFuture (System.String symbol, QuantConnect.Resolution resolution, System.String market, System.Boolean fillDataForward, System.Decimal leverage) [0x00039] in <948b718a188a4ba2994823a9f477c87e>:0 at QuantConnect.Algorithm.CSharp.FuturesMomentumAlgorithm.Initialize () [0x00085] in <37a8d66406484b15b9222918d3dbc502>:0 at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler+<>c__DisplayClass24_0.<Setup>b__1 () [0x000fb] in <bc4479b96615496c83f0743fe1039576>:0 No default market set for security type: Futureand here is the Code:using System; using System.Linq; using QuantConnect.Data; using QuantConnect.Orders; using QuantConnect.Securities; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// EMA cross with SP500 E-mini futures /// In this example, we demostrate how to trade futures contracts using /// a equity to generate the trading signals /// It also shows how you can prefilter contracts easily based on expirations. /// It also shows how you can inspect the futures chain to pick a specific contract to trade. /// </summary> /// <meta name="tag" content="using data" /> /// <meta name="tag" content="futures" /> /// <meta name="tag" content="indicators" /> /// <meta name="tag" content="strategy example" /> public class FuturesMomentumAlgorithm : QCAlgorithm { private const string RootSP500 = Futures.Indices.SP500EMini; public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.Oanda); private const decimal _tolerance = 0.001m; private const int _fastPeriod = 20; private const int _slowPeriod = 50; private ExponentialMovingAverage _fast; private ExponentialMovingAverage _slow; public bool IsReady { get { return _fast.IsReady && _slow.IsReady; } } public bool IsUpTrend { get { return IsReady && _fast > _slow * (1 + _tolerance); } } public bool IsDownTrend { get { return IsReady && _fast < _slow * (1 + _tolerance); } } public override void Initialize() { SetStartDate(2016, 1, 1); SetEndDate(2018, 3, 15); SetCash(10000); SetWarmUp(Math.Max(_fastPeriod, _slowPeriod)); // Adds SPY to be used in our EMA indicators var equity = AddEquity("SPY", Resolution.Daily); _fast = EMA(equity.Symbol, _fastPeriod, Resolution.Daily); _slow = EMA(equity.Symbol, _slowPeriod, Resolution.Daily); // Adds the future that will be traded and // set our expiry filter for this futures chain var futureSP500 = AddFuture(RootSP500); futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182)); } I saw on quantconnect.com/data that SP500 with Oanda is a Cfd; has this maybe to do with the error?Thanks for your help! ;=)NB: I'm not a programmer, just a guy trying to find a solution to automate my trades. ;=)
Jared Broad
OANDA does not support futures trading -- is it the equivalent a CFD you're seeking to trade?
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.
Joao Seabra
Hi Mr Broad, yes. As I am a Oanda customer I have no other choice than to trade as CFD ;-) Most indices if not all are tradeable at Oanda as CFD's. Is there a way to change the 'SecurityType.Future' in 'SecurityType.Cfd'?
using System; using System.Linq; using QuantConnect.Data; using QuantConnect.Orders; using QuantConnect.Securities; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// EMA cross with SP500 E-mini futures /// In this example, we demostrate how to trade futures contracts using /// a equity to generate the trading signals /// It also shows how you can prefilter contracts easily based on expirations. /// It also shows how you can inspect the futures chain to pick a specific contract to trade. /// </summary> /// <meta name="tag" content="using data" /> /// <meta name="tag" content="futures" /> /// <meta name="tag" content="indicators" /> /// <meta name="tag" content="strategy example" /> public class FuturesMomentumAlgorithm : QCAlgorithm { private const string RootSP500 = Futures.Indices.SP500EMini; public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.Oanda); private const decimal _tolerance = 0.001m; private const int _fastPeriod = 20; private const int _slowPeriod = 50; private ExponentialMovingAverage _fast; private ExponentialMovingAverage _slow; public bool IsReady { get { return _fast.IsReady && _slow.IsReady; } } public bool IsUpTrend { get { return IsReady && _fast > _slow * (1 + _tolerance); } } public bool IsDownTrend { get { return IsReady && _fast < _slow * (1 + _tolerance); } } public override void Initialize() { SetStartDate(2016, 1, 1); SetEndDate(2018, 3, 15); SetCash(10000); SetWarmUp(Math.Max(_fastPeriod, _slowPeriod)); // Adds SPY to be used in our EMA indicators var equity = AddEquity("SPY", Resolution.Daily); _fast = EMA(equity.Symbol, _fastPeriod, Resolution.Daily); _slow = EMA(equity.Symbol, _slowPeriod, Resolution.Daily); // Adds the future that will be traded and // set our expiry filter for this futures chain var futureSP500 = AddFuture(RootSP500); futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182)); } public override void OnData(Slice slice) { if (!Portfolio.Invested && IsUpTrend) { foreach (var chain in slice.FutureChains) { // find the front contract expiring no earlier than in 90 days var contract = ( from futuresContract in chain.Value.OrderBy(x => x.Expiry) where futuresContract.Expiry > Time.Date.AddDays(90) select futuresContract ).FirstOrDefault(); // if found, trade it if (contract != null) { MarketOrder(contract.Symbol, 1); } } } if (Portfolio.Invested && IsDownTrend) { Liquidate(); } } public override void OnEndOfDay() { Plot("Indicator Signal", "EOD", IsDownTrend ? -1 : IsUpTrend ? 1 : 0); } public override void OnOrderEvent(OrderEvent orderEvent) { Log(orderEvent.ToString()); } } }
Alexandre Catarino
In order to add CFD to your algorithm, please use:
AddCfd("US30USD", market: Market.Oanda);
For other CFD contracts, please checkout the database.
Joao Seabra
Ola Alexandre, prazer falar consigo ;-)
I have already tried your code proposal, but must I change something here?
private const string RootSP500 = Futures.Indices.SP500EMini;
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.Oanda);
Or replace it completely by your code?
Jared Broad
"Or replace it completely by your code? " -- Correct; CFD's are much simpler than real futures trading.
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.
Joao Seabra
Hi Mr Broad, yes I have completely replaced it. The connection seems to work with the DAX30 (Oanda: DE30EUR). I think the rest of the code is not correct to place the trades If I use 'AddCfd' because I see 'slice.FutureChains' this method will not look for the addCfd.
// Adds SPY to be used in our EMA indicators var equity = AddEquity("SPY", Resolution.Daily); _fast = EMA(equity.Symbol, _fastPeriod, Resolution.Daily); _slow = EMA(equity.Symbol, _slowPeriod, Resolution.Daily); // Adds the future that will be traded and // set our expiry filter for this futures chain } public override void OnData(Slice slice) { if (!Portfolio.Invested && IsUpTrend) { foreach (var chain in slice.FutureChains) { // find the front contract expiring no earlier than in 90 days var contract = ( from futuresContract in chain.Value.OrderBy(x => x.Expiry) where futuresContract.Expiry > Time.Date.AddDays(90) select futuresContract ).FirstOrDefault(); // if found, trade it if (contract != null) { MarketOrder(contract.Symbol, 1); } } } if (Portfolio.Invested && IsDownTrend) { Liquidate(); } } public override void OnEndOfDay() { Plot("Indicator Signal", "EOD", IsDownTrend ? -1 : IsUpTrend ? 1 : 0); } public override void OnOrderEvent(OrderEvent orderEvent) { Log(orderEvent.ToString()); } } }
ES trades on the Chicago exchange and the SPY in New York. The strategy is extremely profitable in backtesting due to look ahead capability derived from New York being 1 hour ahead of Chicago. Perhaps QC can give an example of how to align data across timezones when trading one market based on signals from another?
Joao Seabra
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!