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

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.



    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        53 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        5 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        19 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        6 views
        0 likes
        Last Post cre8able  
        Working...
        X