• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object passed with BarType

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

    Object passed with BarType

    A while ago I was asking about adding an "Object" with the Bar Data. I don't see that capability at the moment. Did that get dropped?

    Sometime it would be nice to pass more than just OHLCV (I see Bid/Ask added). For raw processing this might include strange stuff like (Typical*Typical) value (bad example). Maybe the phase of the moon when that tick was processed... Etc...

    The goal was to allow flexibility to the developer of a BarType to bundle other information along with the bar back to the indicators/strategies.

    In NT7, OHLC were all considered price data, hopefully that assumption doesn't hold true in NT8 orther are ways to override charting. For example the NIKKI has a 5 tick size, if you are passing back OHLC as single ints, you cannot see anything other than the 5 tick intervals. I had to override the instrument to a 1 tick size which has other implications.

    #2
    Unfortunately we made the call to keep the base AddDataPoint as clean as possible without this extra object parameter for many reasons.

    However I'm happy to provide a way you would use to do exactly what you're asking.

    In the custom bar type create a public property that you wanted to access as the tick comes in. Then set this property in the bar type (If you wanted to keep an list/array of values per bar you could do that too). Then cast the Bars.BarType to your custom bar type and access yor custom data directly in the secondary script.

    Something like this:

    BarType:

    public double MyTestValue
    {
    get; set;
    }

    Indicator / Strategy:

    NinjaTrader.NinjaScript.BarsTypes.TestBarType testBarType = Bars.BarsType as NinjaTrader.NinjaScript.BarsTypes.TestBarType;
    if (testBarType != null)
    {
    Print(testBarType.MyTestValue);
    }
    BrettNinjaTrader Product Management

    Comment


      #3
      Brett,

      I think this works nicely. Suites the same purpose. If I have trouble, I will reach out.

      Comment


        #4
        Hi Brett,

        I am trying to setup a "Series<double>" for indicators/strategies to access for the bar type rather than a single discrete value.

        I have the following for example in the BarType:

        private Series<double> m_PriceHigh;
        private Series<double> m_PriceLow;


        The problem is I don't seem to be able to create an instance of these with the BarType with:

        m_PriceHigh=new Series<double>(this);
        m_PriceLow=new Series<double>(this);

        I get an error as it seems like BarType is of NinjaScriptBase.

        Any idea how I can create a series to grow with the BarType like this?

        Comment


          #5
          Hello NJA_MC,

          This post has been edited to reflect Dave's message above.

          Please let me know if you have any questions.
          Last edited by NinjaTrader_MichaelM; 08-17-2015, 05:03 AM.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            There is one way that it should be possible to bypass this limitation and instantiate a Series<T> within a BarsType.

            There is an overload for Series<T> that takes a Bars object, and there is a Bars object supplied within the OnDataPoint() event handler within a BarsType class. This is the ideal place to instantiate a Series, because when OnDataPoint() is triggered, it is safe to assume that the underlying Series for the BarsType has been initialized, and data has started to come in. This solves the problem of not having any Bars data with which to syncronize your custom Series:

            Code:
            Series<double> mySeries;
            protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
            		{
                        mySeries = new Series<double>(bars, MaximumBarsLookBack.Infinite);	
            		}
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Originally posted by NinjaTrader_Brett View Post
              Something like this:

              BarType:

              public double MyTestValue
              {
              get; set;
              }

              Indicator / Strategy:

              NinjaTrader.NinjaScript.BarsTypes.TestBarType testBarType = Bars.BarsType as NinjaTrader.NinjaScript.BarsTypes.TestBarType;
              if (testBarType != null)
              {
              Print(testBarType.MyTestValue);
              }

              I am using this in NT8 ChartStyle but no success, are you sure this can work in chart styles also ? This has been very old problem since i was trying to access public property from BarType to chartStyle in NT7. I was told to use it as static but that was not proper solution.

              Comment


                #8
                To replicate the old problem, i repeat scenario in NT8 by just printing out the bar count from a custom bar type , whenever a new bar forms. Frankly simpler than this i cant think of exposing value from bartypes. But results are always inconsistent. Some time it prints correctly, some time never some time prints for half number of bars, sometime bars disappear from chart. .

                Comment


                  #9
                  Originally posted by devdas View Post
                  To replicate the old problem, i repeat scenario in NT8 by just printing out the bar count from a custom bar type , whenever a new bar forms. Frankly simpler than this i cant think of exposing value from bartypes. But results are always inconsistent. Some time it prints correctly, some time never some time prints for half number of bars, sometime bars disappear from chart. .
                  Can you please clarify a bit exactly what you are trying to pass to what? Are you trying to pass a value from a ChartStyle to a BarsType (or reverse), or from one of those to an Indicator/Strategy? Are you trying to pass a single value or a Series<T>?
                  Dave I.NinjaTrader Product Management

                  Comment


                    #10
                    Originally posted by NinjaTrader_Dave View Post
                    Can you please clarify a bit exactly what you are trying to pass to what? Are you trying to pass a value from a ChartStyle to a BarsType (or reverse), or from one of those to an Indicator/Strategy? Are you trying to pass a single value or a Series<T>?
                    From BarsType to ChartStyle, object is single value in one case and a List in second case.

                    It works but not in consistent basis. For example for first case - a single value. Just make a custom bartype and try to print bars count after Add method.Its not that bar type has flawed logic its ok normally.

                    Comment


                      #11
                      Thank you. I have not been able to come up with a working sample as yet today. It is possible that the current NinjaScript architecture does not allow values to be passed from a BarsType to a ChartStyle specifically, but I'll need to dig a bit deeper before I say that for certain.
                      Dave I.NinjaTrader Product Management

                      Comment


                        #12
                        Originally posted by NinjaTrader_Dave View Post
                        Thank you. I have not been able to come up with a working sample as yet today. It is possible that the current NinjaScript architecture does not allow values to be passed from a BarsType to a ChartStyle specifically, but I'll need to dig a bit deeper before I say that for certain.
                        Thanx.
                        To save your time i have attached a test bar type "TestMinuteBar" which is clone of default minute bar type ( except name and print statements ) and 4 snap for showing the inconsistency in print statements. Basically this is just a prototype of larger problem where i am trying similar practice involving exposing a List to ChartStyle. Inconsistency is very random and cant even be reproduce in same way by even repeating the steps. So i suggest you test it thoroughly and deeply. Try to change bars period value and days to load in same created chart and you will see this. Though this happens on newly created chart also.

                        Session duration : 375 minute. Session Days : Mon to Fri, Trading Hour : Nse.
                        Test1-a : Chart created with 14-Dec and 15-Dec ( running ) , Result : OK
                        Test1-b : Same Chart, day to load resduce to 0. Result : OK
                        Test1-c: Same Chart, day to load 1. Result : Not Ok ( apparently it is taking 16 bars from prior step and printing only last 16 bars of 15-Dec )
                        Test1-d: Same Chart day to load 1 , period changed to 30 minute. Result : Not OK ( apparently its printing only 6 bars of 15-Dec ).

                        Test carried in continuous manner as described , no changed made in between steps.
                        Attached Files

                        Comment


                          #13
                          Thank you for providing that. I will test this out on my end and post back here with my findings.
                          Dave I.NinjaTrader Product Management

                          Comment


                            #14
                            Originally posted by NinjaTrader_Dave View Post
                            Thank you for providing that. I will test this out on my end and post back here with my findings.
                            Any test on progress ?

                            Comment


                              #15
                              With the holidays this weekend we have a lot of staff out. Dave will return next week and post results.
                              BrettNinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tallpaw, Today, 07:20 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post tallpaw
                              by tallpaw
                               
                              Started by leodrz, Yesterday, 10:26 PM
                              1 response
                              27 views
                              1 like
                              Last Post NinjaTrader_Jesse  
                              Started by Martin89, Today, 02:09 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Martin89  
                              Started by Trade95, Yesterday, 05:38 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_EricB  
                              Started by Karelgp7, Yesterday, 03:16 PM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X