Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading Term Structure of Futures for NT8

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

    Trading Term Structure of Futures for NT8

    Hi,

    I uploded several years of different futures contracts in NT8 database as you explained on the website. It looks that like they get automatically merged into a continuos contract while I would like to keep them separated in order to trade a Calendar Spread (and backtest). So, is there any way to trade contracts that are not the front month with NT8 (keep track of the term structure)?
    In any case, how do I query the name of the front contract (or the contract that I am currently looking at) in ninja trader script so that I can send the correct order?

    thank you very much
    Marco



    #2
    Hello marcobar975, thanks for your post and welcome to the NinjaTrader forum.

    In NinjaTrader 8 the merge policy is used to merge contracts together. In a strategy, there is no order entry method that takes a specific contract e.g. EnterLong(); submits a market order to whatever instrument the strategy is enabled upon. If you do a backtest on your strategy, you can use the current contract and NinjaTrader will merge the previous contracts together and perform historical trades without needing to pinpoint a specific expiry.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      thank you for your reply that was helpful. So, therefore , at the current state there is no possibility to backtest or trade a calentar strategy where you buy and sell at the same time two different contracts of the same product.
      Is that correct?

      best
      Marco

      Comment


        #4
        Hello Marco, thanks for your reply.

        I tested using August and September oil and it made trades on both, so it is technically possible:

        Code:
        public class TestCalendarStrat : Strategy
            {
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"Enter the description for your new custom Strategy here.";
                        Name                                        = "TestCalendarStrat";
                        Calculate                                    = Calculate.OnBarClose;
                        EntriesPerDirection                            = 2;
                        EntryHandling                                = EntryHandling.AllEntries;
                        IsExitOnSessionCloseStrategy                = true;
                        ExitOnSessionCloseSeconds                    = 30;
                        IsFillLimitOnTouch                            = false;
                        MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                        OrderFillResolution                            = OrderFillResolution.Standard;
                        Slippage                                    = 0;
                        StartBehavior                                = StartBehavior.WaitUntilFlat;
                        TimeInForce                                    = TimeInForce.Gtc;
                        TraceOrders                                    = false;
                        RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                        StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                        BarsRequiredToTrade                            = 0;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration    = true;
                    }
                    else if (State == State.Configure)
                    {
                        AddDataSeries("CL 09-20", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                    }
                }
        
                bool doonce0 = false;
                bool doonce1 = false;
        
                protected override void OnBarUpdate()
                {
                    if(CurrentBar < 10) return;
        
                    if(BarsInProgress == 0)
                    {
                        if(!doonce0)
                        {
                            EnterLong(0, 1, "Entry0");
                            doonce0 = true;
                        }
                    }
        
                    if(BarsInProgress == 1)
                    {
                        if(!doonce1)
                        {
                            EnterLong(1, 1, "Entry1");
                            doonce1 = true;
                        }
                    }
                }
        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much Chris,
          your example is very useful, I will try that.

          Best
          Marco

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, 04-19-2024, 09:40 AM
          8 responses
          53 views
          0 likes
          Last Post alifarahani  
          Started by mmckinnm, Today, 01:34 PM
          2 responses
          5 views
          0 likes
          Last Post mmckinnm  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          3 responses
          60 views
          0 likes
          Last Post NinjaTrader_SeanH  
          Started by f.saeidi, Today, 01:32 PM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by traderqz, Today, 12:06 AM
          9 responses
          16 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X