Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How many open positions now
Collapse
X
-
Originally posted by alexstox View PostHello. How to check "how many open positions now"?
If you have multiple instruments in the same strategy, you can query their individual positions with the Positions array.
ref:
-
Position.Quantity is described as "Gets the current position size.".
Well, I need to know is entry order in market now or persist as order now. For example, I entered long via order and named it "enter 1". So, I need to check whether it in market as position OR whether it persist as order. I want to enter other long "enter 2". So, I think I should set condition "if strategy hold 1 enter" Or "if order still live or position still live". It's simple to check via "position.long" but this can contains more that 1 entry. So, how can I check whether the "enter 1" is live as order or live as position?Last edited by alexstox; 11-04-2013, 02:52 PM.
Comment
-
Originally posted by alexstox View PostPosition.Quantity is described as "Gets the current position size.".
Well, I need to know is entry order in market now or persist as order now. For example, I entered long via order and named it "enter 1". So, I need to check whether it in market as position OR whether it persist as order. I want to enter other long "enter 2". So, I think I should set condition "if strategy hold 1 enter" Or "if order still live or position still live". It's simple to check via "position.long" but this can contains more that 1 entry. So, how can I check whether the "enter 1" is live as order or live as position?
Comment
-
Hello Alex,
Thank you for your response.
You can use IOrder objects to track the orders in OnOrderUpdate() and check the order state to see if it is filled or not. For information on IOrder objects please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm
Please let me know if I may be of further assistance.
Comment
-
Thank you. I did so before.
There is only one private double that is used for enter - entryOrder. Let imagine, script entered and named this enter as "Long". Sometimes conditions for further enter comes true when "Long" still present as opened position. So, in that case I'd like to enter via entryOrder as "Long1". But before do this I need to check if "Long" still present. How to check entryOrder.Name for presenting as opened position?
Comment
-
Hello Alex,
Thank you for your response.
As there would only be the preceding one long then Position.MarketPosition == MarketPosition.Long will check if the current position is long.
For information on Position please visit the following link: http://www.ninjatrader.com/support/h...7/position.htm
Please let me know if I may be of further assistance.
Comment
-
Well. Thanks. But it's not solution! I think it could be few decisions.
First, by using Position.Quantity. Especially when use DefaultQuantity in entry orders. For example, if by default I enter with 1 contract, then quantity of contracts = number of entries (positions).
Second,
Code:..... private int PositionsQuantity = 0; //to calculate # of opened positions ..... protected override void OnExecution(IExecution execution) { if (entryOrder != null && entryOrder == execution.Order) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { PositionsQuantity = PositionsQuantity + 1; ...................... //than in OnExecution() check for exit order filling. and if filled, if (trailOrder != null && trailOrder == execution.Order) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { PositionsQuantity = PositionsQuantity - 1; }
Comment
-
Please comment is this correct?
Add later: this is bad idea! Because first or other entries could exits different way.
Add later: the QUESTION is
1. how to identify the position?! For example, if I entered with entryOrder.Name == "Long", so I have 1 long position that I can't identify. After entryOrder = null,position still present. But I enter second time entryOrder.Name == "Long1". And as earlier after order was filled, it reset to null. There are 2 positions. How to identify each of them?Last edited by alexstox; 11-07-2013, 06:40 AM.
Comment
-
Hello Alex,
Thank you for your response.
There is no identifier for the individual position, the positions are added or subtracted when the order is filled. The overall count for the Position can be viewed as Position.Quantity, checking this value will let you know if it has increased or decreased.
Please let me know if I may be of further assistance.
Comment
-
Hello Alex,
Thank you for your response.
You can use SetTrailStop() to trail the market: http://www.ninjatrader.com/support/h...ttrailstop.htm
Please let me know if I may be of further assistance.
Comment
-
Originally posted by NinjaTrader_PatrickH View PostHello Alex,
Thank you for your response.
You can use SetTrailStop() to trail the market: http://www.ninjatrader.com/support/h...ttrailstop.htm
Please let me know if I may be of further assistance.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by TheTradingMantis, 10-31-2017, 03:18 PM
|
5 responses
1,251 views
0 likes
|
Last Post
by TheAngryCube
Today, 04:06 PM
|
||
Started by Padan, Today, 02:02 AM
|
9 responses
23 views
0 likes
|
Last Post Today, 03:27 PM | ||
Started by spottysallrite, Today, 11:31 AM
|
7 responses
22 views
0 likes
|
Last Post Today, 03:26 PM | ||
Started by nandhumca, Today, 03:15 PM
|
1 response
4 views
0 likes
|
Last Post Today, 03:23 PM | ||
Started by PopovDS, 03-11-2024, 12:49 PM
|
3 responses
17 views
0 likes
|
Last Post
by PopovDS
Today, 03:16 PM
|
Comment