NinjaTrader Support Forum  

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 12-07-2007, 04:36 PM   #1
Burga1
Senior Member
 
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
Default ID for different open conditions?

Hi,

Is it possible to use a command that can identify unique "open" positions within a strategy that can possibly open mulitple trades? For example if I have a strategy that has 3 possible conditions that may initiate a trade...is it possible to identify which conditions are "open" at the current time--Such as:

"Condition 1 is Long"
"Condition 2 is Flat"
"Condition 3 is Short"...

Could a command like "Position.AvgPrice" do this? I know about commands like "Position.MarketPosition" but I believe they will take into consideration all conditions. I know each condition can be given a unique name upon triggering a trade, I just would like to be able to "track" what conditions are "active" an those that are not...thank you in advance.
Burga1 is offline  
Reply With Quote
Old 12-07-2007, 10:54 PM   #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

You can probably run your own variable through your conditions to determine the theoretical states of all your orders. When condition 1 becomes long set the variable to 1. If its flat set your variable to 0. If it is short set it to -1. When you call the variable just check the value against the proper value state. Hope that helps.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-08-2007, 08:43 AM   #3
Burga1
Senior Member
 
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi,

Thanks for your post. I think I understand but that leads me back to my original question--in order to do so how do I use the " Position.MarketPosition" command(s) for EACH condition within the strategy?

In other words I'd need to do something like:

"if(Position.MarketPosition[condition #1] ==
MarketPosition.Long){set variable or do something...}"

I was under the impression that the "Position.MarketPosition" command takes ALL conditions into consideration, so for example in a strategy with 4 possible conditions if 1 of those conditions is "long" then "MarketPosition.Long" would be set to "true"...despite the fact that the other 3 positions are flat. I hope that makes sense...
Burga1 is offline  
Reply With Quote
Old 12-08-2007, 01:29 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

No. You need to realize you only have ONE position at a time. If you get filled short on one order and then get filled long on another. You are no longer short on condition 1 and long on condition 2. You are just simply long since entering long from a short is a reversal order that will first close out your short position before acquiring the long position.

If condition1 generates a long order and you get filled, MarketPosition becomes long. When condition2 generates a short and condition1 is "long", MarketPosition becomes short because that is what you have now; a short position.

Going back to my suggestion. You want to run a variable through the condition to determine what your theoretical state of the different conditions would be.

So for example.
Code:
if (Close[0] > Close[1])
{
     EnterLong("Condition1");
     condition1State = 1;
}
if (Close[0] < Close[1])
{
     ExitLong("Condition1 Exit", "Condition1");
     condition1State = 0;
}
if (condition1State == 1)
     Print("Condition1 is Long");
else if (condition1State == 0)
     Print("Condition1 is Flat");
Now this is not perfect logic because of potential issues that might happen. For instance, you might only get partial fills or you might get rejected orders. To address this you can use Position.MarketPosition and Position.Quantity. Check the state and value of those two before submitting an order. Store the info. Run through the check again and see if the MarketPosition reflects the correct direction and if Quantity reflects the proper amount.

So if you were Short before Condition1, your initial check will tell you MarketPosition = Short and Quantity=100 (or whatever). In your secondary check you will see MarketPosition is now Long and Quantity is 100. This is correct position we should be in so we know everything is correct. If our quantity is less than 100 we know we have a partial fill. If our MarketPosition is still short we know our order was rejected or something happened to it. Does this make sense?

All in all, MarketPosition is relevant for your OVERALL position. If you want to differentiate between different condition's positions you will need to manually do it.
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
Next Bar Open bradypreston General Programming 17 01-14-2011 10:12 AM
Checking for cross over conditions and generating an alert NinjaTrader_Ray Indicator Development 23 09-25-2010 12:23 PM
Different take profit exit conditions creztor General Programming 7 01-16-2008 11:36 AM
Open Tick - Kuberr Connecting 2 06-18-2007 02:29 PM
Can't open NT Antraman Installation and Licensing 4 10-11-2005 08:10 PM


All times are GMT -6. The time now is 10:37 PM.