NexusFi: Find Your Edge


Home Menu

 





Close Open Position on Startup


Discussion in NinjaTrader

Updated
    1. trending_up 2,551 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,336

I asked NT support for help with this and they said what I'm trying to do isn't supported. So, I thought I would ask you all to see if anyone has an answer

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
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();
	}
}


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
TradingView Opens Volume Footprint Data to Pine Script - …
TradingView
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557



MWinfrey View Post
I asked NT support for help with this and they said what I'm trying to do isn't supported. So, I thought I would ask you all to see if anyone has an answer

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
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();
	}
}

Do you know why it disables the strategy?

If it is because of the close command, you might try just using a normal sell on the next bar or similar.

Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,336


Big Mike View Post
Do you know why it disables the strategy?

If it is because of the close command, you might try just using a normal sell on the next bar or similar.

Mike

yes the close command apparently disables the strategy same as pressing the close button on the chart trader closes the strategy. A normal sell or buy don't work as the positions are account positions not strategy positions. At least that's my suspicion because they don't work for sure. I've also tried synchronizing the strategy and account positions on startup of the strategy and can't get that working either.


Started this thread Reply With Quote




Last Updated on October 19, 2013


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts