if (this.Account.Positions.Count > 0) { for (int count = 0;count<this.Account.Positions.Count;count++) { position = this.Account.Positions[count]; openposition = this.Account.Positions[count].MarketPosition; avgprice = this.Account.Positions[count].AvgPrice; if (openposition != MarketPosition.Flat) position.Close(); } }
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
Close Open Positions
Collapse
X
-
Close Open Positions
When enabling my strategy I want to test for open positions in my account and close them without disabling the strategy. I'm using the following code which closes the open positions but it also disables the strategy.
Code:Tags: None
-
-
If you're are open to play in the unsupported territories further, then this might be very helpful for your task - http://www.ninjatrader.com/support/f...2&postcount=33BertrandNinjaTrader Customer Service
Comment
-
-
-
Originally posted by koganam View PostWhy not either:
- Close each position by issuing an Exit() order? or
- Close all but the last position using what you have now, then close the last position with an Exit() order?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bill2023, Yesterday, 08:21 AM
|
2 responses
14 views
0 likes
|
Last Post
by bill2023
Today, 01:04 AM
|
||
Started by ynoldsany, Today, 01:00 AM
|
0 responses
2 views
0 likes
|
Last Post
by ynoldsany
Today, 01:00 AM
|
||
Started by Carolscogginsi, Yesterday, 10:45 PM
|
0 responses
7 views
0 likes
|
Last Post Yesterday, 10:45 PM | ||
Started by RaddiFX, Yesterday, 10:15 AM
|
2 responses
15 views
0 likes
|
Last Post
by RaddiFX
Yesterday, 09:33 PM
|
||
Started by patrickmlee007, Yesterday, 09:33 AM
|
2 responses
19 views
0 likes
|
Last Post Yesterday, 08:56 PM |
Comment