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

Instrument.Expiry for added instruments

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

    Instrument.Expiry for added instruments

    I've added a few futures in the initialize section and want to use the Instrument.Expiry function. Do I just say Instrument[1].Expiry? or Instrument.Expiry[1]?

    Thanks a lot!

    #2
    Hello and welcome to the forums.

    It is not supported to dynamically Add() instruments within Initialize(). It is recommended to hard code the expiry dates for these instruments as using dynamic input can lead to unexpected errors since Initialize() can be called other times than when just starting the strategy/indicator.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by jean9114 View Post
      I've added a few futures in the initialize section and want to use the Instrument.Expiry function. Do I just say Instrument[1].Expiry? or Instrument.Expiry[1]?

      Thanks a lot!
      Instruments[1].Expiry

      Comment


        #4
        Thanks Lance. I know that, but my plan was to add all the futures in the Initialize section, then I would use the Instrument.expiry,in the OnBarUpdate, function to figure out which futures to trade. Sorry I wasn't clear about that.

        Thanks koganam! I'll try that out.

        Comment


          #5
          But the Expiry gives you only the month not the day. So how do you intend to use it?

          Comment


            #6
            Ah that's unfortunate. I guess I'll manually create an array with the expiry dates in the same order as I add the futures. That way array[3] would be the expiry date for Closes[3], for example. I just didn't wan't to have to do it manually, but that's fine.

            I have two completely different questions too. How do I make my strategy work only at 3:45pm? And let's say I want to close a position and open a new one right afterwards, how do I make it wait until the closing order has passed?

            Comment


              #7
              Originally posted by jean9114 View Post
              I have two completely different questions too. How do I make my strategy work only at 3:45pm? And let's say I want to close a position and open a new one right afterwards, how do I make it wait until the closing order has passed?
              You can do this with a time filter

              Example
              Code:
              if(ToTime(Time[0]) == ToTime(15, 45, 0))
              {
                //do something
              }




              The use of OnOrderUpdate/OnExecution should be helpful for the second part in checking order states
              The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


              Please let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #8
                Thanks a lot! That'll definitely work.

                One more question, how would I backtest a futures strategy? In the Initialize section, I added the futures for the next 2 years, but when backtesting, these won't change. Should I do a Monte Carlo simulation instead or add the old futures and run the backtest normally? Can it run the backtest even though the futures have actually expired already? Might be easier to just run the Monte Carlo simulation.

                Comment


                  #9
                  Hello,

                  You can backtest over previous contracts using the most current contract depending on your merge settings.

                  For example. If you wanted to backtest the past year of the ES, you could run the backtest on the ES 06-13 contract but make it merge in the previous contracts.

                  The different merge settings are defined in the last section here: http://www.ninjatrader.com/support/h...rical_data.htm

                  To change go to tools -> options -> data tab: http://www.ninjatrader.com/support/h...l?data_tab.htm

                  It's up to you whether or not you use the Monte Carlo Analysis.
                  LanceNinjaTrader Customer Service

                  Comment


                    #10
                    How can I find the number of day between lets say, the 1st of May and the 1st of June?

                    With the ToDay function, I get integers, which gives me a difference of 100 instead of 31.

                    Comment


                      #11
                      You can use DateTime subtractions to find this.

                      An example can be found here: http://msdn.microsoft.com/en-us/library/8ysw4sby.aspx

                      For all the DateTime methods: http://msdn.microsoft.com/en-us/libr....datetime.aspx

                      Let me know if I can be of further assistance.
                      LanceNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by jean9114 View Post
                        How can I find the number of day between lets say, the 1st of May and the 1st of June?

                        With the ToDay function, I get integers, which gives me a difference of 100 instead of 31.
                        Lookup DateTime and TimeSpan. You use the TotalDays property of the TimeSpan value that you get from subtracting the DateTime values that represent the dates in which you are interested.

                        Comment


                          #13
                          If I want to go short futures, am I supposed to EnterLong with a negative number of shares or EnterShort with a positive number?

                          Comment


                            #14
                            You would want to EnterShort

                            You can also use the simulation data feed to test you strategy functionality and logic.


                            I often find this useful for debuggin/testing purposes before the backtesting stage.
                            LanceNinjaTrader Customer Service

                            Comment


                              #15
                              Ok great! If i'm short 500 futures and want to go long 500 instead, do I have to closeshort 500 and enterlong 500 or can I enterlong 1000 instead?

                              I know that for equity you need to close first, but I'm quite new to futures. The difference between the two is that you can't sell your futures contracts, that's why I'm wondering if I can simply go long 1000.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by MSerag, Yesterday, 11:52 PM
                              3 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by dcriador, Yesterday, 01:43 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by James650, Today, 08:25 AM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Rogers101, 05-05-2024, 11:30 AM
                              14 responses
                              40 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by ETFVoyageur, 04-30-2024, 06:05 PM
                              11 responses
                              80 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X