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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-13-2012, 07:24 AM   #1
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default closing positions for other strategies

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.
Attached Files
File Type: zip closemaster.zip (2.3 KB, 3 views)
daglas is offline  
Reply With Quote
Old 07-13-2012, 07:32 AM   #2
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default

I have attached screens from my terminal.
Attached Images
File Type: png positions.png (38.8 KB, 2 views)
daglas is offline  
Reply With Quote
Old 07-13-2012, 07:42 AM   #3
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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
        }
}
I will leave the thread open for any forum member who can further assist you in this regard.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 07-13-2012, 10:30 AM   #4
daglas
Senior Member
 
Join Date: Mar 2011
Location: Ukraine
Posts: 146
Thanks: 19
Thanked 2 times in 2 posts
Default

Quote:
Originally Posted by NinjaTrader_Joydeep View Post
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
        }
}
I will leave the thread open for any forum member who can further assist you in this regard.
Many thanks for your help.
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.
Attached Images
File Type: png overfill message.png (11.4 KB, 4 views)
daglas is offline  
Reply With Quote
Old 07-13-2012, 11:01 AM   #5
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep 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
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


All times are GMT -6. The time now is 05:43 AM.