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

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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X