Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open positions either after strategy closed or not controlled by strategy

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

    Open positions either after strategy closed or not controlled by strategy

    Hi,

    I'm developing an unmanaged order strategy. I'm currently putting it through stress testing to identify issues that still need to be resolved or addressed. I've come across an issue where there is an open real order either after I close my strategy or seemingly not controlled by the current instance of the strategy, i.e. lingering from the previous session. I haven't figured out yet what might be causing this, e.g. overfill, order was live when strategy terminated for an error (e.g. out of range index, etc. still cleaning up some of these). My question is what is a robust way to handle this? Should I for instance check Position.MarketPosition during OnStateChange State == State.Terminated and call ExitLong or ExitShort if position is not flat, or is it too late by then?

    Related to this, what is the most accurate way to tell the realtime market position from within the strategy? I've been logging Position.MarketPosition during OnBarUpdate and it didn't show that this order was still open from before the new invocation of the strategy, i.e. it was reporting Flat. Should I use PositionAccout.MarketPosition instead? What is the difference between the two and when should I use one vs. the other?

    Thanks.

    #2
    Hello silverm3170,

    My question is what is a robust way to handle this? Should I for instance check Position.MarketPosition during OnStateChange State == State.Terminated and call ExitLong or ExitShort if position is not flat, or is it too late by then?
    I would need to know more about the specific situation to provide a specific solution here. Depending on the reason the position was left open would determine how you solve that.

    what is the most accurate way to tell the realtime market position from within the strategy?
    Position.MarketPosition would be what is generally used. If the strategy was disabled and re enabled or had an error it would no longer observe that position unless its logic re enters into that position again after starting again. The PositionAccount is what the actual account position is and not the strategy position. That is infrequently used for advanced cases. More than likely it would be best to try and address the reason the strategy left the position rather than trying to find out if it left one open.



    Comment


      #3
      Hi Jesse, thanks for the quick response. It looks like it's happening when I terminate the strategy while a realtime position is still open, either by 1) right-click, select the strategy and uncheck the Enable button, or 2) uncheck Enable in the Control Panel Strategy tab. I just did this and noticed the Control Panel Positions tab still showed the position as being active after the strategy closed. I had assumed this action would automatically exit any open position.

      Comment


        #4
        Hello silverm3170,

        Thanks for the update.

        Yes if you manually stop the strategy you would need to close the position at that point if you want to start completely flat the next time around. The position is open because that exists on the account is and not something which is open like an order that can be cancelled. A position needs to be exited or to remain in place depending on the goal.

        You can also look at using the start behavior ,deepening on the logic used it may be able to be resumed using one of the start behaviors that syncs wit the account.



        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X