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-18-2008, 10:04 AM   #1
Brian1
Member
 
Join Date: Feb 2008
Location: Overland Park, KS
Posts: 94
Thanks: 0
Thanked 0 times in 0 posts
Send a message via Skype™ to Brian1
Default How to Only Enter When Flat?

I have need test to see if my positions are Flat before entering a new "FullTrade". My scripted logic is to enter 3 uniquely named trades with 3 different targets and 3 stops. These are OCO, so the Full Stop cancels all. I call each of the 3 partial trades a "Leg" (e.g. Leg1, Leg2, Leg3).

My question is: In code, how can I avoid entering any additional "FullTrades" when I have a "FullTrade" position on?

My trades are entered in OnBarUpdate(). My targets and stops are adjusted in OnPositionUpdate().

In Initialize() I have:
EntriesPerDirection = 3;
EntryHandling = EntryHandling.AllEntries;

Most "FullTrades" work fine, but whenever one "Leg" has hit it's target, I can find myself entering a new trade if the conditions are right.

IPosition doesn't seem to be available in OnBarUpdate() and OnPositionUpdate is too late. Will I need to track this on my own with additional variables? (Hopefully not, but possible.)

What are your thoughts?

Brian
Brian1 is offline  
Reply With Quote
Old 04-18-2008, 10:15 AM   #2
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
Default

if (Position.MarketPosition == MarketPosition.Flat
&& .....

Not sure if that answers the question regarding your specific strategy but thats what I use in mine.
Elliott Wave is offline  
Reply With Quote
Old 04-18-2008, 10:17 AM   #3
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

Can you not just set some variables to signify a "state" and reset this to a "fresh" state once the position is flat which then signals you can take new "legs" ?
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-18-2008, 10:46 AM   #4
Brian1
Member
 
Join Date: Feb 2008
Location: Overland Park, KS
Posts: 94
Thanks: 0
Thanked 0 times in 0 posts
Send a message via Skype™ to Brian1
Default

Thanks for the quick response(s).

Elliot ... I do that too, but only in the OnPositionUpdate(). I wasn't able to get it to work when I first tried it in OnBarUpdate(). Compiled now, so it may be working now. Thanks very much.

Ray ... ya, that's what I was going to do, if nothing else. I might need to go ahead a set my own class up for my 3-legs in a "FullTrade" anyway. Thanks.

Much appreciated,

Brian
Brian1 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
Entering positions when not flat edward ATM Strategies (Discretionary Trading) 5 08-09-2007 02:21 PM
Flat a position on a market Respond SuperDOM and other Order Entry Windows 2 06-27-2007 08:51 AM
Problem with MarketPosition.Flat zoltran Strategy Development 3 04-10-2007 06:57 AM
P&L When Flat pivot44 Miscellaneous Support 0 02-20-2007 05:01 AM
MarketPosition.Flat compile error DarrylT Strategy Development 3 01-10-2007 05:49 AM


All times are GMT -6. The time now is 02:34 AM.