NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 10-17-2007, 11:56 AM   #1
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default Make trail stop value update intra bar without indicator update.

Can I have my trail stop update on a tick by tick basis without making the indicators change on a tick by tick basis?

If so what would be the way to effect this with strategy builder or the code?

Thanks to anyone who can help...

dendy.
dendy is offline  
Reply With Quote
Old 10-17-2007, 12:30 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Yes you can by running with CalculateOnBarClose = false.

http://www.ninjatrader-support.com/H...BarClose1.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-17-2007, 03:37 PM   #3
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ray,

I honestly tried that but I had to shut down the connection and reload the Ninjascripts before it worked.

Is there any way to allow the trail stop to update intra bar and allow entries to happen only when a bar closes (and conditions are met).

Thanks again....

dendy.
dendy is offline  
Reply With Quote
Old 10-17-2007, 05:20 PM   #4
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Not exactly what you are looking for, but I add a 15 minute timeframe into my chart that runs on a 1 minute timeframe. The trailing stops adjust every minute but I take all my order entry signals off the 15 minute.
woodside is offline  
Reply With Quote
Old 10-17-2007, 07:23 PM   #5
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Woodside,

If you don't mind me asking, what is the script for doing this. I am testing a 5 min strategy on my IB connection and would like it to update the trailstop every 30 seconds to 1 min if possible. I originally wanted every tick but your solution also sounds very good!

Thanks for responding...

dendy.
dendy is offline  
Reply With Quote
Old 10-17-2007, 10:41 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Hi dendy,

The way SetTrailStop() is designed is it will work tick-by-tick and no other way. It does not care what you set CalculateOnBarClose to, it will run tick-by-tick. When you set CalculateOnBarClose to true it means your OnBarUpdate() method will only be executed once at the end of every bar. This means if you have your SetTrailStop() set inside the OnBarUpdate() method then you end up having its value set only when the once per bar at the end. This generally shouldn't be a problem if you call SetTrailStop() immediately after you call EnterLong() or EnterShort(). This caveat also does not mean your Trail Stop order is not working tick-by-tick. Once the order is submitted it will work tick-by-tick until you get stopped out.

Hope that clarifies your concerns about SetTrailStop().
For further information please review the documentation here: http://www.ninjatrader-support.com/H...TrailStop.html
There is also a reference sample that may be of value to you here: http://www.ninjatrader-support.com/v...ead.php?t=3222

In regards to adding a second time frame to your NinjaScript strategy you can review how to do it here: http://www.ninjatrader-support.com/H...struments.html
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-18-2007, 09:18 AM   #7
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Dendy,

I use a modified version of the sample multi timeframe strategy. My strategy runs in a 1 minute timeframe, then I add a 15 minute to the strategy, the use BarsArray[1] in all my indicators to determine entrys.

I found that when backtesting, the results are much more accurate with the trailing stops as the get updated every minute.


Josh, In my experience the trailing stops only get updated when the bar closes. Is this just because I'm running in simulation? When I run my strategy live with my broker account will it send an actual "trail stop" order to my broker which will then update it tick by tick? Broker is MB Trading which does support trailing stops natively.
woodside is offline  
Reply With Quote
Old 10-18-2007, 12:20 PM   #8
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Woodside and Josh,

I've been investigating the multi-time frame strategy and this is great stuff. I know it's old news to you. But I'll be trying to use this for the first time.

As you mentioned Josh, the trail stop is checked on a tick by tick but the value is not updated until the bar closes.

I will work on this.

Thanks to all.

dendy.
dendy is offline  
Reply With Quote
Old 10-18-2007, 01:25 PM   #9
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm still new at this also but I have a fair amount of programming experience.

I could never figure out why I couldn't get better performance using trailing stops then just fixed stops. When looking at past bars, ninja has no idea if a high came before or after a low so trailing stops never get updated on the same bar, and your target and/or your stop could get hit on the same bar. Using 1 minute bars seems to help as at least the stop gets updated once every minute.

If as Josh says they will get updated tick by tick when trading for real that this isn't an issue, but it sure helps when backtesting. My experience with trailing stops is they update at the close of a bar, and they are adjusted based on the high/low of the previous bar depending on if you are long/short.


-Erik
woodside is offline  
Reply With Quote
Old 10-18-2007, 02:40 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

For clarification.

SetTrailStop() will submit a stop loss order immediately on the opening of a position based on internal incoming fill events on an order. The adjustment of the stop loss price (the trailing stop) is adjusted on OnBarUpdate() events which either trigger on the close of a bar or on each tick depending on what your CalculateOnBarClose property is set to.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-19-2007, 07:54 AM   #11
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

I have an issue with trying to use a multi-time strategy to update my trail stop more often than my entry order.

I have a multi time frame and not a multi instrument strategy. According to the help file and confirmed by errors, you may only execute orders against the primary time frame. I cannot make the primary time frame 1 minute because I don't want to execute that many entries. Let's say I make the primary time frame 5 minutes, then my entries will run only on 5 min intervals (good). But the trail stop will also update only every 5 minutes unless I find a workable way to command the trail stop to update based on the bars that I add with the Add command. (As woodside said earlier, 1 min bars or so.)

Can anyone help with this?

Thanks again...
dendy is offline  
Reply With Quote
Old 10-19-2007, 08:42 AM   #12
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

NT 6.5 will allow you to place orders against all time frames which will solve your road block. We are within weeks of releasing public beta of this.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-19-2007, 08:48 AM   #13
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

NT 6.5 sounds like it's going to be a huge update...

Can't wait to see it.

Thanks for clearing that up for us,

dendy.
dendy is offline  
Reply With Quote
Old 10-19-2007, 10:18 AM   #14
woodside
Member
 
Join Date: Sep 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

You could use a counter to do this I think. Load your script on a 1 minute bar, add a 15 minute bar, initialize a counter at 0, then every bar increment it by one, when it hits 15 run your order entry conditions and reset the counter to 0. That way your stops would run every bar but the orders would only trigger every 15th bar.

-Erik
woodside is offline  
Reply With Quote
Old 10-19-2007, 12:04 PM   #15
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Woodside,

I'm trying to use the count command but all the help guide has to say about it is below. The Countif does not work on multi time frame strategies. I'm still trying to make the Count work. I'm slow because I don't know anything about programming.

Thanks...

Definition
The total number of bars or data points.


Property Value
An integer value representing the the total number of bars.


Syntax
Count


Property Of
Custom Indicator, Custom Strategy
dendy is offline  
Reply With Quote
Reply

Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Indicator: Drawing unique objects and objects that update NinjaTrader_Josh Reference Samples 0 09-24-2007 09:01 PM
NT charts won't update on one pc Futures_Shark Charting 12 06-13-2007 07:04 AM
Ninja Update Respond Miscellaneous Support 1 06-07-2007 11:32 PM
Update Problem Alfred Installation and Licensing 3 08-25-2006 12:51 AM
Does Ninja support update (trailing )stop every bar ? joesan Automated Trading 9 03-07-2006 12:05 PM


All times are GMT -6. The time now is 04:06 AM.