Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Second Dataseries price and indicators in backtest

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

    Plotting Second Dataseries price and indicators in backtest

    I'm attempting to get a strategy working that will execute trades on the CME Index Futures RTH session while using a second dataseries on SPY to produce trade signals.

    How do I display the data for the second dataseries in the strategy analyzer instead of the primary dataseries?

    Here is a simplified version showing my most recent attempt to get this to work.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.Indicators.BCM_Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public class MultiMulti : Strategy
    	{
    		private SMA sma;
            private MACD macd;
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Multi";
    				Name										= "MultiMulti";
    				Calculate									= Calculate.OnBarClose;
                    IsOverlay                                   = true;
    				IsExitOnSessionCloseStrategy				= false;
    				TraceOrders									= false;
    				BarsRequiredToTrade							= 200;
    				IsInstantiatedOnEachOptimizationIteration	= false;
    
                    AddPlot(Brushes.DarkCyan, "SMA");
                    AddPlot(Brushes.Orchid, "MACD");
    			}
    			else if (State == State.Configure)
    			{
                    AddDataSeries("SPY", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "US Equities RTH");
                }
                else if (State == State.DataLoaded) {
    
                    sma = SMA(BarsArray[1], 200);
                    AddChartIndicator(sma);
                    sma.Plots[0].Width = 2;
                    sma.IsOverlay = true;
                    sma.Panel = 1;
    
                    macd = MACD(BarsArray[1], 4, 18, 2);
                    AddChartIndicator(macd);
                    macd.DrawOnPricePanel = false;
                    macd.IsOverlay = false;
                    macd.Panel = 2;
    
    				ClearOutputWindow();
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade)
    				return;
    
                if (BarsInProgress == 1)
                {
                    Values[0][0] = sma[0];
                    Values[1][0] = macd[0];
    
                    if (macd[0] > 0)
                        EnterLong(0, 1, "B" + CurrentBar);
                    else if (macd[0] < 0)
                        EnterShort(0, 1, "S" + CurrentBar);
                }
    		}
    	}
    }
    Last edited by RandyT; 08-24-2018, 02:05 PM.

    #2
    Hello RandyT,

    Thanks for your post.

    Only the primary data series will be charted and we would not be able to render our own bars because there would be a different amount of bars/slots between the two data series.

    If you would like to have SPY charted, I recommend using that as the primary data series and to use the other data series you wish to submit orders to as the secondary series.

    If there is anything else we can do to help, please let us know.
    Last edited by NinjaTrader_Jim; 08-24-2018, 03:47 PM.

    Comment


      #3
      Is it possible to plot price and executed trade markers for dataseries 2 in a second panel in Strategy Analyzer?

      Comment


        #4
        Hello RandyT,

        The secondary data series will not add additional slots to the chart like we see when we add a second data series to a chart itself, so it would not be possible to correctly plot the data.

        If you want to see trade markers from another data series that is not the primary, you could have strategy draw its own markers. For example, you could use OnExecutionUpdate() to place a marker and some text describing the order that filled. I would suggest taking this approach so you can display meaningful information without the orders being skewed.

        OnExecutionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

        Draw.Dot (example marker) - https://ninjatrader.com/support/help...s/draw_dot.htm

        Draw.Text() - https://ninjatrader.com/support/help.../draw_text.htm

        If there is anything else we can do to help, please let us know.

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello RandyT,

          The secondary data series will not add additional slots to the chart like we see when we add a second data series to a chart itself, so it would not be possible to correctly plot the data.

          If you want to see trade markers from another data series that is not the primary, you could have strategy draw its own markers. For example, you could use OnExecutionUpdate() to place a marker and some text describing the order that filled. I would suggest taking this approach so you can display meaningful information without the orders being skewed.

          OnExecutionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

          Draw.Dot (example marker) - https://ninjatrader.com/support/help...s/draw_dot.htm

          Draw.Text() - https://ninjatrader.com/support/help.../draw_text.htm

          If there is anything else we can do to help, please let us know.
          ANY EXAMPLE CAN BE SHARED SO I can see the code ??

          thanks

          Comment


            #6
            Hello stantenlee,

            An example of how the code would appear:
            Code:
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
            Draw.ArrowUp(this, "execution" + executionId, true, 0, price, Brushes.Blue, true);
            }
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            59 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            134 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X