Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-time charts

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

    Multi-time charts

    Hi!
    I am trying to use a multi-time strategy, but want to check the values in the chart.
    Just as a test purpose, I am adding 2 and 5 min time in the initiaize section, and try to plot the SMA for the different time frames:
    Code:
    protected override void Initialize()
            {
                Add(PeriodType.Minute, 2);
                Add(PeriodType.Minute, 5);
                
                Add(SMA(5));
                Add(SMA(BarsArray[1],5));
                Add(SMA(BarsArray[2],5));                    
                CalculateOnBarClose = true;
            }
    I just can see the SMA(5) for the index=0 data serie in the chart, but not for index=1 nor index=2.
    How can I see those values in my chart?
    Thank you very much!

    #2
    Unfortunately multi-series charts are not supported, but will be with NT7 (beta end of this year).

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      Unfortunately multi-series charts are not supported, but will be with NT7 (beta end of this year).
      Thank you very much for your immediate response.
      Does it mean I won't be able to plot anything except the main serie and indicators related to that serie?
      For instance, if I calculate the difference between two different instruments in a multi-instruments strategy, do you mean I will be able to use that value to go short, long etc but never be able to plot that number (till version 7)?
      Thanks a lot.

      Comment


        #4
        Unfortunately that is the case.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by eswap0 View Post
          Thank you very much for your immediate response.
          Does it mean I won't be able to plot anything except the main serie and indicators related to that serie?
          For instance, if I calculate the difference between two different instruments in a multi-instruments strategy, do you mean I will be able to use that value to go short, long etc but never be able to plot that number (till version 7)?
          Thanks a lot.
          You can plot anything that you can calculate. Simply add custom indicators, and set their values to whatever you want on each pass through OnBarUpdate. And if the values plotted don't fit the price scale of the main panel, then add them to new panels with their own price scale.

          There are some issues (see "60 Instrument Update" thread), but they don't prevent you from plotting custom values.

          Comment


            #6
            Many thanks for your reply.
            I am a little bit confused now: firs I suposed I could programm nearly anything usinc C# (I must say I am just learning, so I still have important limitations) bus as soon as I was told I wouldn't be able to plot values related to different instruments I just quit.
            Perhaps previous answers mean it was "not officially supported" instead what I undrestood ("it is not possible").
            What looks strange is that many people would like to work with spreads from diferent instruments, and I haven't been able to find any threat here with a solution...

            Comment


              #7
              Originally posted by eswap0 View Post
              Many thanks for your reply.
              I am a little bit confused now: firs I suposed I could programm nearly anything usinc C# (I must say I am just learning, so I still have important limitations) bus as soon as I was told I wouldn't be able to plot values related to different instruments I just quit.
              Perhaps previous answers mean it was "not officially supported" instead what I undrestood ("it is not possible").
              What looks strange is that many people would like to work with spreads from diferent instruments, and I haven't been able to find any threat here with a solution...
              The idea is to use a single Strategy (file) with mutiple instruments (symbols) and indicators "Add"ed to it to do all of your calculations and plotting. The major tricks are:

              (1) Dealing with the fact that OnBarUpdate will be called for every added instrument, and not in any particular order.

              (2) Using added custom indicators to do your plotting, while doing calculations within your Strategy.

              I suspect that these issues will still be present to a large degree in the next version of NT, so one might as well deal with them now. (My impression is that the major improvement will be to allow all this complexity as part of indicators too, but you'll still have to deal with the above issues if you want to use and plot multiple instruments and results in multiple panels in the same window.)

              To help you get started, here is the core of a custom indicator that can be used to plot anything in any panel (the "id" is used when initializing to differentiate one instance from another):

              // generic single price plotter
              publicclass MyPricePlotter : Indicator
              {
              privateint id = 0;

              protectedoverridevoid Initialize()
              {
              CalculateOnBarClose = false;
              Overlay = false;
              PriceTypeSupported = false;
              AutoScale = true;
              PaintPriceMarkers = true;
              DisplayInDataBox = false;

              Add(new Plot(new Pen(Color.Black, 1), "0"));
              }

              protectedoverridevoid OnBarUpdate()
              {
              }

              #region Properties
              [Description("")]
              [Category("Parameters")]
              publicint Id
              {
              get { return id; }
              set { id = value; }
              }
              #endregion
              }

              To use this indicator in a strategy, write something like:

              // declarations
              MyPricePlotter mpp = null;
              ...
              // initializations
              mpp = MyPricePlotter(1); // use "2" for next instance, etc.
              Add(mpp);
              mpp.PanelUI = 1; // where you want plot to go
              mpp.PaintPriceMarkers = false; // can override indicator params here
              ...
              // calculations (in OnBarUpdate)
              double myValue = 100 * 100;
              mpp.Values[0].Set(myValue);
              ...

              So you see that the notion that you "can't plot something" in NT does not make sense. You can plot anything. (BTW, the order in which indicators are "Add"ed determines their plot order, not the order in which their values are set. This is handy when it comes to getting the proper layering of plotted lines.)

              Comment


                #8
                And to create and use an indicator that supports multiple plots, within the indicator do multiple "Add"s...

                Add(new Plot(new Pen(Color.Black, 1), "0"));
                Add(new Plot(new Pen(Color.Black, 1), "0"));
                Add(new Plot(new Pen(Color.Black, 1), "0"));
                ...

                And within the Strategy, do multiple "Set"s, using 0-based indexing to refer to each of the indicator's plots...

                mpp.Values[0].Set(myValue1);
                mpp.Values[1].Set(myValue2);
                mpp.Values[2].Set(myValue3);
                ...

                Comment


                  #9
                  Thank you very much for your help!
                  Going to work on it.

                  Comment


                    #10
                    Got it!

                    I am a newbie (both in programming and trading): As greentrader's solution was a little bit confusing for me (thanks anyway!) I had to search by myself a little bit.
                    My target was "beeing able to plot a two instruments spread chart".
                    I just downoaded this from Official NinjaScript reference code samples (includes a strategy, which I didn't use, and an indicator).
                    Then I modiffy my own strategy according to what I saw in previous sample strategy: it was really easy.
                    Please find enclosed my simple/sample code. To make it work, I open a 1 min chart for GC 12-08, and run my strategy from there. What I get is the spread between the dec'08 future for gold from 50 times the dec'08 future for silver.
                    Must say I am happy tonight

                    Code:
                    //  
                    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>. 
                    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. 
                    // 
                     
                    #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.Strategy; 
                    #endregion 
                     
                    // This namespace holds all strategies and is required. Do not change it. 
                    namespace NinjaTrader.Strategy 
                    { 
                        /// <summary> 
                        /// Multi-Instrument sample strategy. 
                        /// </summary> 
                        [Description("Multi-Instrument sample strategy.")] 
                        public class jm_gc_si_0 : Strategy 
                        { 
                            #region Variables 
                            // Wizard generated variables 
                            // User defined variables (add any user defined variables below) 
                            #endregion 
                     
                            /// <summary> 
                            /// This method is used to configure the strategy and is called once before any strategy method is called. 
                            /// </summary> 
                            protected override void Initialize() 
                            { 
                                // Add an ES 12-08 1 minute Bars object to the strategy 
                                Add("SI 12-08", PeriodType.Minute, 1); 
                                     
                                /* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two 
                                indicators from each other. */ 
                                Add(StrategyPlot(0)); 
                                 
                                // Set the color for the indicator plots 
                                StrategyPlot(0).Plots[0].Pen.Color = Color.Blue; 
                                 
                                // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc. 
                                StrategyPlot(0).PanelUI = 2; 
                                 
                                CalculateOnBarClose = true; 
                            } 
                     
                            /// <summary> 
                            /// Called on each bar update event (incoming tick) 
                            /// </summary> 
                            protected override void OnBarUpdate() 
                            { 
                                                     
                                // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy 
                                // We only want to process events on our primary Bars object (main instrument) (index = 0) which  
                                // is set when adding the strategy to a chart 
                                if (BarsInProgress != 0) 
                                    return; 
                                     
                                double Diferencia = Closes[0][0]-Closes[1][0]*50; 
                     
                                StrategyPlot(0).Value.Set(Diferencia); 
                                         
                            } 
                     
                            #region Properties 
                            #endregion 
                        } 
                    }

                    Comment


                      #11
                      Greentrader,

                      AWESOME POST!

                      This is the type of answer that is invaluable. You clearly identified that something was possible, then you articulated the approach.

                      Thank you so much for your support Greentrader. Your explanation was spot on and extremely helpful!

                      For any new comers to this thread, there is a new indicator that has since been added by NT (it's not documented, but you can get info on how to use it here: http://www.ninjatrader-support2.com/...ead.php?t=6651
                      )

                      It's called StrategyPlot and it essentially is the dummy indicator used to plot that Greentrader is referencing with his initial code example. It's the "first" part if you will.

                      Good luck. Once you wrap your mind around this concept of multiple time frames and plotting indicators based on said time frames, you might want to look at DataSeries Syncing.

                      Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for





                      Thanks,


                      r2kTrader

                      Originally posted by greentrader View Post
                      You can plot anything that you can calculate. Simply add custom indicators, and set their values to whatever you want on each pass through OnBarUpdate. And if the values plotted don't fit the price scale of the main panel, then add them to new panels with their own price scale.

                      There are some issues (see "60 Instrument Update" thread), but they don't prevent you from plotting custom values.
                      Last edited by r2kTrader; 02-28-2009, 12:06 PM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      558 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      324 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      545 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      547 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X