Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting multi-instrument??!

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

    Backtesting multi-instrument??!

    I read in another thread that you can backtest multi instrument strategies.

    Unfortunately, I cannot get it to work. As soon as I compile a strategy that looks at two instruments, things get screwy in Strategy Analyzer.

    Let's pretend I have a multi instrument strategy called "multi" and I have a normal strategy called "buylowsellhigh"

    If I'm in Strategy Analyzer and backtest buylowsellhigh, everything works as expected. If I then grab "multi" from the backtest pulldown selection, it does not update the parameters. I mean, all the parameters I have from "buylowsellhigh" stick, even though the parameters in "multi" should be completely different.

    It's almost as if Analyzer is not updating. If I hit the Run Backtest button, it actually runs the previously selected (buylowsellhigh in this case) strategy. Basically, it is impossible to backtest "multi".

    ===

    Maybe something is strange with my code? This is my first try at using multi instruments. I've stripped down something I've been working on. This won't work on my end. Hopefully you can tell me why.


    Code:
    // sameColorTest
    // 
    //
    // DESCRIPTION:
    // 
    //
    // 
    // CHANGELOG:
    //    10/28/10    
    
    
    
    
    
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// 
        /// </summary>
        [Description("No name for this strategy yet.")]
        public class sameColorTest : Strategy
        {
            #region Variables
            
            
            private int     contracts = 1; 
            private bool    a_goLong = true;
            private bool    a_goShort = true;
            
            private int     _tradeTimeBegin = 630; // Default setting for TradeTimeBegin
            private int     _tradeTimeEnd = 1250; // Default setting for TradeTimeEnd
            private bool     addIndicators = true; // Default setting for AddIndicators
            
            private bool     condition1 = false;
            
            
            
            #endregion
    
            /// <summary>
            /// 
            /// </summary>
            protected override void Initialize()
            {    
                if (AddIndicators == true)
                {
    
                }
    
                CalculateOnBarClose = true;
                TraceOrders = false;
                Unmanaged = false;
                
                Add("DX", PeriodType.Minute, 1);    
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                    
                if (TimeToTrade)
                {
                    if (Position.MarketPosition == MarketPosition.Flat && condition1 == false)
                        LookForCondition1();
                    
                    if (Position.MarketPosition == MarketPosition.Flat && condition1 == true)
                        condition1 = false;
                }
                else FlattenPosition();
                
            }
            
            
    
            
                    
    
            private void LookForCondition1()
            {
    
                SetStopLoss("Long", CalculationMode.Price, 1, false);
                SetProfitTarget("Long", CalculationMode.Price, 10000);
                SetStopLoss("Short", CalculationMode.Price, 10000, false);
                SetProfitTarget("Short", CalculationMode.Price, 1);
                
                
                
                if (
                    Close[0] > Open[0]
                    && Closes[1][0] < Opens[1][0]
                    )
                {
                    EnterLong(contracts, "Long");
                    SetProfitTarget("Long", CalculationMode.Ticks, 1);
                    SetStopLoss("Long", CalculationMode.Price, Low[1], false);
                    condition1 = true;
                }
                
            }
            
            
            
        
    
            
            
    
            
            private void FlattenPosition()
            {
                if (Position.MarketPosition != MarketPosition.Flat)
                {
                    if (Position.MarketPosition == MarketPosition.Long)
                        ExitLong();
                    else if (Position.MarketPosition == MarketPosition.Short)
                        ExitShort();    
                } else
                {
                }
            }    
    
    
            
                
            private bool TimeToTrade 
            {
                get
                {
                    if (_tradeTimeBegin == 0 || _tradeTimeEnd == 0)
                        return true;
                    else
                    {
                        if (_tradeTimeBegin > _tradeTimeEnd)    
                            return ToTime(Time[0]) >= _tradeTimeBegin*100 || ToTime(Time[0]) <= _tradeTimeEnd*100;
                        else
                            return ToTime(Time[0]) >= _tradeTimeBegin*100 && ToTime(Time[0]) <= _tradeTimeEnd*100;
                    }
                }
            }
        
                                    
            
            
    
            #region Properties
            
            
            
            
            [Description("Go long ?")]
            [Category("Parameters")]
            public bool A_goLong
            {
                get { return a_goLong; }
                set { a_goLong = value; }
            }
            
    
        
            [Description("Go short")]
            [Category("Parameters")]
            public bool A_goShort
            {
                get { return a_goShort; }
                set { a_goShort = value; }
            }
        
            
            
            [Description("The time to begin trading in HHMM format.")]
            [Category("Parameters")]
            public int TradeTimeBegin
            {
                get { return _tradeTimeBegin; }
                set { _tradeTimeBegin = Math.Max(0, value); }
            }
            
            [Description("The time to end trading in HHMM format")]
            [Category("Parameters")]
            public int TradeTimeEnd
            {
                get { return _tradeTimeEnd; }
                set { _tradeTimeEnd = Math.Max(0, value); }
            }
            
            
    
            [Description("Add indicators to current chart?")]
            [Category("Parameters")]
            public bool AddIndicators
            {
                get { return addIndicators; }
                set { addIndicators = value; }
            }
            
            
    
            [Description("Number of contracts to trade.")]
            [Category("Parameters")]
            public int Contracts
            {
                get { return contracts; }
                set { contracts = Math.Max(1, value); }
            }
            
            
            
            
            #endregion
        }
    }

    #2
    Hello lookoutbelow,

    Please check the log tab of the control center for any error messages. It's likely there are errors calling that particular strategies Initialize() method.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello lookoutbelow,

      Please check the log tab of the control center for any error messages. It's likely there are errors calling that particular strategies Initialize() method.

      No error messages...

      note::, I can't even get this strat to run. It is not even selecting properly.

      Comment


        #4
        I think I figured it out. The instrument can't simply be "DX", it has to be "DX 12-10" or whatever the current one is. Would of been great to have gotten some sort of error message that something was wrong with my instrument selection.

        tx

        Comment


          #5
          You should see an error message in the log tab of the control center. This is what I get when trying to run your strategy.

          10/29/2010 10:40:59 AM Strategy The strategy 'AATest/13d95be822fd436db3b1d998f8fad731' has called the Add() method with an invalid instrument. Either 'DX' does not exist in the Instrument Manager or the specified exchange has not been configured.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_RyanM View Post
            You should see an error message in the log tab of the control center. This is what I get when trying to run your strategy.

            10/29/2010 10:40:59 AM Strategy The strategy 'AATest/13d95be822fd436db3b1d998f8fad731' has called the Add() method with an invalid instrument. Either 'DX' does not exist in the Instrument Manager or the specified exchange has not been configured.
            The point I was trying to make is that I was never able to even run the strategy to produce that error.

            If I leave it as "DX" (the wrong ID), the strategy cannot be run here on my end. It simply will not properly load when selected from the pulldown. It keeps whatever strategy was previously selected and is never updated to the multi instrument strat.

            Comment


              #7
              I see what you're saying and unfortunately there's no pop up error message in this case.

              If there's anything unexpected when running a strategy please check log tab.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              605 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              351 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              561 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X