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

Add a second instrument to strategy with day session (regular session) only bars

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

    Add a second instrument to strategy with day session (regular session) only bars

    Hi there:

    How can I add ES day session only (from 9:30 to 4:15) data as a secondary instrument to my strategy.
    I know i can use Add() method, but how can I make it day session only? I am using Esignal Premier account as datafeed. In Esignal I can use symbol "ES H0=2", is there a matching symbol in ninjatrader?

    Pls help......

    #2
    There is only one session on the chart and all instruments will use that session. To adjust it you will have to open up the Chart Properties.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank for the quick reply Josh.
      I know that I can adjust chart properties in the chart window.......the problem is that I would like to do it programmetically in the code. I need my strategy to calculate some key numbers automatically, so I need to load some differenct time frame ES data with both 24 hour session and day session only bars, so I can put indicators like Moving Average on each of the Bars, then access the value of them.......I am pretty new on ninja, but I am a .net programmer......Could you tell me if this is possible, please?

      Comment


        #4
        Suggest you set the chart to 24/7 and then use time filters in your code itself. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3226
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,
          Thanks for the sample, but I don't think this is solving my problem, because I need to build indicators onto it. It would be nice if I can build a Bars object with day session only bars to put into my strategy's BarsArray, so I can attach indicators like SMA or EMA to it.

          Another issue is about day session only daily bars, it's not possible to build it from 24 hour daily bars. Esignal does provide these data, is it possible to retrieve it from ninja?

          Please advise

          Thanks

          Comment


            #6
            net4walk,

            Not from a single chart. A single chart only has a single session. You cannot have two sessions on a chart.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I was actually talking about the strategy.....According to the help document, I can have multi instruments in Strategy, right? I can use method Add(......) to add more than one instrument to property BarsArray which I can access in the OnBarUpdate. What I wanted is to add ES daysession only bars to BarsArray, so I can calculate some indicator on it.


              Oh, I know what you mean, did you mean all the instruments in the strategy have to use the same time session, 24 hours or day session or whatever?
              Last edited by net4walk; 12-23-2009, 05:14 PM.

              Comment


                #8
                Correct, all instruments used within a single script will use whatever session is applied to the strategy/chart. You can't have one instrument on session A and another on session B.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Josh. Is there any improvement on this area in ninja 7? or is there a way to get around it? 'cause my strategy use both indicators on 24 hr session and regular session..... please advise..

                  Comment


                    #10
                    NT7 can have multiples I believe.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Josh.

                      If there is anyone on this forum have some insight on this issue, please let me know, I would appreciate it.

                      All I need right now is to get both 24 hr & regular session ES data from Esignal into one strategy, so I can load a windows form from the strategy to show me some key numbers calculated from the multi session data.

                      Thanks...

                      Comment


                        #12
                        my solution on this

                        I think I have figured out something over the Christmas. I managed to load different symbols and different session data in one strategy. Also I can put different indicators on the data, then I pass all the data into a form and display them in a data grid. I believe this is useful for anybody who wants to do analysis on different data with different session, time frames, etc, and wants to show analysis result in a custom form. That why I decide to post it although this is not officially supported by NT....

                        Below is the code snippet.... I also attached the files with the form design. I found that if I put c# files into Documents\Ninja6.5...\custom or ....\custom\function, then when I compile any strategy or indicator, NT would compile it as well, even if what I put in is a winform files. Just down load the attachment unzip it to a tmp directory, then copy the files in to matching folders in ....\custom\, then open any strategy, add reference to system.data.dll (default folder for it is c:\windows\microsoft.net\framework\v2.0.50727\) then F5 compile. Then open any chart and add strategy "DanielTestBars"...... There is an error when I run this saying can't serialize Bars or something, but it didn't stop the strategy from showing the form, so I just clicked ok and ignored it...
                        if anybody have any new discovery on anything, please let me know...

                        btw, in the form, the realtime price is displayed in two text boxes.

                        Code:
                         
                        #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;
                        using NinjaTrader.Custom.Function;
                        #endregion
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                            /// <summary>
                            /// Test retrive data in the code
                            /// </summary>
                            [Description("Test retrive data in the code")]
                            public class DanielTestBars : Strategy
                            {
                                #region Variables
                                // Wizard generated variables
                                // User defined variables (add any user defined variables below)
                          public Bars bars;
                                public NinjaTrader.Indicator.ATR atr;
                                public SMA sma;
                          bool FirstTime = false;
                                #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()
                                {
                                    CalculateOnBarClose = true;
                                    //Print("here \n");
                         
                                }
                                /// <summary>
                                /// Called on each bar update event (incoming tick)
                                /// </summary>
                                protected override void OnBarUpdate()
                                {
                                    //Print(String.Format("{0}\n", CurrentBar));
                                    if (!FirstTime)
                                    {
                                        Instrument instru = Instrument.GetObject("ES 03-10");
                                        if (instru != null)
                                        {
                                            Period period = new Period(PeriodType.Minute, 5);
                                            Session DaySession = new Session(new DateTime(2009, 12, 10, 8, 30, 0),
                                                                                new DateTime(2009, 12, 10, 3, 15, 0), false);
                                            Session Session24hr = new Session();
                         
                                            //create a Bars object independent and use different sessions 
                                            bars = Bars.GetBars(instru, period, new DateTime(2008, 11, 15), DateTime.Now, Session24hr, false, false);
                         
                                            //construct an indicator on the fly and set the property Bars, then set the other properties like period....
                                            atr = new ATR();
                                            atr.Bars = bars;
                                            atr.Period = 5;
                                            atr.CalculateOnBarClose = false;
                                            atr.SetUp();
                                            //another indicator on the same bars object
                                            sma = new SMA();
                                            sma.Bars = bars;
                                            sma.Period = 5;
                                            sma.CalculateOnBarClose = false;
                                            sma.SetUp();
                         
                                            //here is the trick that undocumented.  This loop would force the indicator to calculate
                                            for (int i = 0; i < bars.Count ; i++)
                                                bars.CurrentBar=i;
                                            //then load the form and use current strategy as parameter.
                                            FrmTest frmTest = new FrmTest(this);
                                            frmTest.Show();
                                            FirstTime = true;
                                        }
                                    }
                                }
                                public override void Dispose()
                                {
                                    if ( bars != null) bars.Dispose();
                                    if (atr != null) atr.Dispose();
                                    if (sma != null) sma.Dispose();
                                    base.Dispose();
                                }
                                #region Properties
                                #endregion
                            }
                        }
                        Attached Files
                        Last edited by net4walk; 12-27-2009, 11:33 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Mathias79, Today, 03:44 PM
                        0 responses
                        16 views
                        0 likes
                        Last Post Mathias79  
                        Started by Austiner87, Today, 03:42 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post Austiner87  
                        Started by lorem, 04-25-2024, 09:18 AM
                        19 responses
                        83 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by joselube001, 05-10-2024, 12:17 PM
                        6 responses
                        29 views
                        0 likes
                        Last Post joselube001  
                        Started by bigc0220, 09-18-2018, 09:16 AM
                        6 responses
                        2,587 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X