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

Exit Strategy Position before Transition

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

    Exit Strategy Position before Transition

    I've got a strategy that is semi automated with buttons on the chart. I want to see the historical performance, so it trades during historical processing. But I want the strategy to go flat before the transition to realtime.

    I've tried exiting the position when State == Transition, but get the error message: "'SubmitOrderUnmanaged' method can't be called while strategy is in state 'Transition'."

    What would be the correct way to make the strategy go flat before the transition to realtime?

    #2
    Hello kevinenergy,

    Thank you for your post.

    You could set your strategy to exit any open position on the last historical bar before the strategy transitions to State.Realtime. You may identify the last historical bar as follows:

    Code:
    if (State == State.Historical && CurrentBar == Count - 2)
    {
    if (Position.MarketPosition != MarketPosition.Flat)
    // SubmitOrderUnamanaged() to exit with an orderAction of Sell or BuyToCover Market order for the quantity of the open position and also CancelOrder() as needed for any working orders
    }​
    This should suit your needs so that you still get historical performance, and the strategy will also be flat once it reaches State.Realtime.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      How do I know whether any given bar in the sequence of BarUpdates is the last historical bar?

      Comment


        #4
        Hello kevinenergy,

        Thank you for your reply.

        The last historical bar is identified with the condition I provided:
        if (State == State.Historical && CurrentBar == Count - 2)

        When that condition is true, then it means OnBarUpdate() is being called on the last historical bar on the chart.

        For more information regarding Count and CurrentBar, please see the help guide pages below:Please feel free to reach out with any additional questions or concerns.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          This worked! thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by llanqui, Today, 08:32 AM
          1 response
          5 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by lollers, Yesterday, 03:26 AM
          1 response
          52 views
          0 likes
          Last Post lollers
          by lollers
           
          Started by Salahinho99, 05-05-2024, 04:13 AM
          7 responses
          61 views
          0 likes
          Last Post Salahinho99  
          Started by knighty6508, 05-10-2024, 01:20 AM
          4 responses
          29 views
          0 likes
          Last Post knighty6508  
          Started by OllieFeraher, 05-09-2024, 11:14 AM
          6 responses
          19 views
          0 likes
          Last Post OllieFeraher  
          Working...
          X