Hello everyone!
I'm new to QuantConnect, algorithmic trading, coding, and LEAN, and I have a lot of questions.
1. How do I use multiple indicators in one algorithm with different periods? Do I have to rename all the params? DOes the template load all the indicators beforehand and I can just use one line of code to call them, like RSI(14) and EMA(30) or something?
2. How do I use a subindicator? Like AROONdown from the Aroon oscillator.?
3. I'm getting a LOT of errors (30+) when I copy+paste my basic code from the QuantConnect web template to LEAN, and they're mostly the same thing. "The type or namespace name ____ could not be found (are you missing a using directive or an assembly reference?" How do I fix these errors?
Andre Stevens
Oh, and one more thing.
4. How can I create an offset (forward/backward) simply, for every indicator? Like if I wanted the value of RSI(14) for 10 bars ago, is there a way I can do it without having to add in a bunch of additional code? if I have to, what do I do?
Thanks,
AS
Suki Sohi
Hi Andre,
1. To use multiple indicators with different periods, it is helpful to store each indicator into separate variables. Within each indicator, the first argument is typically the symbol and the second is the period length; there are also optional arguments that follow. You should have access to these within the QCAlgorithm class and be able to call them in one line. For instance a 14 period RSI for Apple with daily resolution can be written as
var rsi = RSI("APPL", 14, MovingAverageType.Exponential, Resolution.Daily) ;
2. I believe you can access AroonDown as aroon.AroonDown. For example,
var aroon = AROON("AAPL", 14, 14, Resolution.Daily); Log("AroonDown:"+ aroon.AroonDown) ;
If you want to create an indicator check out here.
3. For a similar problem using VisualStudio, try taking a look at this thread.
If you are getting excessive errors, such as not being able to use the scope “namespace QuantConnect”, I would suggest working in the online IDE.
4. To create a backward offset, you could initialize a list of 0’s, insert each indicator value into the front of a list, and then remove the indicator from the back of the list when accessing it. For instance, for accessing the RSI from 10 days ago with AAPL
var rsiList = new List<int> {0,0,0,0,0,0,0,0,0,0}; Schedule.On(DateRules.EveryDay("AAPL"), TimeRules.BeforeMarketClose("AAPL", 5), () => { var rsi = RSI("APPL", 10) ; rsiList.Insert(0, rsi) ; 10dayOffsetRSI = rsiList[10] ; rsiList.RemoveAt(10) ; });
I hope that's helpful. Otherwise, check out the docs.
Jared Broad
#3 - You need to add "using QuantConnect;" etc namespaces to the algorithm. We add these automatically for you in the web IDE. There are various namespaces required to use the basic parts of QuantConnect. This is a fundamental part of C# coding, please see Microsoft's website.
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.
Andre Stevens
Thanks Suki and Jared, you guys solved my preliminary issues.
However, now I've encountered one more. It seems to be an issue where it can't find my algorithm.
To fix this, the tutorial says:
"The algorithm you just ran was called the "Basic Template Algorithm" and is located in QuantConnect.Algorithm.CSharp/BasicTemplateAlgorithm.cs. To change the algorithm which runs look inside the config.json file and modify the "algorithm-type-name" to match the name of the class you want to load."
The name of my file is AlgorithmTest.cs, and so I tried both AlgorithmTest and AlgorithmTest.cs to put into my config.json, which looks like this now, but it wont work. Is my project not in the CSharp.dll? it shows up in the side bar.
// algorithm class selector
"algorithm-type-name": "AlgorithmTest",
// Algorithm language selector - options CSharp, FSharp, VisualBasic, Python, Java
"algorithm-language": "CSharp",
//Physical DLL location
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
//"algorithm-location": "QuantConnect.Algorithm.Python.dll",
//"algorithm-location": "QuantConnect.Algorithm.FSharp.dll",
//"algorithm-location": "QuantConnect.Algorithm.VisualBasic.dll",
//"algorithm-location": "QuantConnect.Algorithm.Java.dll",
Here's the errors from the debug log.
ERROR:: Engine.Run(): Error running algorithm System.NullReferenceException: Object reference not set to an instance of an object.
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, String assemblyPath) in c:\Users\Andre\Downloads\LEAN2\Lean-master\Engine\Engine.cs:line 179
2017-03-07T08:14:57.6618880Z ERROR:: Algorithm.Initialize() Error: Please verify algorithm type name matches the algorithm name in the configuration file. Unable to resolve multiple algorithm types to a single type.: try re-building algorithm. Stack Trace: at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in c:\Users\Andre\Downloads\LEAN2\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 97
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, String assemblyPath) in c:\Users\Andre\Downloads\LEAN2\Lean-master\Engine\Engine.cs:line 114
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in c:\Users\Andre\Downloads\LEAN2\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 97
Thanks again,
AS
Alexandre Catarino
What is the name of the class that inherits QCAlgorithm in AlgorithmTest.cs?
The engine looks for the types in the assembly (QuantConnect.Algorithm.CSharp.dll), so if we have AlgorithmTest.cs with:
public class MyAwesomeAlgorithm : QCAlgorithm
we need to use
"algorithm-type-name": "MyAwesomeAlgorithm",
Andre Stevens
Thanks Alexandre, that solved that issue, but now I have another one.
I get this error when I try to get minute data for EURUSD (2013-2014), there's one for every day.
2017-03-08T00:39:24.5298979Z ERROR:: DefaultDataProvider.Fetch(): The specified file was not found: ../../../Data/forex\oanda\minute\eurusd\20130102_quote.zip
Alexandre Catarino
Please checkout the the Data folder of your Lean installation for available data.
Up to this moment, we haven't uploaded Oanda data. In order to use Oanda locally, we need to download it from the database.
Andre Stevens
Is there any way I can download lots of zips from the data library at once? I really don't want to have to download 10,000+ manually.
Andre Stevens
It solved my issue, though downloading these zips is tedious.
My code is now running, but every once in a while I get this error
ERROR:: OrderID: 5 Warning - Code: NotSupported - This model does not support MarketOnOpen order type.
What's causing this? I'm guessing it's every week when the FX market opens, what can I fix it with? If not, What other order types are supported, is Fill-Or-Kill/IOC supported by QC/LEAN?
Alexandre Catarino
When we place a market order that cannot be filled in the current session, it is converted into MarketOnOpen. However, FXCM and Oanda do not support that order type and that restriction causes the warning.
It is just a warning, thus we need to evaluate whether that breaks our stratety. For instance, if we are using second or minute resolution and our condition for placing an order still holds after the first bar, then we may not want to change our code. Otherwise, we need to check before placing an order whether we are at the last bar of the week.
Andrew Hart
@Andre - about downloading lots of zips - Use the ApiDataProvider. Basically, if Lean can't find the data on disc, it will reach out to your Data Library on QuantConnect.com and see if the necessary data is in your data library. If it is, it will download and store it for you on disc in the appropriate spot.
To configure, add your username and api key to the Lean config (job-user-id and api-access-token). Also, configure the ""data-provider" in the config to "QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider".
https://github.com/QuantConnect/Lean/pull/788
Andre Stevens
Thanks Alexandre.
@Andrew, I've entered my username and api key into job-user-id and api-access-token, but I can't find "data-provider", there's a "data-file-provider" but when I entered "QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider", it just broke, so I'm assuming that's incorrect.
Andre Stevens
Update: This happened because I didn't realize the ApiDataProvider was a new feature and I was running it on an outdated version of LEAN.
I am, however, getting this warning: ERROR:: QuoteBar.ParseTradeAsQuoteBar(): Data formatted as Trade when Quote format was expected. Support for this will disappear June 2017.
This should be fixed.
Alexandre Catarino
This warning is due the fact that Forex and CFD are QuoteBar objects (they have information about the Bid and Ask), but the data is still TradeBar object (does not have Bid and Ask). It doesn't change previous backtest results.
We are working on our data and on tools to improve it. After that we are going to reprocess it and transform TradeBar data into QuoteBar data and that message will disappear.
John Rewolinski
Has the error: ERROR:: QuoteBar.ParseTradeAsQuoteBar(): Data formatted as Trade when Quote format was expected. Support for this will disappear June 2017.
Been fixed yet? I am getting this issue all of the sudden and nothing is processing in Lean because of it. What's the fix for this?
Jared Broad
either convert your data or download it from our data library,
quantconnect.com/data
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.
Andre Stevens
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!