I posted a cointegration indicator ("CADF") in the Elite Downloads area. It plots the output statistic of an Augmented Dickey Fuller cointegrating regression of 2 instruments. It's a C# translation of MATLAB code developed by James P. LeSage and posted at Econometrics Toolbox for MATLAB. I used some mathematical routines from ALGLIB (ALGLIB) which are included, and wrote a lot of helper routines to accomplish the MATLAB functions. Even if you're not interested in cointegration, you might find it useful as an example programming with quantitative methods for NinjaTrader.
I haven't seen a cointegration indicator for a trading platform posted publicly before, only MATLAB or R code. So I thought I would be the first. I posted it for futures.io (formerly BMT) Elite members only, please don't share or distribute.
This version is made using primarily static routines, which call "new" frequently. This works fine for indicators or normal strategies, but it can fall apart by filling up memory if you try to run an extensive optimization on it. The alternative is to implement the internal routines as classes which can be instantiated once and pre-allocate their storage once at the start. I've done that for strategies, and it helps optimizer performance quite a bit, but ALGLIB uses "new" in some places so I haven't been able to get rid of all uses of "new".
I also posted the latest ALGLIB 3.5.0 library, packaged as a NinjaTrader "indicator", in the MATLAB downloads area. But it's not needed for CADF, the required ALGLIB routines are included.
The following 11 users say Thank You to kevind for this post:
Thanks, as a math-stupid person, I was wondering about this.
Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.
Need help? 1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first. 2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses. 3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make. 4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance. 5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers. 6) Help using the forum? Watch this video to learn general tips on using the site.
If you want to support our community, become an Elite Member.
Thanks for your contribution, I never been exposed to this trade style and i am a completely ignorant about this, but for sure its an interest theme and style. It will be good if you post some example on how to use this approach.
kevind, about some examples I would be pleased too.
I experimented with this approach in Matlab before a while and tried to translate this to C# but failed.
The same problem with R.
Thank you for your code I will take a look.
The following user says Thank You to bascher for this post:
It should work fine with futures, or futures paired with stocks. You need to enter a symbol in the proper form, the symbol must exist in the instrument manager, and the data has to exist for the period specified. Cointegration is typically tested on daily data over longer periods, so continuous futures data is probably your best bet.
Proper symbol form is i.e. "ES ##-##" for continuous futures, or "ES 06-12" for a specific contract.
Thanks for the reply. I have the ES and 6E loaded on a Ninja chart for max days daily chart. Also tried 1440 minute chart because I know some indicators only report on 1440 minute charts on Ninja. Still nothing with the CADF. The parameters list "Symbol 2", which I assume is the second symbol, Nlag ste to 1, P set to 0, and Period set to 250. Should any of these be adjusted? Thanks.