Announcement

Collapse
No announcement yet.

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.

    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.

        Comment


          #5
          This worked! thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          65 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X