Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Autoclose Positions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Autoclose Positions

    I would like to setup my system to automatically close any open positions and cancel any unfilled target orders within 15min of so of market close. The safety stop and target limits are set by ATM.

    I go to tools -> options -> trading -> and see the auto close position, but it's requiring me to put a set time. Some markets close at 1PM PST, some at 2PM PST and some at 11AM pst.

    Click image for larger version

Name:	image.png
Views:	230
Size:	8.2 KB
ID:	1290500

    Is there a way to specify 30 min before session close (like in a strategy?).

    or ... even better ...

    Is there a way to manually enter the market with an ATM placing the target and safety stop but have a strategy detect the entry and the ATM stop and make adjustments to the atm stop as well as exit 30min before close?

    #2
    Hello,

    The auto close feature must be set to a certain time and this will apply to all markets/positions in your account. For a more granular system that only closes certain instruments at certain times you would need to program this into an automated strategy.

    Comment


      #3
      Originally posted by NinjaTrader_RyanS View Post
      Hello,

      The auto close feature must be set to a certain time and this will apply to all markets/positions in your account. For a more granular system that only closes certain instruments at certain times you would need to program this into an automated strategy.
      So, I ran a test to see if a manual entry can be detected in a strategy. I used the following code ..

      Click image for larger version  Name:	image.png Views:	0 Size:	21.3 KB ID:	1290681

      I manually entered the market, and the ATM strategy correctly applied my target and safety stop.

      Click image for larger version  Name:	image.png Views:	0 Size:	77.7 KB ID:	1290682

      With the code above, I was hoping to see the results of the print statement in my output window, but this is all my output window showed....

      Click image for larger version  Name:	image.png Views:	0 Size:	59.8 KB ID:	1290684

      The strategy was ran BEFORE the order was placed.

      Upon my first target getting filled, I received no update in the output window.

      Click image for larger version  Name:	image.png Views:	0 Size:	73.1 KB ID:	1290685

      It appears my strategy can't see the manual activity. So, it appears that the only way my strategy can see the order is if the initial entry into the market was performed within the strategy? Is this correct?

      In order for me to make a strategy to exit the market and close any unfilled orders 30min before the market closes for multiple markets with varying close times, I will need to be able to see the actual manually entered position in the strategy. Is there a place, other than OnOrderUpdate override within the strategy that I can accomplish this?

      ​​​
      Attached Files

      Comment


        #4
        I think you can have NinjaScript pull up any open orders/positions, regardless if they were placed manually or by strategy. For example:

        Code:
        NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
                    account = chartTraderAccountSelector.SelectedAccount;
        
        foreach(Order o in account.Orders)
                        {
                            //Print(o.OrderType + " " + o.Name);
                            if (o.Name.StartsWith("Stop1") && (o.OrderState == OrderState.Accepted || o.OrderState == OrderState.Working))
                            {
        
                            }            
                        }​
        I've used the above for creating custom auto trials for stop losses, and you can probably modify it to get open positions by looking at account.Positions or something like that

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        75 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        45 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        26 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        62 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X