NexusFi: Find Your Edge


Home Menu

 





VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one calhawk01 with 10 posts (1 thanks)
    2. looks_two Big Mike with 9 posts (193 thanks)
    3. looks_3 spinnybobo with 6 posts (2 thanks)
    4. looks_4 stephenszpak with 6 posts (0 thanks)
      Best Posters
    1. looks_one Big Mike with 21.4 thanks per post
    2. looks_two piersh with 8 thanks per post
    3. looks_3 zeller4 with 7 thanks per post
    4. looks_4 Cloudy with 1.5 thanks per post
    1. trending_up 85,339 views
    2. thumb_up 231 thanks given
    3. group 61 followers
    1. forum 67 posts
    2. attach_file 3 attachments




 
Search this Thread

VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy

  #1 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,473

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.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
The following 164 users say Thank You to Big Mike for this post:
aart1, adorati, Alan, Alinghy, AnderW, arbuthnot, Arpad, Ashtreegambler, aslan, Atlasal, Autobot, autotrader8, aventeren, bagzi, Bamizo77, bd92154, BDawg, bon1025hk, boomer50usa, Buddy, bukkan, cclsys, chakspin, ChasBrownTH, Cimino, Cloudy, creasy, ctbaran, dany, DaveTrading, ddspock, deadlyvenom, deandavis, devdas, doug, driver594, dsraider, DTdr2, Enalmada, engl98, evergreen, False, Fat Tails, firstbrain, Flash, flavs, ganamide, Gary, gary9, GaryD, GaryT, GemsBot, gracepips, gregid, GregLGTP, gretzkyless, GTNorthwest, huracan, Icehouse, im197, iPipper427, jacqudy, Jathrop Swayoza, jibe, jntdigital, JohnKK, JohnnyAustin, jonesr9, JustWondering, jwhtrades, jzbqhr, kcmotrader, kevind, kimbobm, Kimland, kirkhammett, kiro, KPreston, listu, LoboTrader, loschle, LostTrader, maiers, MarkG, Maxwell, MBAGearhead, mea109, Mega, MetalTrade, MKaiser, mkaminski, mmather, MrDonQui, MrTrader, n0ph0bia, nanobiotech, nanook77, neilsomi, neocazimi, Nibble, nickdsc, Nientenickgrazie, NJAMC, NTrader, OldGerman, OmegaXan2, optimod, panjm, PaulK410, paulmc1840, piersh, polo974, Portland, project belgrade, Pwirth, raff, raj1301, RBerry, rbrk, redford007, rem4444, resirca52009, richsan, RJay, rogerbar, rsi77, rtace1, Rumann, sam028, Sammy C, Saroj, seeker, semoa, Sentenza, smithma01, sorin, soumi71, spinnybobo, spr1ngfl1ng, spsilage, srvsrv, Stem1, stephenszpak, steve2222, SteveZ, Tbax, theucreport, TomasGeissler, trader2010, Traderji, traderpards, tradesignal, Treggs, tretrader, tshunhu, usct, vvill, waza1960, wbear009, wdjennings, Wessel, wiredawg100, zeller4, zungybungy

Can you help answer these questions
from other members on NexusFi?
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Ninja Trader 8 Drawing Tools Wanted
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
49 thanks
NexusFi site changelog and issues/problem reporting
46 thanks
Battlestations: Show us your trading desks!
34 thanks
GFIs1 1 DAX trade per day journal
32 thanks
Friendly challenge question to vendors
19 thanks

  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,473

This video was recorded in HD mode. Don't forget to click the bottom-right option in the video to expand to full screen, so you can see the text.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
The following 12 users say Thank You to Big Mike for this post:
  #3 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120


very nice.

a quick FYI: in NT7 (c# 3.0) you can declare your strategy/indicator properties like this if you don't care about the Math.Min part:

 
Code
                            
[GridCategory("Parameters")]
public 
MAType MA1 getset; } 
saves a bit of typing...

also, there's (almost) never any need to type 'private'. it's the default and you can omit it.

Reply With Quote
The following 8 users say Thank You to piersh for this post:
  #4 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

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:

 
Code
                            
SetProfitTarget("Long 1a"CalculationMode.TicksTarget);
SetProfitTarget("Short 1a"CalculationMode.TicksTarget);
SetTrailStop(CalculationMode.TicksTrailStop); 
It works. I've tried something like this:

 
Code
                            
SetProfitTarget("Long 1a"CalculationMode.TicksTarget);
SetProfitTarget("Short 1a"CalculationMode.TicksTarget);
SetTrailStop("Long 1a"CalculationMode.TicksTrailStopLong);
SetTrailStop("Short 1a"CalculationMode.TicksTrailStopShort); 
... 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.

Did I miss something obvious with SetTrail Stop?

As always, thanks for sharing your knowledge.

Reply With Quote
The following user says Thank You to MXASJ for this post:
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,473


MXASJ View Post
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.

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).

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
The following 7 users say Thank You to Big Mike for this post:
  #6 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

Big Mike,

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.
 
Code

SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
There's alot more to be learned for optimization and limit order entry.

Looking forward to your next tutorial on Strat writing!

Kirk

Attached Files
You must login first File Type: zip MyMoneyMaker_BigMike.zip (8.2 KB, 856 views)
Reply With Quote
The following 14 users say Thank You to zeller4 for this post:
  #7 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,473

zeller,

Yes, please do, and I look forward to it. I will do more videos soon, but who knows when. I have to be "in the mood"

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
  #8 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

If I may, Mike...

I noted this code:

 
Code
                            
SMA smav SMA(SMAlength);
EMA emav EMA(EMAlength);
HMA hmav HMA(HMAlength);
 
ManageOrders();
 
if (
Position.MarketPosition != MarketPosition.Flat) return;
 
if (
Rising(smav) && Rising(emav) && Rising(hmav))
GoLong();
else
if (
Falling(smav) && Falling(emav) && Falling(hmav))
GoShort(); 
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.

Reply With Quote
  #9 (permalink)
 toulouse-lautrec 
Europe
 
Experience: Beginner
Platform: NinjaTrader
Posts: 73 since Jun 2009
Thanks Given: 13
Thanks Received: 53

recorded 2:07 am

yuck!

anyways, thanks for this informative video

Reply With Quote
The following user says Thank You to toulouse-lautrec for this post:
  #10 (permalink)
 Treggs 
Working on my LCD tan
 
Experience: Advanced
Platform: NinjaTrader
Posts: 127 since Jun 2009
Thanks Given: 25
Thanks Received: 52


Hi Mike,

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.

TIA

Reply With Quote
The following 2 users say Thank You to Treggs for this post:





Last Updated on October 23, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts