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!
See more
See less

Partner 728x90

Collapse

Automated Strategies, Failed Exits and Getting Strategies Back to Flat

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

    Automated Strategies, Failed Exits and Getting Strategies Back to Flat

    My automated strategy is designed to make trades from 9 am CST to 2:30 pm CST. All open positions are forced to exit at 3:12 pm CST, and this done in the code and not through “Exit on Session Close”. On Friday, my EMD position failed to exit at 3:12. All my entries and exits are market orders, not limit orders. I run both live money account and a Sim 101 account against the same Strategy, and neither market order exit got filled at 3:12.

    (1) How do market orders NOT get filled? I know that the spread is wider on the EMD and the volume is a lot lower than say the ES or NQ. Is that a factor even for market orders?

    When the market resumed at 3:30 pm CST, I manually exited the EMD SHORT position on both the live trading account and the SIM. I thought that took care of those positions, but when I restarted the Strategy this morning, it was not flat, and it was as if the position was still SHORT, and it was accruing Realized PnL. Usually, I run the Strategy as “Wait Until Flat” but when I saw this, I restarted the Strategy and tried “Immediately Submit” and “Immediately Submit, Synchronize Account” - those made the Strategy flat, but the position was open and accruing PnL again. Again, I manually exited it again.

    Today, the Strategy entered Long, first a buy to cover from the previous Short on Friday that failed to exit, and a Long from normal logic of the Strategy.

    (2) I am assuming that when I manually exited the position on Friday, that action was outside the Strategy and that’s why when it was restarted, it started not flat, and the position opened again?

    (3) How do I manually exit positions and make sure they are closed and not reopened when I restart the Strategies later on in time? I’ve always been confused with Start Behaviors. I need to make sure my Strategy knows it should be flat when a manual exit occurs outside its normal trading range.

    #2
    Hello szayedoud,

    If an order is not filled it may have been rejected or ignored.
    If the order was not rejected or ignored, the session may been closed, or the connection may have been temporarily lost and the transmission did not go through.

    The log in NinjaTrader would specifics on what happened with the order and/or connection from your end. Your broker would have more information about what happened to the order after the broker received it.

    Manual orders, or any orders that are not submitted by the strategy instance, cannot be seen by the strategy. These orders would affect the account but not the strategy, causing the strategy and account to become out of sync.


    The strategy when enabled, will process historical data. The position when this is complete will be whatever was calculated in that historical data.

    To prevent a historical position from submitting live working orders, you would need to use the wait until flat start behavior. Using immediately submit will submit any working historical orders that are still working and are not matched.

    For the strategy to be flat, that has done with code. The strategy code must exit the strategy position.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I had something similar happen today. My 2L EMD position did not exit at 3:12. After 3:30, I selected "Flatten Everything" on the Positions tab which closed everything, and disabled the Strategy. When I enabled the Strategy soon after, it was green, flat with no positions. It's possible when I manually exited on Friday, I chose "Close Position" instead of "Flatten Everything". It sounds like "Flatten Everything" is reflected in the Strategy while "Close Position" would not. Is that right?

      Comment


        #4
        Hello szayedoud,

        This would mean the strategy logic re-calculated a flat position in the historical data when enabled.

        Flatten everything will close all positions, cancel all working orders, and all disable all enabled NinjaScript Strategies.

        The strategy will be disabled. It will re-calculate a position from processing the historical data when enabled. No previous orders will prevent the strategy from calculating a historical position.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          it sounds like "Flatten Everything" is the best way to manually exit positions when the strategy is unable to for whatever reason.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:10 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          5 responses
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X