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 DTSSTS, Today, 06:53 AM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Jim  
          Started by lightsun47, Yesterday, 07:17 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChristopherS  
          Started by ezrollin, Yesterday, 10:38 PM
          3 responses
          7 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by janio973, Today, 04:17 AM
          0 responses
          16 views
          0 likes
          Last Post janio973  
          Started by awa485, Yesterday, 05:08 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Working...
          X