Big Mike's Trading Forum
 

Go Back   Big Mike's Trading Forum

> Trading Forums > Platforms and Indicators > NinjaTrader > NinjaTrader Programming


Notices
     

Sample Advanced Automated Strategy v1.0
Started:February 9th, 2010 (12:39 PM) by dsraider Views / Replies:19,926 / 117
Last Reply:November 16th, 2011 (01:57 PM) Attachments:15

Welcome to Big Mike's Trading Forum.

Welcome, Guest!

This forum was established to help traders by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

BMT is fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


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, and we will never resell your private information.

-- Big Mike
     

Reply
 15  
 
Thread Tools Search this Thread

Sample Advanced Automated Strategy v1.0

Old February 9th, 2010, 12:39 PM   #1 (permalink)
Trading for Fun
New York, NY
 
Trading Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Instrument: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 79 received

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
     

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

Thanks for the Strategy.... being new to NT I am struggling with how to program a strategy and incorporate an ATM, etc. I will dig into it tonight...

I am guessing that this is for the ES? Is it chart timeframe dependent (tick vs 1,5,10min). DOes it use your pc clock? What time zone should I be set on, or can it be adjusted with starttime?

Thanks a lot...
Bob


Last edited by bobc635; February 7th, 2011 at 12:19 PM. Reason: Simple Questions for author about strategy
     

Old February 11th, 2010, 12:25 PM   #3 (permalink)
Elite Member
Sydney, NS
 
Trading Experience: Intermediate
Platform: Ninja
Broker/Data: Zen-Fire
Favorite Instrument: TF,S,GC
 
cclsys's Avatar
 
Posts: 607 since Nov 2009
Thanks: 248 given, 348 received


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)
Trading for Fun
New York, NY
 
Trading Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Instrument: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 79 received

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
Sydney, NS
 
Trading Experience: Intermediate
Platform: Ninja
Broker/Data: Zen-Fire
Favorite Instrument: TF,S,GC
 
cclsys's Avatar
 
Posts: 607 since Nov 2009
Thanks: 248 given, 348 received

Current BMT User Poll

Should sim traders that pretend to trade cash be allowed on BMT?

 
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)
Elite Member
Asia
 
Trading Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 731 received

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:

 
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)
Trading for Fun
New York, NY
 
Trading Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Instrument: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 79 received

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)
Elite Member
Asia
 
Trading Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 731 received


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)
Trading for Fun
New York, NY
 
Trading Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Instrument: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 79 received

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)
Elite Member
Asia
 
Trading Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 731 received


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
Register to download File Type: zip SimpleFramework.zip (2.1 KB, 248 views)
Reply With Quote
     
The following 8 users say Thank You to MXASJ for this post:
     

Reply



Tags
account, accounts, accurate, amp, analysis, atm, atr, automated, automated strategy, automation, autotrader, backtest, backtesting, bars, bat, big mike, bot, broker, brokers, c#, ces, challenge, change, chart, chart trader, charts, charttrader, chop, cl, close, code, coding, color, combine, compile, condition, contracts, control, convert, corporate, cot, create, currency, daily, data, data provider, day, demo, desktop, development, discretionary, dow, downloads, eco, ema, enter, entriesperdirection, entry, error, errors, es, execution, exit, feed, file, fill, fills, forex, formula, forward testing, free, function, futures, greater than, greene, group, high, historical, how to, hurley, import, indicator, indicators, initialize(), instrument, instruments, intraday, journal, learn, learning, limit, limit orders, line, live, living, load, lot, love, low, management, margin, market, market replay, market_replay, master, mc, medianrenko, method, mind, ml, mode, modify, moves, multiple, names, need help, newbie, news, ninja, ninjascript, ninjatrader, note, nt, nt help, nt7, object, open, optimization, option, options, order, order entry, orders, override, paid, parameters, performance, period, positions, price, price_action, profit, profit target, profitable, program, programmer, programming, proprietary, purpose, puts, question, range, range chart, reliable, renko, renko chart, replay, research, reverse, review, right-click, rules, runner, sample, save, script, scripts, searching, series, session, setstoploss, settings, short term, signal, signals, sim, simple, simulation, sim_trading, small, sound, start, startegy, stocks, stop, stop loss, stoploss, stops, strategies, strategy, strategy development, strategy programming, superdom, support, symbols, system, systems, t1, ta, targets, template, terms, testing, thank you, tick, ticks, time, time frames, timeframe, trade, trade management, trader, trades, trading, trailing, trailing stop, type, update, variable, volatility, volume, ym, zone
     

Big Mike's Trading Forum > Trading Forums > Platforms and Indicators > NinjaTrader > NinjaTrader Programming > Sample Advanced Automated Strategy v1.0

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike NinjaTrader 57 April 10th, 2014 09:25 AM
VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy Big Mike MultiCharts 22 March 25th, 2014 03:54 PM
End of day sample strategy mrticks The Elite Circle 9 February 18th, 2011 06:37 AM
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


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

Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
Copyright © 2014 by Big Mike Trading. 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

Page generated 2014-04-16 in 0.23 seconds with 20 queries on phoenix via your IP 54.198.34.238