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

How to exit position from a different Bars/DataSeries than the entry was placed on?

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

    How to exit position from a different Bars/DataSeries than the entry was placed on?

    Is it possible to exit a position that was placed on the primary bar series (BarsInProgress == 0) from a secondary bar series that was added via AddDataSeries (so BarsInProgress == 1) and have the order executed on that secondary bar instead of waiting for the next primary bar?

    For example, say I have a primary data series of 80 minutes, where I enter a position based on some entry criteria. I then want to exit that position from a 30 minute bar series and have that exit happen at the specific 30 minute bar, not wait for the next 80 minute bar. I have tried using barsInProgressIndex of ExitLong/ExitShort set to 0 in OnBarUpdate of BarsInProgress == 1, however that order still doesn't get executed until the next BarsInProgress == 0 happens. I am debugging this running a strategy backtest.​
    Last edited by andrewnavratil; 03-22-2024, 12:19 PM.

    #2
    Hello andrewnavratil,

    Welcome to the NinjaTrader forums!

    "Is it possible to exit a position that was placed on the primary bar series (BarsInProgress == 0) from a secondary bar series that was added via AddDataSeries (so BarsInProgress == 1) and have the order executed on that secondary bar instead of waiting for the next primary bar?"

    Yes, you can place orders to any series added to the script.

    Specify the BarsInProgress Index for the series you want the order placed to, in the order method parameters.

    ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)


    ExitLong(1, 1, "myExit", "myEntry"); // this would be placed to BarsInProgress index 1

    Do this when BarsInProgress is 1 in OnBarUpdate() when the added 30 minute series is updating.





    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, that worked. However, it is not exiting until the next 30min bar close in this example from when the ExitLong is submitted, instead of immediately executing on the current bar. I was able to set the time 30 minutes earlier to get the execution at the proper time though. Is that also expected?

      Comment


        #4
        Hello andrewnavratil,

        This would be expected.


        If you wanted the orders to appear on the same bar, these would need to be submitted before the bar closes with Calculate.OnEachTick or .OnPriceChange.
        In historical this would also require TickReplay and 1-tick intra-bar granularity.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok, thanks. I checked my entries again and they are happening on the open of the next bar after EnterLong is called on a bar close of the primary series, essentially immediately. Does EnterLong get executed on a bar open and ExitLong executed on a bar close, is that how it works? Or is the fact that a secondary bar series is being used for exit order entries causing the different flow here?

          I have another strategy that uses tick based bars, and I did not seem to run into this issue, both entries and exits occurred immediately, but they were both happening on the primary data series.

          Comment


            #6
            Hello andrewnavratil,

            Any market order submitted after a bar close will be filled on the open of the next bar of the series it is submitted to. This applies to entry orders and exit orders. This applies to all bar types.

            If an exit is submitted on a secondary series after the secondary series bar closes, it will appear on the open of the next secondary bar.

            Orders being filled on the same bar as the condition bar, are being submitted intra-bar.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ageeholdings, Today, 07:43 AM
            0 responses
            5 views
            0 likes
            Last Post ageeholdings  
            Started by pibrew, Today, 06:37 AM
            0 responses
            4 views
            0 likes
            Last Post pibrew
            by pibrew
             
            Started by rbeckmann05, Yesterday, 06:48 PM
            1 response
            14 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
            12 views
            0 likes
            Last Post burtoninlondon  
            Working...
            X