VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy - futures io
futures io futures trading



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 zeller4 with 7 thanks per post
    3. looks_3 piersh with 7 thanks per post
    4. looks_4 Cloudy with 1.5 thanks per post
    1. trending_up 71,915 views
    2. thumb_up 228 thanks given
    3. group 62 followers
    1. forum 67 posts
    2. attach_file 3 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy

(login for full post details)
  #1 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received

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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io 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 futures io?
Data for the YM and RTY for NT8 to practice on?
NinjaTrader
Reading A set of Trading Signals
EasyLanguage Programming
OFA (Order Flow Analytics) Licence
NinjaTrader
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
Help Needed: TOS Options Chain IV & IMPL MOVE Calcul …
ThinkOrSwim
 
 
(login for full post details)
  #2 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received

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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 12 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #3 (permalink)
California
 
 
Posts: 87 since Jun 2009
Thanks: 5 given, 119 received


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 7 users say Thank You to piersh for this post:
 
(login for full post details)
  #4 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

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:
 
(login for full post details)
  #5 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received


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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 7 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #6 (permalink)
Florida
 
Experience: Intermediate
Platform: NT7
Trading: CL, NQ, NG
 
Posts: 469 since Jun 2009
Thanks: 1,401 given, 402 received

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 futures.io (formerly BMT) community group here: https://futures.io/groups/automated-strategies.html 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
Register to download File Type: zip MyMoneyMaker_BigMike.zip (8.2 KB, 835 views)
Reply With Quote
The following 14 users say Thank You to zeller4 for this post:
 
(login for full post details)
  #7 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received

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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #8 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

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
 
(login for full post details)
  #9 (permalink)
Europe
 
Experience: Beginner
Platform: NinjaTrader
 
Posts: 73 since Jun 2009
Thanks: 11 given, 53 received

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:
 
(login for full post details)
  #10 (permalink)
Working on my LCD tan
 
Experience: Advanced
Platform: NinjaTrader
 
Posts: 127 since Jun 2009
Thanks: 25 given, 51 received


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 user says Thank You to Treggs for this post:
 
(login for full post details)
  #11 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received


Treggs View Post
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

There are a few reasons.

1) Not enough backtesting data. You need to really backtest for > 1 year, in my opinion.
2) Yes, you need to forward test in live market.
3) Simple is usually better, but in this case, the strategy is too simple to work. Efficiency is required to be profitable, and this strategy isn't very efficient in my opinion.

Still, I'm sure you could do worse

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 5 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #12 (permalink)
Chicago
 
Experience: Intermediate
Platform: Ninja Trader & TradeStation
Broker: Amp Futures/Zen-Fire
Trading: ES
 
Posts: 56 since Jun 2009
Thanks: 17 given, 48 received

Mike,
Great video. I only learned C# from what I've done in NT so your little tricks will help me a lot in writing more elegant code.

By the way, what did you use for screen capture? The quality of the video is excellent.

Ron

Reply With Quote
 
(login for full post details)
  #13 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received

Ron,

I used Camtasia and recorded it in HD mode (1920x1080), and have a Vimeo Plus account which supports 720p and 1080p videos.

I'll do all my future videos this way, thanks for the feedback.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #14 (permalink)
Chicago
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-FIre
Trading: GC, ES
 
Posts: 73 since Mar 2010
Thanks: 40 given, 32 received

Mike,

Great job. The video was clear, valuable and easy to understand.

Reply With Quote
 
(login for full post details)
  #15 (permalink)
Market Wizard
New Orleans, La (Mardi Gras City)
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
 
DavidHP's Avatar
 
Posts: 1,351 since Aug 2009
Thanks: 9,506 given, 2,363 received


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

Kirk

Greetings,
I have tried to run the strategy.
As long as I run it in Simulation or Market Replay mode it works fine.

If I try to run it with a 'live' realtime feed, I get an error message.
I've attached it here.

Does anyone know what would cause this?

I think it is the exit method using more than one target?

Thanks,


 
Code
An over fill was detected on order
'Order='44af571b9b9d45c7877c78edbbb3547a/Sim101' Name='target2'
State=Filled Instrument='6E 06-10' Action=SellShort Limit price=0 
Stop price=0 Quantity=1 Strategy='BarColorChgv3' Type=Market 
Tif=Gtc Oco='-f6739cd0d9334993a2b6879bc6792c90' 
Filled=1 Fill price=1.3404 Token='44af571b9b9d45c7877c78edbbb3547a'
 Gtd='12/1/2099 12:00:00 AM'' generated by strategy
'BarColorv3/f6739cd0d9334993a2b6879bc6792c90' : This strategy will be disabled and NinjaTrader will attempt to cancel/close any strategy generated orders and positions. Please check your account orders and positions and take any appropriate action.
 
Code
Strategy 'BarColorv3/f6739cd0d9334993a2b6879bc6792c90' attempted to cancel an
 order with ID '30eb4130978e40778d70732b650955ad' however, NinjaTrader has not
 yet received cancellation confirmation from your broker. 
Please check your account orders and position and take appropriate action.

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
 
(login for full post details)
  #16 (permalink)
Florida
 
Experience: Intermediate
Platform: NT7
Trading: CL, NQ, NG
 
Posts: 469 since Jun 2009
Thanks: 1,401 given, 402 received

I think the offending code has to do with

 
Code
BarColorv3
I don't have Ninja on at the moment to look at the code to see if that has anything to do with what I posted. Do you have a separate cs file for this?

kz

Reply With Quote
 
(login for full post details)
  #17 (permalink)
Elverum, Norway
 
Experience: Intermediate
Platform: Multicharts, Ninja Trader
Broker: Optimus futures / Rithmic
Trading: NQ
 
Posts: 7 since Dec 2009
Thanks: 5 given, 1 received

Hello

Thank you for making videos like this. For those of us that is not very experienced in making ninja strategies, it is very usefull to watch and learn. One video like that, saves me for many hours of reading. I hope you can make more of them to us.

Reply With Quote
 
(login for full post details)
  #18 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received

Mike

thanks for posting this video. It is really great for us who are learning programming to see videos like this as there are literally none on the internet for NinjaTrader.

so thank you very much

Spencer

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #19 (permalink)
Tucson, AZ
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Mirus/Zen-Fire
Trading: CL, TF
 
LostTrader's Avatar
 
Posts: 74 since Sep 2009
Thanks: 21 given, 64 received

Thank you for this video. I have no experience with strategies and have been hesitant to jump in. I found your walk-through on writing a strategy very encouraging. It seems to be one of those programming things that NT doesn't like to discuss in their videos.

Reply With Quote
The following user says Thank You to LostTrader for this post:
 
(login for full post details)
  #20 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

Post #6 has the download.

In the download:

private bool be2 = true;
private bool be3 = true;

In the video:

private bool be2 =false;
private bool be3 =false;

So which is correct? (Sorry if this question was already covered or I missed something here.)

I've spent some time now and then trying to understand NinjaScript. I appreciate this video greatly. There
is just no way whatsoever I could have put together this strategy. I have altered it to remove the moving
averages, which never seem to help, and added some other very basic code.
It compiles so it must work. (hee hee)

- Stephen

Reply With Quote
 
(login for full post details)
  #21 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

I just ran MyMoneyMaker_BigMike in the Optimizer. I'm not positive of what I see in the
attachment (included). Is the 1L, 2L, 3L in the 'executions' what one would expect? I'm thinking
that 3L means there are 3 long contracts in the market. I thought the strategy would only allow
one long (or short) at a time. (I'm extremely new to the Optimizer.)

- Stephen

Attached Thumbnails
Click image for larger version

Name:	positions in backtest.jpg
Views:	399
Size:	324.8 KB
ID:	16519  
Reply With Quote
 
(login for full post details)
  #22 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

I don't know if this thread is still active or not. If anyone wants to comment that's fine.

From post #11:

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
There are a few reasons.

1) Not enough backtesting data. You need to really backtest for > 1 year, in my opinion.



I'm don't like moving averages in general, but if someone used a system that was backtested with moving
averages, and it was found to be profitable over the last, let's say 13 weeks (quarter year), then why wouldn't
optimizing it daily, always looking back 13 weeks (ie. 65 trading days) work to keep the system profitable?

- Stephen

Reply With Quote
 
(login for full post details)
  #23 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

It seems I'm having trouble fully understanding the code of the video. The attachment
enclosed (YM) shows a long trade taken that was profitable and unprofitable at the same time.
One can see the green dots and red dots. I think I'm making a basic mistake regarding understanding
order placement and or quantity.

I thought the profitable long trade entered at the beginning of the day would be exited much much sooner.
Or maybe it is??

- Stephen

Attached Thumbnails
Click image for larger version

Name:	image July25.jpg
Views:	410
Size:	373.8 KB
ID:	17447  
Reply With Quote
 
(login for full post details)
  #24 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received


stephenszpak View Post
It seems I'm having trouble fully understanding the code of the video. The attachment
enclosed (YM) shows a long trade taken that was profitable and unprofitable at the same time.
One can see the green dots and red dots. I think I'm making a basic mistake regarding understanding
order placement and or quantity.

I thought the profitable long trade entered at the beginning of the day would be exited much much sooner.
Or maybe it is??

- Stephen

Hi,

It's because there is more than one target...

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #25 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

Ok. What I thought was happening was that the stoploss became a breakeven stop which
later became a trailing stop. Are you saying that all 3 stops are setup from the get-go? With
each one relaying off to the next? which is what seems to be happening here as I look more closely.

Also, it seems that if the system is long, it will not go short even if the 3 moving averages are
falling, IF none of the stops have been triggered. Is this correct?

Thanks for the previous reply,

- Stephen

Reply With Quote
 
(login for full post details)
  #26 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received


stephenszpak View Post
Ok. What I thought was happening was that the stoploss became a breakeven stop which
later became a trailing stop. Are you saying that all 3 stops are setup from the get-go? With
each one relaying off to the next? which is what seems to be happening here as I look more closely.

Also, it seems that if the system is long, it will not go short even if the 3 moving averages are
falling, IF none of the stops have been triggered. Is this correct?

Thanks for the previous reply,

- Stephen

I'm sorry, I don't recall the particulars of it and no longer have it and don't do any NinjaTrader programming any more. My suggestion is to look at the Hurley thread, there are hundreds and hundreds of replies with advanced order management, break even stops, etc. You will learn a lot from the thread, just take some time and read through it.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #27 (permalink)
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

Thanks. Can't hurt. Might help.

- Stephen

Reply With Quote
 
(login for full post details)
  #28 (permalink)
 
 
Posts: 1,081 since May 2010

Can you do the same for multicharts :-)

Reply With Quote
 
(login for full post details)
  #29 (permalink)
Canada
 
Experience: Intermediate
Platform: NT, IB
Broker: IB
Trading: Currency Futures
 
sam1197's Avatar
 
Posts: 55 since Feb 2011
Thanks: 13 given, 12 received

Excellent video.. I wonder why Ninja would not post something similar to help their users. lousy support.

One question, you used your own parameter to optimize on. Is it something I can download and use? Thanks much

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #30 (permalink)
Canada
 
Experience: Intermediate
Platform: NT, IB
Broker: IB
Trading: Currency Futures
 
sam1197's Avatar
 
Posts: 55 since Feb 2011
Thanks: 13 given, 12 received

Mike in this video warn about using the default optimizer and used PH Generic and used his own parameter called _mike_preferred. I searched the forum to find this to download but no success. How can I implement this for my own optimization? Side note: I tried simple optimization for 2 month data, NT7 crashed. I have used my notebook without any upgrades. Is this typical. I am travelling now and this is what I have access to.


Thanks much. I am in the process to upgrade to elite but my paypal acct have been inactive for years. working on it.


Big Mike View Post
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


Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to sam1197 for this post:
 
(login for full post details)
  #31 (permalink)
BC Canada
 
Experience: Beginner
Platform: Several
Trading: Stocks, Currency
 
Posts: 25 since Apr 2011
Thanks: 29 given, 4 received

Hi; Mike
Very nice and very help full Great job. The video was clear, valuable and easy to understand.
Best Regards

Reply With Quote
 
(login for full post details)
  #32 (permalink)
minneapolis
 
Experience: Beginner
Platform: ninjatrader
Trading: nq
 
Posts: 6 since Aug 2010
Thanks: 1 given, 0 received

Thanks Mike for the video . Very helpful for a new guy.

Reply With Quote
 
(login for full post details)
  #33 (permalink)
Boston Massachusetts
 
 
Posts: 1 since May 2011
Thanks: 9 given, 0 received

(My first post as a new member -- hi everyone! Mike, this site is amazing, so much quality content...)

This video was very helpful for me, simply by going through the entire process from start to finish in a straightforward fashion. I appreciate that you took the time to capture a legible HD video. +1 for high-speed typing and compile-from-the-hip.

Now armed with some programming experience, and this video, I'm off to write my first ninjascript strategy.

(again: This site! Think of the dollars and years you've saved everyone by bringing this together in one spot...)

Thanks!

Reply With Quote
 
(login for full post details)
  #34 (permalink)
Newark
 
 
Posts: 2 since Jul 2011
Thanks: 0 given, 1 received

Hey - I am a newbie to Ninja trader platform. I have entered EXACTLY what Big Mike showed in the video but when I compile, I get this error no matter what I do:


Strategy\NewTest.cs The name 'be3' does not exist in the current context CS0103 - click for info 115 26
Strategy\NewTest.cs The name 'be3' does not exist in the current context CS0103 - click for info 116 19

Line 115 and 116 don't contain 'be3'. Is there some simple newbie thing I am missing?! Even if I completely remove be3 from the script and replace it with something else, I still get the same error. So I am mightily confused. Any help would be much appreciated .... Thanks!

WBJo

Reply With Quote
 
(login for full post details)
  #35 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,778 since Jun 2009
Thanks: 32,304 given, 97,558 received


WBJo View Post
Hey - I am a newbie to Ninja trader platform. I have entered EXACTLY what Big Mike showed in the video but when I compile, I get this error no matter what I do:


Strategy\NewTest.cs The name 'be3' does not exist in the current context CS0103 - click for info 115 26
Strategy\NewTest.cs The name 'be3' does not exist in the current context CS0103 - click for info 116 19

Line 115 and 116 don't contain 'be3'. Is there some simple newbie thing I am missing?! Even if I completely remove be3 from the script and replace it with something else, I still get the same error. So I am mightily confused. Any help would be much appreciated .... Thanks!

WBJo

You have a type-o. Case sensitivity matters.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Started this thread Reply With Quote
 
(login for full post details)
  #36 (permalink)
Newark
 
 
Posts: 2 since Jul 2011
Thanks: 0 given, 1 received

Thanks Mikewbjoh998 - I figured that part out, and checked everything. Still possible, of course (been down that road many times win other programming environments) but I'm guessing not. When I load a standard indicator like Bollinger and try to compile I get a similar error message, which leads me to believe something is wrong in general with my installation.

Reply With Quote
The following user says Thank You to WBJo for this post:
 
(login for full post details)
  #37 (permalink)
Quebec
 
Experience: Intermediate
Platform: MultiCharts
Trading: Futures
 
Posts: 3 since Nov 2012
Thanks: 0 given, 1 received

Hi Mike, Thank you for this video, it was really helpful.

I am wondering how I could program my own set of rule to "optimize on" like you did with " _mike_preferred" I don't have problem to program in C# and I already did some strategies who look profitable when I test them in the market replay.

But I would really like to be able to set my own set of rule for optimization.
Please help me with that.

Thank you

Reply With Quote
 
(login for full post details)
  #38 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

hi i'm not a programmer but am learning from this script. this script seems to buy 3 contracts. how can I only make it one contract?
 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");

						
		}
will that do?

what I'm trying to do is, buy 1 contract when my signal occurs, and move my targets and stops as they occur only for ONE contract

Reply With Quote
 
(login for full post details)
  #39 (permalink)
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,965 since Dec 2010
Thanks: 3,035 given, 2,377 received


calhawk01 View Post
hi i'm not a programmer but am learning from this script. this script seems to buy 3 contracts. how can I only make it one contract?
 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");

						
		}
will that do?

what I'm trying to do is, buy 1 contract when my signal occurs, and move my targets and stops as they occur only for ONE contract

You should be able to delete the following line because you don't enter a position with a similar name:
SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #40 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

Thank you for the reply.

Now I have:

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			
			EnterLong("target1");

		}


		
		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
				
				if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
			
			}
This still does not seem to work. It exits at profit target1

Reply With Quote
 
(login for full post details)
  #41 (permalink)
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,965 since Dec 2010
Thanks: 3,035 given, 2,377 received


calhawk01 View Post
Thank you for the reply.

Now I have:

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			
			EnterLong("target1");

		}


		
		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
				
				if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
			
			}
This still does not seem to work. It exits at profit target1

Hi,

I couldn't find a description of what you were trying to do, but that seems correct with a single target.

Can you describe what it is you are trying to do?

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #42 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received


NJAMC View Post
Hi,

I couldn't find a description of what you were trying to do, but that seems correct with a single target.

Can you describe what it is you are trying to do?

hi NJAMC, apolgs for the late reply [went on a vaca ]

what i'm trying to do is:

buy one contract when my buy conditions are true, set my initial stoploss 12 ticks away, and have three targets, once target1 is hit, I want to move my initial stoploss to my purchase price, once target2 is hit, i want to move my stoploss to target1 and once target 3 is hit, i want to exit. i thought that is what this script did but it's a bit different :/

Reply With Quote
 
(login for full post details)
  #43 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
				
			}
when t1 is hit, it moves to stoploss to average price, but when t2 is hit, the stoploss isn't moved to t1

Reply With Quote
 
(login for full post details)
  #44 (permalink)
desert CA
 
Experience: Intermediate
Platform: NT7, SC, ToS
Broker: AMP, DT, TDA
Trading: CL,NQ,YM
 
Posts: 2,134 since Jul 2011
Thanks: 2,387 given, 1,723 received

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
                                else if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
                                else if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
			}
                }

Just an idea. Reversing the order of the statements and using "else" so that "SetStopLoss" is not set multiple times in the loop. I don't have a strategy setup currently to test it.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #45 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

Cloudy, thank you for trying. Still no luck though :/

here is the complete code to the strategy:

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
		
			EnterLong("target1");
			
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
                                else if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
                                else if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				
			}
                
			
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

ManageOrders();

if (CrossBelow(CCI(14), 250, 1))
EnterLong();
}

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Reply With Quote
The following user says Thank You to calhawk01 for this post:
 
(login for full post details)
  #46 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

Alright i'm going to give up on this unless someone helps me lol

I've tried to play around with this for the past several days but it does not seem to work properly

Current code I have, does not seem to call the "manage order();" properly.

It enters the positions, but the stoploss only changes ONCE when target1 is hit, the stoploss moves to avg price, but when target2 is hit, stoploss is never moved to target1 and so on..

Thanks in advance for looking at the code:

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
			EntryHandling		= EntryHandling.UniqueEntries;
			
		}
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target2*TickSize));	
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
			
			}
                
			
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {

            EntryHandling		= EntryHandling.UniqueEntries;
			
			GoLong();
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			if (........ENTER ANY TRADING LOGIC.................))
				EnterLong("target1");
				GoLong();
			if (ToTime(Time[0]) == ToTime(15, 56, 0))
				ExitLong("", "");			
        }

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Reply With Quote
 
(login for full post details)
  #47 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received


calhawk01 View Post
Alright i'm going to give up on this unless someone helps me lol

I've tried to play around with this for the past several days but it does not seem to work properly

Current code I have, does not seem to call the "manage order();" properly.

It enters the positions, but the stoploss only changes ONCE when target1 is hit, the stoploss moves to avg price, but when target2 is hit, stoploss is never moved to target1 and so on..

Thanks in advance for looking at the code:

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")]
    public class TargetES930 : Strategy
    {
        //#region Variables
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		
		private int		stop			= 12;
		
		private bool	be2				= true;
		private bool	be3				= true;
		
		
		//#endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
			EntryHandling		= EntryHandling.UniqueEntries;
			
		}
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target2*TickSize));	
		}

		private void ManageOrders()
		{

			if (Position.MarketPosition == MarketPosition.Long)
			{
				if (High[0] > Position.AvgPrice + (Target1*TickSize))
					SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
					SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
				if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
					SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
			
			}
                
			
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {

            EntryHandling		= EntryHandling.UniqueEntries;
			
			GoLong();
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			if (........ENTER ANY TRADING LOGIC.................))
				EnterLong("target1");
				GoLong();
			if (ToTime(Time[0]) == ToTime(15, 56, 0))
				ExitLong("", "");			
        }

        //#region Properties
		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE2
        {
            get { return be2; }
            set { be2 = value; }
        }
		[Description("")]
        [Category("Parameters")]
        public bool BE3
        {
            get { return be3; }
            set { be3 = value; }
        }
		
		
        //#endregion
    }
}

Hey Calhawk01

it looks like in the method GoLong() you only have SetProfitTarget for "target1" and did not set it for "target2 and "target3. If you don't set them, then they don't exist.
or you are setting them the manageorders and bugs are then happening. Make sure when you first GoLong, you have Stops and all Profit Targets set. then when they are set, you can properly call manageorders. otherwise weird things happen and hard to trace. make a step by step list, then program it that way. It will take care of most of your problems.

actually, now that I look at it, if you are using 3 positions you need to call SetStopLoss 3 times.
here is the code you should start with as a template. It has been stripped down. If not using the optimizer, then you don't need B/E, if you are not going short, then you don't need short logic.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		private int		stop			= 12;
		
		
		
        protected override void Initialize()
        {
            
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				//Enter Trade management logic here for stop tightening
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
    }
}
hope this helps.
can you please describe your management strategy?

Spencer

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #48 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received


spinnybobo View Post
Hey Calhawk01

it looks like in the method GoLong() you only have SetProfitTarget for "target1" and did not set it for "target2 and "target3. If you don't set them, then they don't exist.
or you are setting them the manageorders and bugs are then happening. Make sure when you first GoLong, you have Stops and all Profit Targets set. then when they are set, you can properly call manageorders. otherwise weird things happen and hard to trace. make a step by step list, then program it that way. It will take care of most of your problems.

actually, now that I look at it, if you are using 3 positions you need to call SetStopLoss 3 times.
here is the code you should start with as a template. It has been stripped down. If not using the optimizer, then you don't need B/E, if you are not going short, then you don't need short logic.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		target1			= 12;
		private int		target2			= 10;
		private int		target3			= 24;
		private int		stop			= 12;
		
		
		
        protected override void Initialize()
        {
            
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
			
			
        }
		
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				//Enter Trade management logic here for stop tightening
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return stop; }
            set { stop = Math.Max(1, value); }
        }
    }
}
hope this helps.
can you please describe your management strategy?

Spencer

Hello Spencer, the above code enters three different positions. that's what i'm trying to change. the original code posted by bigmike also enters three different positions. I want to enter one position (one contract) with three different profit targets and stoplosses that move once profit targets are hit. initial stoploss 12 ticks, if target1 is hit then stoploss= avg price, if target2 is hit, then stoploss=target1, if target3 is hit, then stoploss= target2

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
			SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
			SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
			
			EnterLong("target1");
			EnterLong("target2");
			EnterLong("target3");
			
		}
the above creates three different positions/ buys three contracts

i figured the below would set the stoploss and target1 when the trade is first entered, but once target1 is hit, ManageOrder() would kick in and move the stoplosses. Ya know?

 
Code

 
Code
		private void GoLong()
		{
			SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);

			
			SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));

			
			EnterLong("target1");

			
		}

Reply With Quote
 
(login for full post details)
  #49 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received

anyone? maybe I can paypal you some cash?? i really dont feel like dropping hundreds of dollars to one of the indicator creating companies! b/c i feel like i already have the correct code.. just needs some additional coding or move some parts around. need:

buy ONE contract when trade logic becomes true with the following trade management settings: initial stoploss 12 ticks, if target1 is hit then stoploss= avg price, if target2 is hit, then stoploss=target1, if target3 is hit, then stoploss= target2

thank you in advance for taking the time

Reply With Quote
 
(login for full post details)
  #50 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received

Hey,

Ok, I know what you mean now. So, I think in order to access the entry price, you need to create an IOrder object.

 
Code
private IOrder _entry = null;

//then you can do this
_entry = EnterLong("tag you want to give");

//then later you can do this
if (High[0] >= (target1 * TickSize))
SetStopLoss(CaculationMode.Price, (_entry.AvgFillPrice);
I did not try it out yet. Look at Scott Shodsons Ninja Trader webinars. He uses IOrders a lot.
He has 2 webinars. They are very good.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		_target1			= 12;
		private int		_target2			= 10;
		private int		_target3			= 24;
		private int		_stop			= 12;
		
		private IOrder _entry = null;
		
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
        }
		
		private void GoLong()
		{
			SetStopLoss("Enter_Position", CalculationMode.Price, Close[0] - (Stop*TickSize), false);

			_entry = EnterLong("Enter_Position");
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				if(High[0] >= (_target1 * TickSize))
					SetStopLoss(CalculationMode.Price, _entry.AvgFillPrice);
				else if (High[0] >= (_target2 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target1 * TickSize)));
				else if (High[0] >= (_target3 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target2 * TickSize)));
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return _target1; }
            set { _target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return _target2; }
            set { _target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return _target3; }
            set { _target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return _stop; }
            set { _stop = Math.Max(1, value); }
        }
    }
}
hope this helps

I will code something later and test it.
Spencer

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #51 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received


spinnybobo View Post
Hey,

Ok, I know what you mean now. So, I think in order to access the entry price, you need to create an IOrder object.

 
Code
private IOrder _entry = null;

//then you can do this
_entry = EnterLong("tag you want to give");

//then later you can do this
if (High[0] >= (target1 * TickSize))
SetStopLoss(CaculationMode.Price, (_entry.AvgFillPrice);
I did not try it out yet. Look at Scott Shodsons Ninja Trader webinars. He uses IOrders a lot.
He has 2 webinars. They are very good.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Big Mike - 1/26/10 - https://futures.io/beginners-introductions-tutorials/2512-video-tutorial-how-create-advanced-ninjatrader-strategy.html
    /// </summary>
    [Description("Make me millions Jan 27 2010")] //modified by Spencer Davis as a simple template 05/30/2013.  
    public class MyMoneyMaker_BigMike : Strategy
    {
        
		
		private int		_target1			= 12;
		private int		_target2			= 10;
		private int		_target3			= 24;
		private int		_stop			= 12;
		
		private IOrder _entry = null;
		
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			EntryHandling		= EntryHandling.UniqueEntries;
        }
		
		private void GoLong()
		{
			SetStopLoss("Enter_Position", CalculationMode.Price, Close[0] - (Stop*TickSize), false);

			_entry = EnterLong("Enter_Position");
		}
		
		private void ManageOrders()
		{
			if (Position.MarketPosition == MarketPosition.Long)
			{
				if(High[0] >= (_target1 * TickSize))
					SetStopLoss(CalculationMode.Price, _entry.AvgFillPrice);
				else if (High[0] >= (_target2 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target1 * TickSize)));
				else if (High[0] >= (_target3 * TickSize))
					SetStopLoss(CalculationMode.Price, (_entry.AvgFillPrice + (_target2 * TickSize)));
			}
		}

        protected override void OnBarUpdate()
        {
            EntryHandling		= EntryHandling.UniqueEntries;
			ManageOrders();
			
			if (Position.MarketPosition != MarketPosition.Flat) return;
			
			//if ( enter reason for going long here ) 
			//	GoLong();
			
        }

		[Description("")]
        [Category("Parameters")]
        public int Target1
        {
            get { return _target1; }
            set { _target1 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target2
        {
            get { return _target2; }
            set { _target2 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Target3
        {
            get { return _target3; }
            set { _target3 = Math.Max(1, value); }
        }
		[Description("")]
        [Category("Parameters")]
        public int Stop
        {
            get { return _stop; }
            set { _stop = Math.Max(1, value); }
        }
    }
}
hope this helps

I will code something later and test it.
Spencer

Spencer, I'm at work right now so won't be able to test it till later. Thank you for the help Spencer!

Reply With Quote
 
(login for full post details)
  #52 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received

hmm, actually I am still new to Ninjascript. It seems like Position.AvgPrice is the average representation of the fill price. from the documentation

 
Code
{
    // Raise stop loss to breakeven when there is at least 10 ticks in profit
    if (Close[0] >= Position.AvgPrice + 10 * TickSize)
         ExitLongStop(Position.Quantity, Position.AvgPrice);
}
So, we probably don't need IOrder, but I hear that most professionals will only use them with real live strategies. We can always take IOrder out and replace _entry.AvgFillPrice with Position.AvgPrice and just add a simple SMA cross strategy or something.

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #53 (permalink)
baltimore marylnd
 
Experience: Beginner
Platform: ninja
Trading: es
 
Posts: 91 since May 2013
Thanks: 5 given, 11 received


spinnybobo View Post
hmm, actually I am still new to Ninjascript. It seems like Position.AvgPrice is the average representation of the fill price. from the documentation

 
Code
{
    // Raise stop loss to breakeven when there is at least 10 ticks in profit
    if (Close[0] >= Position.AvgPrice + 10 * TickSize)
         ExitLongStop(Position.Quantity, Position.AvgPrice);
}
So, we probably don't need IOrder, but I hear that most professionals will only use them with real live strategies. We can always take IOrder out and replace _entry.AvgFillPrice with Position.AvgPrice and just add a simple SMA cross strategy or something.


you're correct about position.avgprice

Reply With Quote
 
(login for full post details)
  #54 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received

Hey calhawk01

I think this code pretty much works.
I did not use IOrders. You can always take out the reason to get long or short. You can also play with the drawLine things.
However, I believe it works or at least it is a general outline to what you were looking for

take care
Spencer

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /*
	Author:  Spencer Davis
	This is an outline Trade Management strategy for using dynamic stops and targets
	*/
    [Description("A strategy that trails the stops")]
    public class sdTM : Strategy
    {
		//periods
		private int fastPeriod = 8;
		private int slowPeriod = 34;
		
		//trade management
		private int stopLoss = 18;
		private int target1 = 10;
		private int target2 = 20;
		private int target3 = 30;
		private SMA fastSMA;
		private SMA slowSMA;
		
		private bool drawStop = false;
		
        
        protected override void Initialize()
        {
		CalculateOnBarClose = true;
		EntryHandling = EntryHandling.UniqueEntries;
		fastSMA = SMA(FastPeriod);
		slowSMA = SMA(SlowPeriod);
		Add(slowSMA);
		Add(fastSMA);
		fastSMA.Plots[0].Pen.Width = 2;
		fastSMA.Plots[0].Pen.Color = Color.Green;
		slowSMA.Plots[0].Pen.Width = 2;
		slowSMA.Plots[0].Pen.Color = Color.Red;
			
        }

        protected override void OnBarUpdate()
        {
		if (CurrentBar < 20) return; //make sure there is enough data

		//buy conditions
		if (CrossAbove(SMA(FastPeriod), SMA(SlowPeriod), 1)&& Flat)
			GoLong();
		else if (CrossBelow(SMA(FastPeriod),SMA(SlowPeriod),1) && Flat)
			GoShort();			
		ManageTrade();
        }
	private void ManageTrade()
	{
		if(Long)
		{
			if (!drawStop)
				this.DrawLine("StopLine"+CurrentBar, true, 0, (Position.AvgPrice - StopLoss*TickSize), -8, (Position.AvgPrice -StopLoss*TickSize), Color.Red, DashStyle.Dash, 2);				
				
			if (High[0] >= (Position.AvgPrice + Target1*TickSize) && High[0] < (Position.AvgPrice + Target2*TickSize))
			{
				SetStopLoss("EntryLong", CalculationMode.Price, Position.AvgPrice, false);
				this.DrawLine("BreakEvenLong"+CurrentBar,true,0,(Position.AvgPrice + Target1*TickSize), -8, (Position.AvgPrice + Target1*TickSize), Color.Gray, DashStyle.Dash, 2);
			}
			if (High[0] >= (Position.AvgPrice + Target2*TickSize)&& High[0] < (Position.AvgPrice + Target3*TickSize))
			{
				SetStopLoss("EntryLong", CalculationMode.Price, Position.AvgPrice + Target1*TickSize, false);
				this.DrawLine("Target1Long"+CurrentBar,true,0,(Position.AvgPrice + Target2*TickSize), -8, (Position.AvgPrice + Target2*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			if (High[0] >= (Position.AvgPrice + Target3*TickSize))
			{
				ExitLong(1, "Exiting Long", "EntryLong");
				this.DrawLine("Target2Long"+CurrentBar,true,0,(Position.AvgPrice + Target3*TickSize), -8, (Position.AvgPrice + Target3*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			drawStop = true;	
		}
		if(Short)
		{
			if (!drawStop)
				this.DrawLine("StopLine"+CurrentBar, true, 0, (Position.AvgPrice + StopLoss*TickSize), -8, (Position.AvgPrice + StopLoss*TickSize), Color.Red, DashStyle.Dash, 2);				

			if (Low[0] <= (Position.AvgPrice - Target1*TickSize)&& Low[0] > (Position.AvgPrice - Target2*TickSize))
			{
				SetStopLoss("EntryShort", CalculationMode.Price, Position.AvgPrice, false);
				this.DrawLine("BreakEvenShort"+CurrentBar,true,0,(Position.AvgPrice - Target1*TickSize), -8, (Position.AvgPrice - Target1*TickSize), Color.Gray, DashStyle.Dash, 2);
			}
			if (Low[0] <= (Position.AvgPrice - Target2*TickSize)&& Low[0] > (Position.AvgPrice - Target3*TickSize))
			{
				SetStopLoss("EntryShort", CalculationMode.Price, Position.AvgPrice - Target1*TickSize, false);
				this.DrawLine("Target1Long"+CurrentBar,true,0,(Position.AvgPrice - Target2*TickSize), -8, (Position.AvgPrice - Target2*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			if (Low[0] <= (Position.AvgPrice - Target3*TickSize))
			{
				ExitShort(1, "Exiting Short", "EntryShort");
				this.DrawLine("Target2Long"+CurrentBar,true,0,(Position.AvgPrice - Target3*TickSize), -8, (Position.AvgPrice - Target3*TickSize), Color.Green, DashStyle.Dash, 2);
			}
			drawStop = true;
		}
	}
	private void GoLong()
	{
		SetStopLoss("EntryLong", CalculationMode.Ticks, StopLoss, false);
		EnterLong(1, "EntryLong");
		drawStop = false;
	}
	private void GoShort()
	{
		SetStopLoss("EntryShort", CalculationMode.Ticks, StopLoss, false);
		EnterShort(1, "EntryShort");
		drawStop = false;
	}
	//returns current state of Flat, Long, or Short
	#region TradeState
	private bool Flat { get{ return Position.MarketPosition == MarketPosition.Flat; } }
	private bool Long { get{ return Position.MarketPosition == MarketPosition.Long; } }
	private bool Short { get{ return Position.MarketPosition == MarketPosition.Short; } }
	#endregion

        #region Properties
        [Description("Fast Period")]
        [GridCategory("Parameters")]
        public int FastPeriod
        {
            get { return fastPeriod; }
            set { fastPeriod = Math.Max(1, value); }
        }
		[Description("Slow Period")]
        [GridCategory("Parameters")]
        public int SlowPeriod
        {
            get { return slowPeriod; }
            set { slowPeriod = Math.Max(1, value); }
        }
		[Description("Stop Loss")]
        [GridCategory("Parameters")]
        public int StopLoss
        {
            get { return stopLoss; }
            set { stopLoss = Math.Max(1, value); }
        }
		[Description("1st Target")]
        [GridCategory("Parameters")]
        public int Target1
        {
            get { return target1; }
            set { target1 = Math.Max(1, value); }
        }
		[Description("2nd Target")]
        [GridCategory("Parameters")]
        public int Target2
        {
            get { return target2; }
            set { target2 = Math.Max(1, value); }
        }
		[Description("3rd Target")]
        [GridCategory("Parameters")]
        public int Target3
        {
            get { return target3; }
            set { target3 = Math.Max(1, value); }
        }
		
        #endregion
    }
}

Follow me on Twitter Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
(login for full post details)
  #55 (permalink)
 
 
Posts: 929 since Oct 2012
Thanks: 678 given, 897 received


Big Mike View Post
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.

[Mike

I got the following Recursive Property error when I compiled the strategy (see code below):
Your strategy likely holds one or more recursive properties which could cause NinjaTrader to crash: EMAlength HMALENGTH TARGET1 TARGET2 TARGET3 BE2 BE3

Do you want to edit these properties?
I have attached the code I created. Please note I did not use the SMA. Can anyone please point out what I typed in wrong?

Thank you.


JLW

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Create a strategy with optimizable variables")]
public class testbmt : Strategy
{
private int emalength = 20;
private int hmalength = 10;

private int target1 = 12;
private int target2 = 10;
private int target3 = 18;

private int stop = 12;

private bool be2 = false;
private bool be3 = false;

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
}

private void GoLong();
(
SetStopLoss("target1", CalculationMode.Price, Close(0) - (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, Close(0) - (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price, Close(0) - (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2+Target3*TickSize));

EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
)

private void GoShort()
(
SetStopLoss("target1", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price,Close(0) + (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)

private void ManageOrders()
(
if (Position.MarketPosition == MarketPosition.Long)
(
if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)

if (Position.MarketPosition == MarketPosition.Short)
(
if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)
)
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

EMA emav = EMA(EMAlength);
HMA hmav = HMA(HMAlength);

ManageOrders();

if (Position.MarketPosition != MarketPosition.Flat) return;

if (Rising(emav) && Rising(hmav));
GoLong();
else if (Falling(emav) && Falling(hmav));
GoShort;
}

#region Properties
[Description("")]
[GridCategory("Parameters")]
public int EMAlength
{
get { return EMAlength; }
set { EMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int HMAlength
{
get { return HMAlength; }
set { HMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target1;
{
get { return target1; }
set { target1 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target2;
{
get { return target2; }
set { target2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target3;
{
get { return target3; }
set { target3 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Stop;
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be2;
{
get { return be2; }
set { be2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be3;
{
get { return be3; }
set { be2 = Math.Max(1, value); }
}
#endregion
}
}

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #56 (permalink)
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 181 since Aug 2009
Thanks: 103 given, 56 received


jlwade123 View Post
I got the following Recursive Property error when I compiled the strategy (see code below):
Your strategy likely holds one or more recursive properties which could cause NinjaTrader to crash: EMAlength HMALENGTH TARGET1 TARGET2 TARGET3 BE2 BE3

Do you want to edit these properties?
I have attached the code I created. Please note I did not use the SMA. Can anyone please point out what I typed in wrong?

Thank you.


JLW

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Create a strategy with optimizable variables")]
public class testbmt : Strategy
{
private int emalength = 20;
private int hmalength = 10;

private int target1 = 12;
private int target2 = 10;
private int target3 = 18;

private int stop = 12;

private bool be2 = false;
private bool be3 = false;

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
}

private void GoLong();
(
SetStopLoss("target1", CalculationMode.Price, Close(0) - (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, Close(0) - (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price, Close(0) - (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) + (Target1+Target2+Target3*TickSize));

EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
)

private void GoShort()
(
SetStopLoss("target1", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price,Close(0) + (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)

private void ManageOrders()
(
if (Position.MarketPosition == MarketPosition.Long)
(
if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)

if (Position.MarketPosition == MarketPosition.Short)
(
if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
SetStopLoss("target2", CalculatationMode.Price, Position.AvgPrice, false);

if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculatationMode.Price, Position.AvgPrice, false);
)
)
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;

EMA emav = EMA(EMAlength);
HMA hmav = HMA(HMAlength);

ManageOrders();

if (Position.MarketPosition != MarketPosition.Flat) return;

if (Rising(emav) && Rising(hmav));
GoLong();
else if (Falling(emav) && Falling(hmav));
GoShort;
}

#region Properties
[Description("")]
[GridCategory("Parameters")]
public int EMAlength
{
get { return EMAlength; }
set { EMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int HMAlength
{
get { return HMAlength; }
set { HMAlength = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target1;
{
get { return target1; }
set { target1 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target2;
{
get { return target2; }
set { target2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int target3;
{
get { return target3; }
set { target3 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Stop;
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be2;
{
get { return be2; }
set { be2 = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool be3;
{
get { return be3; }
set { be2 = Math.Max(1, value); }
}
#endregion
}
}

Hey JLW,

just to let you know, if you use

 
Code
  

//write code here
makes it look more readable.
It looks like you used () in places you should use {}

you wrote:

 
Code
private void GoShort()
(
SetStopLoss("target1", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price,Close(0) + (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

)
it should be:

 
Code
private void GoShort()
{
SetStopLoss("target1", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price,Close(0) + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price,Close(0) + (Stop*TickSize), false);

SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2*TickSize));
SetProfitTarget("target1", CalculationMode.Price, Close(0) - (Target1+Target2+Target3*TickSize));

EnterShort("target1");
EnterShort("target2");
EnterShort("target3");

}
This will probably give you a bunch of errors.
(....) are for functions and arguments
{....} is for blocks of code --- everything that goes inside of a method, class, namespace

Spencer

Follow me on Twitter Reply With Quote
The following user says Thank You to spinnybobo for this post:
 
(login for full post details)
  #57 (permalink)
Boston, Massachusetts
 
 
Posts: 7 since Mar 2013
Thanks: 1 given, 1 received

Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

Reply With Quote
 
(login for full post details)
  #58 (permalink)
Wiesbaden
 
 
Posts: 2 since Mar 2014
Thanks: 1 given, 0 received


Wazoo View Post
Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

I am not sure if those are the reasons Big Mike does it, but the following advantages come to my mind when running it on a Virtual Machine:
1. You can run a 2. instance of NinjaTrader
2. Assuming you are connecting to a demo account on your VM: Your testing of strategies etc. won't interfere with your live trading accounts (depending on how you test this could happen if you test it on your primary NT connected to your live accounts)
Hence: you completely keep your live trading and your research separated

Reply With Quote
 
(login for full post details)
  #59 (permalink)
 
 
Posts: 929 since Oct 2012
Thanks: 678 given, 897 received


Wazoo View Post
Big Mike

You mention in the video your running ninja on a virtual machine. Could you amplify on this. I guess more specifically
I am wondering if this gives some enhanced level of security for your code etc. From who, Ninja, Hackers etc.
and what virtual machine do you recommend?

Thanks
Jerry

I use Amazon S3 for free to house my Ninja data backup. I have been thinking increasing storage/memory from Amazon to use as a sandbox for my strategy development. Amazon is pretty cheap.

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #60 (permalink)
kansas city, ks
 
 
Posts: 17 since Jun 2014
Thanks: 0 given, 5 received

great video, thanks

Reply With Quote
 
(login for full post details)
  #61 (permalink)
NYC, NY, United States
 
 
Posts: 9 since Aug 2014
Thanks: 27 given, 1 received

I know it's late to reply but the virtual machine is for Linux. Ninja runs native on windows. To run it on Linux you a virtual machine or some workaround. Big Mike mentioned he had a Cron backup running and that's a Linux scheduled task.

Reply With Quote
 
(login for full post details)
  #62 (permalink)
rome - italy
 
 
Posts: 12 since Oct 2014
Thanks: 0 given, 0 received

It's possible to have this code to start ?

I'm a beginner and I'd like to input this on my Platform to improve ad see how it works.

Thank you





Big Mike View Post
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


Reply With Quote
 
(login for full post details)
  #63 (permalink)
las vegas
 
Experience: Beginner
Platform: ninja trader
Trading: es,tf
 
Posts: 7 since May 2014
Thanks: 2 given, 8 received

Hello Mike, kudos to you for the effort to sustain this forum over the years. I am a student of the trading game for 2 years now..anyhow, i have a question for you, what is the correct code to have 2 entires in ninja programming, , having them with 1 stop loss, and 2 different profit targets without trailing stops. I am trying to teach myself how to code my ideas correctly in order to backtest fast, because, although going through price bars 1 by 1 has it's benefits, i will grow BIG beard untill i complete 1-2 years of tests.

Reply With Quote
 
(login for full post details)
  #64 (permalink)
desert CA
 
Experience: Intermediate
Platform: NT7, SC, ToS
Broker: AMP, DT, TDA
Trading: CL,NQ,YM
 
Posts: 2,134 since Jul 2011
Thanks: 2,387 given, 1,723 received

MWinfrey has some strategies posted which show the code for multiple trade entries and stops.



Visit my futures io Trade Journal Reply With Quote
The following 3 users say Thank You to Cloudy for this post:
 
(login for full post details)
  #65 (permalink)
Newburyport, MA / USA
 
Experience: Advanced
Platform: NinjaTrader, TOS
Trading: CL, ES
 
Posts: 5 since Sep 2012
Thanks: 1 given, 1 received

The link to Mike's Video on Ninja Strategy is broken

Reply With Quote
 
(login for full post details)
  #66 (permalink)
Berlin Germany
 
 
Posts: 87 since Jul 2020
Thanks: 5 given, 72 received


afshinmoshrefi View Post
The link to Mike's Video on Ninja Strategy is broken

yes. I stumbled over this thread because I want to learn the basics for indicator/strategy development but the video is not there anymore. Any help appreciated. Thank you

Reply With Quote
 
(login for full post details)
  #67 (permalink)
Site Moderator
Sarasota FL
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
 
bobwest's Avatar
 
Posts: 6,358 since Jan 2013
Thanks: 48,487 given, 21,307 received


afshinmoshrefi View Post
The link to Mike's Video on Ninja Strategy is broken


patricia View Post
yes. I stumbled over this thread because I want to learn the basics for indicator/strategy development but the video is not there anymore. Any help appreciated. Thank you

Please note that this video was recorded in January 2010, so at best it applies to a very early version of NinjaTrader 7 -- I don't recall the relevant dates now, so perhaps NT 6.5 or earlier.

(I was just able to find a link on the NT support board dated Feb 25, 2010, stating "NT7 is currently in a closed beta. We are looking to do a public beta in the near future.")

Anything it contains will not be relevant to NT 8, which was extensively redesigned from the ground up, and probably not relevant to more current versions of NT 7 either.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to bobwest for this post:
 
(login for full post details)
  #68 (permalink)
Berlin Germany
 
 
Posts: 87 since Jul 2020
Thanks: 5 given, 72 received

thanks for clarifying

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy


Last Updated on October 23, 2020


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts