Big Mike's Day Trading Forum

Go Back   Big Mike's Day Trading Forum > Trading Forums > Programmers Paradise > NinjaTrader Programming

Thread Statistics
Started:February 9th, 2010 (12:39 PM) by dsraider Views:5,129
Last Reply:August 4th, 2010 (03:59 PM) Replies:95

Reply
  10
 
LinkBack Thread Tools Search this Thread Display Modes

Sample Advanced Automated Strategy v1.0
Old February 9th, 2010, 12:39 PM   #1 (permalink)
Member
Trading Experience: Advanced
Trading Platform: NinjaTrader
Favorite Instrument: ES
 

Join Date: Dec 2009
Location: New York, NY
Posts: 128
Chats: 2
Thanks Given: 37
Thanks Received: 51

Points: 7,918, Level: 62
Points: 7,918, Level: 62 Points: 7,918, Level: 62 Points: 7,918, Level: 62
Forum Activity: 7%
Forum Activity: 7% Forum Activity: 7% Forum Activity: 7%
Sample Advanced Automated Strategy v1.0

People of the interweb,

With the help of several sample strategies I found on the NT forum and a little ingenuity, I have put together a fully-automated, advanced strategy which does the following:

1. Only enters between 10:15 AM and 3:15 PM (EST) (allows for second time frame as well)
2. Shuts down if PnL is more than $1,000 or less than -$300
3. Enters limit orders for long and short based on signal
4. Covers three time frames but will only have one active position open at a time
5. Cancels entry order if market moves four ticks away from limit order without filling
6. Sets an initial stop at 12 ticks, then changes to breakeven at +4 ticks and trails, tick by tick, from there
7. Scales out of half position at +4 ticks (1st profit target) and covers second half position at +8 ticks (2nd profit target)

Good news: All parameters can be changed to suit your needs. Please feel free to add to, delete or change anything in the code. All that I ask is that you don't sell my hard work for profit.

Bad news: As I have been coding C# for roughly 2.5 weeks, the contents of the strat pretty much consists of everything I know about coding. Therefore, if you want something drasticly changed, I will most likely not know how.

I am creating this thread so that we may all help to make it better, if need be, so please keep all comments and requests to this thread. As of now, the only thing with which I am not thrilled is the CancelOrder() code. It USUALLY works fine, but sometimes it surprises me. I am open to suggestions for how to make that, or any other part, better.

Click below for the strat. To install: Control Panel ---> File ---> Utilitites ---> Import Ninjascript...

Thanks and happy trading,
Dave

SampleAdvancedAutomatedStratv1.1

UPDATE:
v.1.1 - 2/23/10
1. Fixed CancelOrder() code.
2. Added arrows and chart name plots (since plots will only show on main chart, this lets you know which time frame just took the trade).

If you cannot see your full chart name once plotted: Right-click on chart ---> Properties ---> Right Side Margin


Last edited by dsraider; February 23rd, 2010 at 07:56 AM.
Reply With Quote
The following 21 users say Thank You to dsraider for this post:
     

Old February 9th, 2010, 12:39 PM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

Reply With Quote
     

Old February 11th, 2010, 12:25 PM   #3 (permalink)
Elite Member
Trading Experience: Intermediate
Trading Platform: Ninja
Favorite Instrument: TF,S,GC
 
cclsys's Avatar
 

Join Date: Nov 2009
Location: Sydney, NS
Posts: 605
Chats: 26
Thanks Given: 248
Thanks Received: 280

Points: 32,452, Level: 100
Points: 32,452, Level: 100 Points: 32,452, Level: 100 Points: 32,452, Level: 100
Forum Activity: 22%
Forum Activity: 22% Forum Activity: 22% Forum Activity: 22%


Thank you very much. Having sample strategies like this is extremely helpful for those who don't know all the ins and outs of NT strategy programming.

One feature I would like to see an example of is very simple but don't know how to do it: I like to make stops and PT's variable by reference to expanding/contracting ATR versus fixed tick sizes.

Now in theory I think all one has to do is have a tick size PT input (for example) but then multiply it by an ATR ratio.

If the short-term ATR is greater than longer term ATR, then if that is divided by the longer term you get a ratio (say 1.25), so the PT tick input can be multiplied by 1.25 to get the current PT amount. As I said, very simple in concept.

But how to do that within strategy coding I am not sure. Now that I have your template I can try (when I have time). Also there is the Hurley sample strategy here on the forum thanks to BM. But if any other expert would like to add that in, I am sure I am not the only person who would find it a very helpful snippet to have handy. Good for stops, profit targets, entry conditions etc.

More importantly, makes it possible to test the same strategy on different tick/time/instrument charts to find bell-curve ratios that work best rather than having to optimize each instrument and tick/time chart each time which creates over-optimization type problems with system design in general, but especially with intraday systems using short term data/bars.

Ideally (imho) all you need to optimize on a system should be
a) profit-to-loss ratio
b) volatility quotient applied to
c) stops and profit targets.

a) is a simple ratio which is a double expressing ratio of PT to stop (say), i.e. 2 = PT is 2*stop.
b) is the Stop in ticks (one input) with a second input which is the volatility multiplier (i.e. test from .5 to 2.5).

This means there are only 3 inputs to test: the P-L ratio, the volatility multiplier, and the base stop price in ticks.

If you want to get it down to only 2 inputs to optimize then the stop itself is a function of the volatility multiplier so that one multiplier optimizes the stops and PT's whilst the second input is the PT-Stop ratio which expands and contracts the PT relative to the initial stop price.

Having only two inputs to optimize on any given system makes for far more robust systems.

At least in theory!

PS: on looking at this noticed that most things are not inputs already so for myself I shall experiment with the Hurley since the times of day etc. are optimizable etc.

Of old the skilled first made themselves invincible to await the enemy's vincibility.
Invincibility lies in oneself. Vincibility lies in the enemy.
Thus the skilled can make themselves invincible.
They cannot cause the enemy's vincibility.
Thus it is said: 'Victory can be known; it cannot be made.'

Last edited by cclsys; February 11th, 2010 at 12:54 PM.
Reply With Quote
The following user says Thank You to cclsys for this post:
     

Old February 11th, 2010, 12:50 PM   #4 (permalink)
Member
Trading Experience: Advanced
Trading Platform: NinjaTrader
Favorite Instrument: ES
 

Join Date: Dec 2009
Location: New York, NY
Posts: 128
Chats: 2
Thanks Given: 37
Thanks Received: 51

Points: 7,918, Level: 62
Points: 7,918, Level: 62 Points: 7,918, Level: 62 Points: 7,918, Level: 62
Forum Activity: 7%
Forum Activity: 7% Forum Activity: 7% Forum Activity: 7%

cclsys,

First, thanks for your kind words. I'm a firm believer in giving back.

Second, I don't fully follow you but if you'd like to post a screenshot that helps me understand this in layman's terms, I'd be happy to give it a shot.

Thanks,
Dave

Reply With Quote
     

Old February 14th, 2010, 10:40 AM   #5 (permalink)
Elite Member
Trading Experience: Intermediate
Trading Platform: Ninja
Favorite Instrument: TF,S,GC
 
cclsys's Avatar
 

Join Date: Nov 2009
Location: Sydney, NS
Posts: 605
Chats: 26
Thanks Given: 248
Thanks Received: 280

Points: 32,452, Level: 100
Points: 32,452, Level: 100 Points: 32,452, Level: 100 Points: 32,452, Level: 100
Forum Activity: 22%
Forum Activity: 22% Forum Activity: 22% Forum Activity: 22%

Dsraider: cannot program NT strategies unfortunately so no screenshots. Just a thought. A little 'bee in my bonnet' with strategies that I think I have been harping on too much about past few days. Would just love to see a simple strategy with this capability. Had many in TS and always found it very helpful.

Of old the skilled first made themselves invincible to await the enemy's vincibility.
Invincibility lies in oneself. Vincibility lies in the enemy.
Thus the skilled can make themselves invincible.
They cannot cause the enemy's vincibility.
Thus it is said: 'Victory can be known; it cannot be made.'
Reply With Quote
     

Old February 15th, 2010, 01:35 AM   #6 (permalink)
Market Wizard
Trading Experience: Beginner
Trading Platform: NinjaTrader, TOS
 

Join Date: Jun 2009
Location: Asia
Posts: 488
Chats: 851
Thanks Given: 61
Thanks Received: 341

Points: 17,249, Level: 90
Points: 17,249, Level: 90 Points: 17,249, Level: 90 Points: 17,249, Level: 90
Forum Activity: 23%
Forum Activity: 23% Forum Activity: 23% Forum Activity: 23%

Don't know if it helps dsraider but I'm testing something now that uses a bool for trade times and session P&L. Whether the strategy looks at those can be switched on or off before you start the strategy.

In the variables area I have

private bool useTradeTimes = false;
private bool useSessionPnL = false;

And a bunch of user configurable parameters related to those two options.

Then in the OnBarUpdate area I have:

PHP Code:
if (UseSessionPnL == true && Position.MarketPosition == MarketPosition.Flat && (Performance.AllTrades.TradesPerformance.Currency.CumProfit priorTradesCumProfit >= sessionProfitTarget
|| Performance.AllTrades.TradesPerformance.Currency.CumProfit priorTradesCumProfit <= (-1*sessionLossLimit)))
PrintWithTimeStamp("STRATEGY Erratic NT7: " Instrument.FullName " HALTED by Session P&L Logic");
return;
 
if (
UseTradeTime==true && ToTime(Time[0]) <= tradeStartTime || ToTime(Time[0]) >= tradeEndTime) return; 
I've lifted your Trail Stop code and I'm testing it now. I note you are not using ExitLongStop and ExitLongLimit in your code and are instead using SetStopLoss and SetProfitTarget. Any reason for that? This is the first time I've really looked at IOrders.

Reply With Quote
The following user says Thank You to MXASJ for this post:
     

Old February 15th, 2010, 08:09 AM   #7 (permalink)
Member
Trading Experience: Advanced
Trading Platform: NinjaTrader
Favorite Instrument: ES
 

Join Date: Dec 2009
Location: New York, NY
Posts: 128
Chats: 2
Thanks Given: 37
Thanks Received: 51

Points: 7,918, Level: 62
Points: 7,918, Level: 62 Points: 7,918, Level: 62 Points: 7,918, Level: 62
Forum Activity: 7%
Forum Activity: 7% Forum Activity: 7% Forum Activity: 7%

cclsys - I actually meant a screenshot of your chart, only because I'm not familiar with that ATR formula. I was thinking that if I saw an example, I might be able to come up with a code snippet that does what you want (emphasis on MIGHT).

MXASJ - You're making me nervous. My time of day and PnL codes have been working perfectly for me. Did they not work for you? As far as using SetStopLoss/SetProfitTarget is concerned, as of now, I exit my trades solely based on how many ticks I want. I don't really have an actual exit strategy. If and when I do, I'll definitely use ExitLong at that point. Oh, for the trail to work properly, make sure you have CalculateOnBarClose set to false. This ensures that the "Close[0]" part of the trail means current price, so it will trail exactly how it's supposed to.

Thanks guys,
Dave

Reply With Quote
     

Old February 15th, 2010, 08:43 AM   #8 (permalink)
Market Wizard
Trading Experience: Beginner
Trading Platform: NinjaTrader, TOS
 

Join Date: Jun 2009
Location: Asia
Posts: 488
Chats: 851
Thanks Given: 61
Thanks Received: 341

Points: 17,249, Level: 90
Points: 17,249, Level: 90 Points: 17,249, Level: 90 Points: 17,249, Level: 90
Forum Activity: 23%
Forum Activity: 23% Forum Activity: 23% Forum Activity: 23%

Quoting dsraider: View Post
MXASJ - You're making me nervous. My time of day and PnL codes have been working perfectly for me. Did they not work for you?
If it works for you leave it alone . I like the option of being able to turn that on/off without commenting out the code, but that's just me.

Reply With Quote
     

Old February 15th, 2010, 08:57 AM   #9 (permalink)
Member
Trading Experience: Advanced
Trading Platform: NinjaTrader
Favorite Instrument: ES
 

Join Date: Dec 2009
Location: New York, NY
Posts: 128
Chats: 2
Thanks Given: 37
Thanks Received: 51

Points: 7,918, Level: 62
Points: 7,918, Level: 62 Points: 7,918, Level: 62 Points: 7,918, Level: 62
Forum Activity: 7%
Forum Activity: 7% Forum Activity: 7% Forum Activity: 7%

Ahh, okay. Just checking. I actually don't trust myself enough to have that power. I used to be really bad about revenge trading, etc, so this helps keep me from being my own worst enemy.

Hope your code works for you and thanks again for the suggestion. Let me know if you run into any issues with whatever you grab from mine. I'm STILL working on my CancelOrder code. Once that's done, I'll repost with a few other minor additions.

Dave

Reply With Quote
     

Old February 17th, 2010, 08:53 AM   #10 (permalink)
Market Wizard
Trading Experience: Beginner
Trading Platform: NinjaTrader, TOS
 

Join Date: Jun 2009
Location: Asia
Posts: 488
Chats: 851
Thanks Given: 61
Thanks Received: 341

Points: 17,249, Level: 90
Points: 17,249, Level: 90 Points: 17,249, Level: 90 Points: 17,249, Level: 90
Forum Activity: 23%
Forum Activity: 23% Forum Activity: 23% Forum Activity: 23%


Paying it forward, dsraider. My code is not as good as yours but you might get an idea or two out of it for further development (switching trade times and session P&L off, for example). Attached is NT7 only I'm afraid but here you go.

Attached Files
File Type: zip SimpleFramework.zip (2.1 KB, 65 views)
Reply With Quote
The following 6 users say Thank You to MXASJ for this post:
     
Reply

Tags
advice, atm, atr, automated, backtest, backtesting, bars, brokers, c#, chart, charts, chop, cl, code, cot, downloads, eco, ema, es, forex, historical, hurley, import, indicator, indicators, intraday, journal, line, market_replay, method, modify, multiple, newbie, news, ninja, ninjascript, ninjatrader, nt7, optimization, options, price_action, profitable, programming, renko, review, sim_trading, size, strategies, strategy, success, superdom, support, symbols, templates, tick, timeframe, tips, trade management, trader, trading, trailing stop, volume, wanted
     

Big Mike's Day Trading Forum > Trading Forums > Programmers Paradise > NinjaTrader Programming > Sample Advanced Automated Strategy v1.0

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike Beginners, Introductions and Tutorials 26 July 25th, 2010 06:22 PM
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike NinjaTrader Programming 0 January 26th, 2010 05:22 AM
Advanced Strategy Writing zeller4 NinjaTrader Programming 8 December 27th, 2009 11:21 PM
Call ATM Strategy on an automated strategy to control position jsengxx NinjaTrader Programming 1 November 16th, 2009 01:14 PM


All times are GMT -4. The time now is 05:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
vBulletin Optimisation by vB Optimise (Reduced on this page: MySQL 5.13%).
Copyright © 2010 by Big Mike Trading. All information is for educational use only and is not investment advice.
 
no new posts

Page generated in 0.32 seconds with 37 queries