Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy did not close a position after overnight

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

    Strategy did not close a position after overnight

    I am testing a strategy in a sim account. Yesterday the strategy entered a long position. This morning, based on the strategy it should have exited this long position but did not do so.

    If it makes any difference I made some code changes to the strategy last night.

    Today I am running the strategy against 5 instruments including the one it entered the position on yesterday. However in the strategies window once started the strategy it did not show any of the information for this instrument like position,avg price etc. I'm new to using the strategies but expected I would have seen this informtion as I had an open position.

    Where should I be looking?

    Using 6.5

    Thanks,

    David

    #2
    David, as first step when testing and working with NS strategies, please ensure the strategy vs account position in sync as needed - http://www.ninjatrader-support.com/H...tPosition.html

    Next, it would be helpful to add print statements or visual confirmations to your strategy code, this way you would know if a condition indeed evaluated to true or not -



    Also as you started up the strategy, was ExitOnClose for example activated? This would mean there would be no historical position to exit, as it was closed at the session end time you've setup in the Chart Properties.

    Comment


      #3
      No, ExitOnClose was not selected, either yesterday or this morning when I started the strategy.

      Since I opened NT this morning, my positions tab shows I'm long 150 units, the same 150 units the strategy entered into yesterday. When I started the strategy this morning on the same instrument, the strategy does not show that there is any position at all. Let me explicitly ask this time, should the strategy be showing the position from the previous day when I open it the next morning? I've never done this before so while I expected that it should have, I don't know for sure.

      So to get them in sync, according to the link you gave me, are you saying that I have to enter another long position in addition to the one I've already entered? Not particulary useful if I want to hold a position over night.

      Comment


        #4
        David, which order types are you using? If you don't go with market orders you could get a different fill (no fill here) as you restart the strategy and it cycles again through it historical fill processing and calculations, then the trade could have triggered realtime, but might not show up in a backtest.



        If the strategy and account positions are in sync at restart, there would be need to sync the account position up.

        Comment


          #5
          I'm using EnterLong and ExitLong, which as I understand are market orders.

          So let me ask again, if the account and strategy are sychronized at startup, then I should see the position in the strategies tab for the applicable strategy/instrument, as well as on the positions tab?




          Comment


            #6
            Thanks for clarifying - yes if both are in sync you would see the strategies tab position being reflected by the account position you're holding. Likely this was really influenced by the coding changes you did, so as you started a new strategy instance it would not trigger the long yesterday to be held overnight.

            Comment


              #7
              OK, so for now we will assume that the account and the strategy got out of sync due to me making some code changes last night.

              Not sure what this might mean but I thought this was Interesting. When I went into positions and told NT to flatten the position, the strategy for the same instrument stopped running ...

              So, if this happens to me again in the future, is there no way to force the strategy to recognize the existing position?

              Comment


                #8
                Yes, closing position here will also stop the strategy. To keep the strategy running you would have to place the corresponding closing order manually. (Can't use Close or Flatten Everything)

                There's no way to state what the strategy position is. The NinjaScript strategy is run on each historical bar for the 1st hour of the session (it will actually run on all historical data loaded in a chart) to determine the current position state it would be in if it had been running live since the start of the session.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Yes ... I read through some other related threads that I found.

                  But, if the account and strategy were out of sync why would flattening the position that the strategy was not in sync with cause the strategy to stop running? Seems odd to me.

                  And would it be more correct to say the strategy is run on historical bars unless I have
                  if (Historical)
                  return;
                  just after onbarupdate? Which I do have btw ...

                  So is a possible answer to somehow tell the strategy how many bars to look back to get it back in sync with the account?

                  Comment


                    #10
                    Close in this context operates similarly to the close button on the superdom.

                    Clicking on the "CLOSE" button with your left mouse button will close the current position and cancel any working orders associated to the instrument/account combination.

                    More info on closing a position or strategy here.

                    Yes, if you have that statement then the strategy will not run against Historical data.

                    There's no way to explicitly declare the strategy position. If you're only running it on real time data then the position state at the time of starting the strategy should be flat.
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    650 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    577 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X