Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multiple order state management

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

    multiple order state management

    I'm a bit lost on how to properly account for my open/closed/stopped out positions.

    I am backtesting on 1min historic data, with CalculateOnBarClose = true.

    My strategy generates multiple signals which I store in an ArrayList of IOrder objects.

    All of my signals are of the type EnterLongStop() or EnterShortStop().
    They all have a unique name (timestamp).

    Each entry is preceded by a SetStopLoss() for the same unique name order name.

    With this logic, my orders get filled and my stop-losses work just fine.

    I cancel any OrderState = "Working" or OrderState = "Accepted" orders if they remain unfilled for more than three hours. This sets their OrderState to "Cancelled".

    I'm stuck trying to identify the remaining orders that are not stopped out. The OrderState shows "Filled" regardless of whether the order is stopped out or not.

    I thought about changing my logic to use ExitLongStop() and ExitShortStop() methods instead of SetStopLoss() and also pushing the returned IOrder objects into my ArrayList.

    But then I have to program around waiting for the orders to be filled (might not be on the next 1min bar) before I can apply stops to them.
    I would need to keep track of which stop price to apply to which entry order and then iterate over the ArrayList twice and try to join up the Stops with the Entries, which feels messy.

    I'm pretty sure I'm making this more complicated than it needs to be.

    Can anyone point me in the right direction?

    Summary:
    1. Backtesting OnBarClose
    2. Multiple uniquely named entries, with a single unique stop per entry
    3. Need to cancel old/unfilled orders, and handle orders being stopped out
    4. Need to identify as time progresses which orders are still alive so that I can apply different take-profit logic to each trade individually.

    I need the take profit rules to remain open-ended, as this is my focus of my development.


    Thanks very much,
    Kel.

    #2
    You will definitely want to use explicit exits that actually have IOrder objects instead of Set() methods for your stops. To determine if you stopped out is then a matter of accessing your IOrder for the stop order. You cannot check the IOrder of the entry order because when the entry is filled the state is Filled and that means it is terminal. There is nothing left for that IOrder to do.

    You will need to monitor for executions coming off of your entry order and apply the necessary stop orders accordingly based off of that information.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Ah, I see.

      I'm looking into OnExecution() now and realise that is where I should be working my stops.

      Thank you for the help, much appreciated.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X