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 04-11-2008, 04:31 PM   #1
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default Managing the order of trades

I am still learning but managed to put a system together that is showing potential.

If certain conditions are met I enter long with EnterLongStop and short with EnterShortstop

If the system was long and the condition to go short was met - the long trade would be closed and a short trade entered automatically

After reading what I could find in the help file I then added SetTrailStop(CalculationMode.Ticks, 80); to the initialize method.

Now all trades are exited only with trailstops.

What do I need to do so that a trade may be exited by a trailstop OR a trade in the opposite direction?
verge is offline  
Reply With Quote
Old 04-12-2008, 12:13 AM   #2
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

Using that line should not prevent you from reversing with an opposite directioned order. You most likely are hitting the stops before you reach the reversal condition. You can verify this for yourself by setting a ridiculously large stop that should theoretically never be triggered. When you do this you should see that your orders are still reversing as expected.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-12-2008, 05:44 AM   #3
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default unfortunately does not work

Quote:
Originally Posted by Josh View Post
Using that line should not prevent you from reversing with an opposite directioned order. You most likely are hitting the stops before you reach the reversal condition. You can verify this for yourself by setting a ridiculously large stop that should theoretically never be triggered. When you do this you should see that your orders are still reversing as expected.
Josh

Thanks for the reply

I have done what you suggested. Made it 800 ticks wide. Number of trades reduced from 171 to 4 - all was only exited by trailstop - none by reversal in direction.

To make sure I commented the trailstop line out - system then generated 171 trades again.

Regards
verge is offline  
Reply With Quote
Old 04-12-2008, 01:23 PM   #4
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

Okay verge. Thanks for the information. Would you mind posting a simple as possible strategy that demonstrates the issue you are experiencing so I can play around with it?
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-13-2008, 03:06 PM   #5
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default It works in a simple strategy

Quote:
Originally Posted by Josh View Post
Okay verge. Thanks for the information. Would you mind posting a simple as possible strategy that demonstrates the issue you are experiencing so I can play around with it?
Josh

I thought about what I could do with the least effort to do what you ask - so I inserted the following line in to a copied version of the SimplaMAcrossOver strategy that comes with NT. The line was SetTrailStop(CalculationMode.Ticks, 500);

I then ran the strategy - and it work the way it should - when a trade was entered in the opposite direction the system executed - and did not wait for a trailingstop.

So now I still don't know what I am doing wrong in my own strategy. (could it have something to do with the curly braces - when comparing the two strategies that is about the only thing I can see that differ (except for the conditions themselves of course) . My own strategy has more curly braces.

The simple one is below:

protected override void Initialize()
{
SMA(Fast).Plots[0].Pen.Color = Color.Orange;
SMA(Slow).Plots[0].Pen.Color = Color.Green;

Add(SMA(Fast));
Add(SMA(Slow));

CalculateOnBarClose = true;
SetTrailStop(CalculationMode.Ticks, 500);
}

/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLong();
else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort();
}
verge is offline  
Reply With Quote
Old 04-13-2008, 03:13 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

Since it worked in the simple case we know the architecture is fine. That means some debugging on your strategy will need to be done to locate what is messing your strategy up. Please try debugging as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
http://www.ninjatrader-support.com/v...ead.php?t=3627
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-14-2008, 12:44 AM   #7
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default It seems to happen because I used EnterLongStop

Quote:
Originally Posted by Josh View Post
Since it worked in the simple case we know the architecture is fine. That means some debugging on your strategy will need to be done to locate what is messing your strategy up. Please try debugging as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
http://www.ninjatrader-support.com/v...ead.php?t=3627
There is another difference between my strategy and the simple one I realised now is that the simple one use EnterLong while mine used EnterLongStop (and same for short)

I could not find any documentation describing the interaction between SetTrailStop and using a stop order. Can you point me to a section that describes how they work together please?

When I changed the order type from EnterLong Stop to EnterLong the SetTrailStop did not prevent a trade in the opposite direction anymore. The problem is that I want to use stop orders and trailstops - and have trade reversals
verge is offline  
Reply With Quote
Old 04-14-2008, 02:07 AM   #8
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

Please see this article on order rules: http://www.ninjatrader-support.com/H...verview36.html
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-14-2008, 12:12 PM   #9
Sidhartha
Senior Member
 
Join Date: Mar 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Josh,

I have to say I seemed to be confused about something similar to Verge. And I've studied all the relevant sections I can find on your on-line guide.

My strategy is working fine... I enter named positions using EnterLong() or EnterShort(). I place stops dynamically using ExitLongStop() or ExitShortStop() - obviously tied to the entries by name. All working.

However, I am looking to add another form of exit... which is effectively a reversal into a position in the opposite direction.

If I am currently long 1 contract and my position is named "MyLong"... and I have a working stop attached to that named long position called "MyLongStop"... If I now get a signal to go short, how do I exit my long and short one contract and get all the names right...? i.e. exiting the long called "MyLong" and entering a 1 contract short called "MyShort"...??


Do I have to use ExitLong() first and then on the next line call EnterShort() - named "MyShort"...???

Many Thanks
Last edited by Sidhartha; 04-14-2008 at 01:24 PM.
Sidhartha is offline  
Reply With Quote
Old 04-14-2008, 01:36 PM   #10
Sidhartha
Senior Member
 
Join Date: Mar 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

Guys... not sure if you've seen this post since I didn't post a new thread. Any thoughts...?
Sidhartha is offline  
Reply With Quote
Old 04-14-2008, 01:43 PM   #11
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

Since you have been working with Josh, he will respond later on this evening.
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-14-2008, 01:46 PM   #12
Sidhartha
Senior Member
 
Join Date: Mar 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ray.
Sidhartha is offline  
Reply With Quote
Old 04-15-2008, 01:44 AM   #13
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 Sidhartha,

You could try just submitting the EnterShort() order directly. You may need to cancel your ExitLongLimit() order first depending on how you have it setup (see the Internal Order Handling Rules article in my previous post). Bear in mind if you are using market orders (EnterShort and EnterLong) you don't need to worry about the IOHRs.

Alternatively you can go with the approach you outlined. Just ExitLong() and then do an EnterShort and name it however you want.

If you can outline the exact methodology of orders you wish to place I can advise you on that case scenario. It is difficult to talk in generalities due to the order handling rules.
Last edited by NinjaTrader_Josh; 04-15-2008 at 02:06 AM.
NinjaTrader_Josh 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
Manually managing auto strategy latkinso Strategy Development 1 12-19-2007 11:03 AM
Managing partially filled limit orders EvolveK Automated Trading 1 10-30-2007 11:17 AM
Managing NinjaScript Strategies with ATM daven Suggestions And Feedback 1 09-25-2007 04:05 PM
Managing Plots for Strategy vs Presentation whitmark Strategy Development 3 06-14-2007 07:25 AM
Managing positions bermuda Miscellaneous Support 1 05-01-2005 09:23 AM


All times are GMT -6. The time now is 05:35 AM.