![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Nov 2007
Posts: 388
Thanks: 0
Thanked 0 times in 0 posts
|
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... |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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");
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.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |