Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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...
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
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.'
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.
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.'
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.
And a bunch of user configurable parameters related to those two options.
Then in the OnBarUpdate area I have:
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.
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.
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.
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.