Hi there!
Some background on myself: Java developer (mostly EE stuff) who likes dabbling in C, C++, OpenSource, MQL and MetaTrader. As of late I've become frustrated with the quality of MetaTrader's backtesting. I decided to try out QuantConnect, since I'm spending more time sanitizing data and Googling MT4/Ubuntu problems than doing what interests me to begin with - coding and algorithmic trading.
MT flaws real or perceived, here I am! And I have a few questions after spending the last few days with QuantConnect. Most of my original questions I could resolve by looking at the source code (seeing as C# and Java aren't radically different.) Some others are more a question of wrapping my head around the intended use of the API. In all probability I'm using it incorrectly.
So here are them questions!
1. First off, there's is somewhere something I'm not properly understanding with indiciator resolutions.
Is this similar to MetaTrader's PERIOD constants?
Say I wanted, in metatrader, to obtain the 100 SMA on a half-an-hour chart. I do a method call, I give it a period (defined as a constant) and a shift that would look more or less something like this (this is not exact, I don't have MT on this box):
double sma100 = iMA("EURUSD", PERIOD_M30, MODE_SIMPLE, 0);
Now I want to do this in QuantConnect:
private member variable:
private SimpleMovingAverage _sma100;
In the initialize method I encounter the problem of resolution.
_sma100 = SMA("EURUSD", 100, Resolution.Minute);
This only gives me SMA100 on a minute basis. What would be the equivalent then of SMA100 for half-an-hour candlesticks be here?
Perhaps
SMA("EURUSD", 3000, Resolution.Minute);
?
So, either Resolution isn't like PERIOD in MetaTrader, or QuantConnect doesn't allow Resolutions/Periods on 5min/15min/etc charts.
2. Second, I'm having trouble querying what happened to a trade. Say that I have a strategy that may have two open trades - one long, one short. In this scenario, one of the orders gets filled, and I can confirm that when I write the OrderStatus to debug:
Filled
Now, the problem is that this was a StopLimitOrder with a specific stop loss and take profit. The market moves, either the sl or tp gets hit, and... nothing. I don't know how to see from the OrderTicket object whether the order is closed - according to debug, it remains Filled. I know it can't be an active trade anymore though, since SL should have been hit a long time ago.
A similar problem is when I feel that some condition has been met for me to close down the trade. They only way I've found to do this would be to call the Liquidate() function, which would liquidate... everything, right? If I have both a long and a short open, I can't tell it to liquidate only the one and not the other.
Would be fantastic if any of you could provide me with some insight into these.
And, well done on the platform - it looks and works really well!
Kind regards,
Kepler
JayJayD
Hi Kepler,
Please check this modified example, there you’ll see how two consolidators are defined to update the SMA with 15 and 30 minute bar. In the Initialize method, some of the SMA are declared, but not registered, they’ll be updated when the DataConsolidated EventHandler is fired.
Respect to the orders, you have two options:
Note the use of the SetWarmup method to avoid waiting time until the indicators are ready and the override method OnEndOfDay. Hope it helps.
Finally, for a more complex example of indicators and consolidators, check this example by Alex Catarino and don’t forget to take a look to the documentation and to the QC University examples.
Best.
JJD
P.S.: I used APPL instead EURUSD because seem there is a bug with the consolidators subscription and Forex data. I'll report it right now.
JayJayD
UPDATE!
There is no bug, just me!
Forex data is QuoteBar so, the consolidator should be QuoteBar consolidator (Douh!)
Kepler Engelbrecht
Hi, that helps a lot, thank you!
To check that I understand you correctly about the TransactionManager - I'd probably have an instance of a SecurityTransactionManager, and do something similar that the GetOpenOrders method does? One of the methods in that class contains a snippet of functional code that seems ballpark in terms of what I'm going to do: (x => x.Symbol == symbol && x.Status.IsOpen()).ToList()
JayJayD
I'm glad I helped.
Yes, you understood correctly, the QCAlgorithm has a SecurityTransactionManager, so you can call the methods already defined or make your own queries.
Gregory Hosler
I am starting to use Oanda. I come from using different other brokers that all had MT4 support. I have written various MT4 EA's, indicators, and scripts.
My MT4 EA does interactive things like:
when initialized it displays 3 lines (Entry, Stop Loss, Take Profit). You (the user) then moves the lines to where you want your trade to be. Then you click a button (created by EA). The EA then reads the values of these lines, and submits trades based upon the settings of the lines, the Spread, and soem other indicaters (for example, ATR).
I have gathered that it is possible to get Spread. and possibly other indicators. (I would appreciate a reference to documentation to reading other indicators, is there such a library?)
I have not yet found documentation as to how to draw (or read value of) lines. Is there documentation on this ?
I have another MT4 indicator that extends the right side of a rectangle to the right side of the chart (used in much supply/demand programming). It needs to identify rectangles drawn on the chart, and then re-draw them. It will also associate lables with the newly redrawn object.
Sorry for very newbie questions.
I know C, C++, Python, a variety of other languages, and API's. It was fairly easy for me to pick up MQL. I am pretty sure that I can pick up C# very quickly. I already know python. I need to learn the CuantConnect API. For this, I usually rely heavily upon documentation (When I was writing MQL, I used this a lot:
MQL4 Reference
), May I know, please, the equivalent here.
I have looked at the documentation here (
It would be much more useful to (at the same time) look at some examples. that is to say: I also learn from reading samples, modifying, testing, and trying things.
In MT4 there are source code libraries. Do such exist here ?
I am *BRAND NEW* to QuantConnect. I am also an open source developer. I am interested and keen to learn and contrubute.
Thank you and kind regards,
Greg Hosler
JayJayD
Hey Gregory Hosler
Welcome!
The Documentation tab in the upper right corner, there you’ll find a good introduction. But for me the best documentation is the code itself; so clone the repo, launch Visual Studio and just dive into the code. You’ll find lots of useful examples there.
Coding an indicator is an excellent way to know the engine and to contribute, check the issues at github, there are some suggested indicators to implement.
Finally, as far as I know, there is not an automatic way to plotting in real time.
Good luck!
Gregory Hosler
HI JayjayD. I'm trying to stay positive, but...
Is there no docuemtation? I mean REAL documentation, not read a book documentation.
I've looked at the tutorials, the videos, and the documentation. Where's the API documentation ?
From the video tutorials, it's not even clear that what I described above is even possible to do. My EA/Scripts create tools (buttons, lines) that are used by the user to set position entries/exits/stop losses, the buttons then create pending trades and/or watch price, and then upon a condition, create a pending trade. This interaction cannot be done in back testing. The 1st video which describes the overall picture, describes the process as clone, compile, backtest. in otherwords an algorithmic non-interactive EA/program.
I want to compile, run on demo (or eventually live). Most importantly, I want to INTERACT with my program (by moving lines that it has created, or pressing buttons that it has created). Is this even possible, or am I in the wrong place ?
-Greg
Jared Broad
QC is made for creating fully automated strategies and has no mechanisms for creating buttons etc. You need to be a programmer to really make the most of QuantConnect.
There is plenty of documentation. Please be specific with what "real" documentation means for you and indicate what you'd like to see.
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.
Kepler Engelbrecht
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!