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

Rolling Over within a strategy

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

    Rolling Over within a strategy

    Hey,

    I started this question in this thread: https://ninjatrader.com/support/foru...70#post1176670
    And was advised to create a separate thread.

    I want to automate everything as much as possible, and, with swing trading micro E-mini futures, once in 3 months I would need to roll-over positions.
    My main struggle is with at the point of roll-over.

    According to rollover calendar (https://www.cmegroup.com/trading/equ...rolldates.html), next rollover date is 9th of December, 2021. So at this date I would want to exit any open positions and open all subsequent positions for next contract, in this case, MES 03-22 (until it rolls over at 10th of March, 2022).

    My idea around this is:
    Code:
    if (Bars.IsFirstBarOfSession && NextRollOverDate == Time[0].Date) // Where NextRollOverDate is DateTime variable, set to be Next Roll Over Date
    {
    ExitLong();
    ExitShort();
    NextRollOverDateCode = "03-22"; // MM-YY Code Of Next Contract
    CurrentSymbol = "MES " + NextRollOverDateCode; // Idea is to calculate the result of "MES 03-22", not sure if it's correct?
    }
    But then, how do I make a good use of CurrentSymbol variable in EnterLong() and EnterShort(), when, I suppose, a strategy uses instrument (and expiration) that is set in Strategies tab? How to override it? How can I determine correctly which futures contract to enter?
    Last edited by UltraNIX; 11-02-2021, 04:53 AM.

    #2
    Hi, thanks for posting.

    The contract being used by the strategy must be set manually through the user interface. There is no support for changing a contract month while a strategy is running. The strategy must be disabled, contract month changed, then re-enabled on the new contract.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I see. Ok.

      Comment


        #4
        I have a related question:

        What code should I use to determine:
        1) If instrument is Futures instrument (ES, NQ, etc.)
        2) If Futures rollover is monthly or quarterly?

        I want to code exit on rollover date in my strategy and was unable to extract rollover date from the indicator in Ecosystem. If you are able to do that - that could shorten the path.

        Comment


          #5
          Hi UltraNIX, thanks for the follow up.

          1. Instrument.MasterInstrument.InstrumentType == InstrumentType.Future can be used to determine a futures instrument

          2. You will need to calculate this using the Instrument.MasterInstrument.RolloverCollection object and check the frequency of rollovers.

          Our colleague Chelsea has made this Rollover Indicator for example:

          Shows a button on the chart to roll the expiry to the next available contract month. Option to hide button until a number of days before or on roll date. Another option to confirm by opening the instrument overlay selector or automatically rollover without confirmation. (Update June 27th, 2019 – Added an option to show […]


          Best regards,
          -ChrisL

          The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Yes, but I tried to call that indicator using Strategy Builder and it was not in the list, maybe it doesn't return any date values and is used for display purposes only (I loaded it on the chart - it displays data correctly). Maybe NinjaTrader_ChelseaB could edit the indicator, so I would be able to call it from the strategy?

            Comment


              #7
              Hi Chelsea, any chance that NinjaTrader would accept an enhancement request of volume based / back adjusted auto-rollover for a continuous contract data series? Sierra Charts does this really well which makes it pretty easy for back testing.

              Comment


                #8
                Hello,

                NinjaTrader 8 already uses the Merge Policy to combine previous contracts into the newest contract, so one can just use the newest futures contract when backtesting. itsthefriz If you would like to submit a feature request, please start a new thread.

                The indicator from Chelsea is not designed to be used in the strategy builder, it only displays the roll date as a WPF object. The InstrumentType property is not available in the builder either. The strategy builder was designed to make simple strategies using the conditions builder with indicators that implement Plots. The strategy will need to be written through the NinjaScript editor.

                Best regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  I will use it in strategy code, I just need a way to call it in the strategy from the indicator. And Strategy Builder is a good way, as adviced by NinjaTrader support here, to start and then unlock the code, in order to call indicator properly.

                  Comment


                    #10
                    Hi UltraNIX,

                    Strategies normally access indicators through their Plots, we also have an example here showing how to expose data that are not plots (like a String):



                    Best regards,
                    -ChrisL
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Can NinjaTrader_ChelseaB just add some lines of code in his indicator to store Value[0] and that way we could access it via strategy?

                      Comment


                        #12
                        Hi UltraNIX,

                        The samples we provide come as-is. The example I sent to you can be used to either add a plot to the indicator and store the rollover value on each bar or expose the string property so it can be accessed through a strategy.

                        Best regards,
                        -ChrisL
                        Chris L.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by frslvr, 04-11-2024, 07:26 AM
                        6 responses
                        105 views
                        1 like
                        Last Post NinjaTrader_BrandonH  
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        6 responses
                        26 views
                        0 likes
                        Last Post trilliantrader  
                        Started by arvidvanstaey, Yesterday, 02:19 PM
                        5 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Zachary  
                        Started by Rapine Heihei, Yesterday, 08:25 PM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by Mongo, Yesterday, 11:05 AM
                        6 responses
                        27 views
                        0 likes
                        Last Post Mongo
                        by Mongo
                         
                        Working...
                        X