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 pibrew, Today, 06:37 AM
          0 responses
          0 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          12 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          10 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          15 views
          0 likes
          Last Post AaronKoRn  
          Working...
          X