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
Find open positions on another account or Instrument in the same account
Collapse
X
-
Find open positions on another account or Instrument in the same account
I have created a multiple account/instrument strategy . The main chart that has the strategy is the controlling one. So my issue is when the order closes in the main chart ie NQ, and I have an open order that may still be open on ES or NQ on another account. Once the primary NQ closes I need to determine if the other instrument and or account has any open positions. What is the best code to ascertain the other accounts/instruments for open positions .One check to see if a particular account had any open positions and a second request if a certain instrument had a position openTags: None
-
Hello set2win,
Thanks for your post.
You could use <Account>.Positions to check what the market position is for a specific account.
See this help guide page for more information and sample code: https://ninjatrader.com/support/help...ns_account.htm
<Account>.Orders could be used to get a collection of orders on a specific account.
See this help guide page: https://ninjatrader.com/support/help...rs_account.htm
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
-
not having any luck with this. using the code example for Positions I get an error OnStateChange object referenced not set to instance of an object.
else if(State==State.DataLoaded)
{
// Find our Sim101 account
lock (Account.All)
Account1 = Account.All.FirstOrDefault(a => a.Name == account1);
Account2 = Account.All.FirstOrDefault(a => a.Name == account2);
/// When adding this section I get the error:
lock (Account1.Positions)
{
foreach (Position position in Account1.Positions)
{
Print(String.Format("Position: {0} at{1}", position.MarketPosition,position.AveragePrice));
}
}
The main issue is to note when the main strategy no longer has open positions to go ahead and run a Close procedure for the open trades in other account or Instrument. So maybe a bool that notes when state has changed. so when order is placed and the state would be not flat. then when the state changes to flat then it would fire the procedure to close the other orders in other account or instrument
Comment
-
Found a problem in the naming of the account, which seems to have cured that object not referenced issue, but still not sure how to accomplish the task of determining the status of when the
main strategy has no positions then checking for positions in other account
[TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
public string AccountName { get; set; }
Comment
-
Hello set2win,
Thanks for your note.
You could look at the account's overall position and not a position for a specific strategy. The accounts have a positions collection to find open positions and this would be the total position for the account.
It is not suggested to try and link two strategies as you are doing. There would be no way to know if one strategy or another strategy has a position from the positions collection. You would need to create one strategy that opens and closes all positions. Or, you could use indicators and reference the account position directly.
The code you shared in post # 3 would be what you would need to use to get the overall position of an account.
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by strategist007, Today, 07:51 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,967 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
6 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
Comment