Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
In this video tutorial I show how to create a strategy from scratch (not using the wizard, which I never use).
The strategy contains a few optimizable parameters such as SMA length, EMA length, HMA length, three different targets with custom tick settings on each, a stop size, and the option to move target 2 to breakeven after target 1 is hit, as well as move target 3 to breakeven after target 2 is hit.
The strategy is just an example! It took all of 10 minutes to write. Even though it says it made 20k in 90 days over 700 trades, it will likely fail going forward. Simple strategies are usually best, but this one is too simple to work fully automated. Most strategies I write for customers take me hours of work (this one took 10 minutes), so don't just go and copy this strategy and expect good results.
Instead, I created this so you could get your feet wet and learn some of the basics of a more advanced strategy than what Ninja includes with the base install. I also created it so if someone shows you backtest results where it makes tons of money, you can see just how easy it is to produce those results.
Also, don't forget that optimizing based on net profit is virtually worthless. I've spent two years tweaking my custom optimizer type and it considers everything you can imagine such as balanced longs/shorts, trade counts, commission costs, profit factors, expectancy, trade duration, and a bunch of other stuff I don't want to go into because I am not giving it away.
With the normal drop-down list of optimizer types in NT, you don't want to just pick the result that shows the most net profit. You should factor in as many other variables as you can. Unless you're going to do what I did with the custom optimizer, the easiest way is to dump the results to an Excel spreadsheet (feature is built-in to NinjaTrader) and then work some analysis there.
Nice video, Mike. Thanks. I guess you are finding optimization to be a wee bit quicker in NT7 .
You mentioned that you would use the same trail stop for all contracts... but I was under the impression we had no choice.
If I code this:
It works. I've tried something like this:
... but I got compiler errors which I thought meant SetTrailStop only can take two arguments (Calcmode, value).
I was trying to find a way to have different targets/stops on my shorts/longs, and using ToTime to also have different targets/stops depending on time of day.
SetTrailStop is very limited. I don't use it. What I meant was coding your own trailing stop, and controlling it for each target. You also should do it on a small time frame, which means adding a second dataseries to the strategy (mtf).
Thanks for this valuable basis for strategy writing and development.
I took the liberty to code what you demonstrated into v6.5 as I'm not yet using v7. I think every serious student of strategies should go through this exercise, partly for understanding the outline of the code as well as logic and syntax among other things.
If I may, I would like to post this for the next step of learning regarding strat writing. If you feel this shouldn't be done in this particular thread, please remove and/or place in a more appropriate location.
I'm hoping others wanting to provide additional help / suggestions will be able to share and develop this into an even more detailed or advanced code.
"gregid" has set up a new nexusfi.com (formerly BMT) community group here: [COLOR=#810081]https://nexusfi.com/groups/automated-strategies.html[/COLOR] He has helped me with some issues in a Strat I'm writing involving IOrder and other advanced portions of code. I appreciated the issues you mentioned regarding CalculationMode and not using "Ticks" for this piece of code.
There's alot more to be learned for optimization and limit order entry.
Looking forward to your next tutorial on Strat writing!
Those first three lines have me intrigued as I've never seen that before. How does that work? Is it assigning the value SMA(SMAlength) to SMA variable (?) smav? I can see how that makes typing easier and less error prone... one would only need to type "smav" instead of "SMA(SMAlength)" in all later references to that.
Is that a correct interpretation of what you did and why you did it? I know its basic C# stuff but I'm still learning.
Thanks for the video Just wondering if you could explain your comments on why this particular optimization gives positive results but isn't actually profitable. I have only done a little optimization (on a different trading platform) and I'm wondering what is the point of optimization if the results can be so varied?
Would your next step be to forward test an optimized strategy to ensure it works? Just interested in your work flow.