![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
|
Dear friends.
I try to create strategy which can monitor positions from other instruments or opened manually. But I have a trouble with closing position. As I understand I can influence only at my strategy. If manually opened positions is Short with 5 lots, and my strategy opens Long position with 5 lots, I will not close first position. I have attached my strategy. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
|
I have attached screens from my terminal.
|
|
|
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello daglas,
If you open a position for 5 short manually and your strategy opens a position for 5 long, then overall your account position will be flat however your strategy position will be 5 long. You can use the below unsupported code to check on the overall account position. Code:
foreach (Position p in Account.Positions)
{
if (p.Instrument.FullName == Instrument.FullName)
{
//do stuff
}
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
|
Quote:
I have check this code, it has access only for position which are visible on Positions Tab. I can't get data about from my strategy with this code. I think I should you getpnl method in code of my strategy and compare it with positions available on Position tab. Also I have get some strange message about overfill orders. |
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello daglas,
Position.Quantity should give you the current position held by your strategy. http://www.ninjatrader.com/support/h...l?quantity.htm An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NT closing positions rules | entropy | Automated Trading | 2 | 06-20-2011 01:59 PM |
| Disable a strategy without closing positions | MicroTrends | Automated Trading | 3 | 02-07-2011 03:55 PM |
| Errors closing positions | marynja | Strategy Development | 1 | 01-29-2011 01:03 PM |
| What is the method called for closing positions? | tomiboi | Strategy Development | 1 | 12-14-2007 03:43 AM |
| Positions Closing Early | rmmsmh | Miscellaneous Support | 4 | 05-25-2005 05:15 AM |