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

BarsType Clone never called

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

    BarsType Clone never called

    I have a custom BarsType and can see NinjaTrader going thru the process of creating a large number of objects in the life cycle process. However, Clone() is never called. I realize most of these objects are temporary, but I need the Clone to be properly called to copy private bar state between "functional" objects (i.e. I suspect there are multiple objects to deal with historical and live data).

    Seems like this should be a fundamental function of the life cycle process.

    #2
    Hello aslane,

    This is a bit too general for me to enter a feature request for.

    Is there a specific error this will resolve that we can provide to our development?

    Can you please provide an export of a reduced script that demonstrates the issue?

    o export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It's not a feature request per se, really just trying to figure out why Ninja does not follow the documented life cycle process for a BarsType object.

      If it did, Clone would be properly used.

      If you just create a BarType with a Clone method and set a break point, you will see that Clone is never called as the large number of BarsType objects are created.

      Clone is needed in order to properly track private state while bars are being built. So, if you need a feature request, there it is (although I would call it a bug since you are not following documented process).

      Comment


        #4
        Hello aslane,

        The Help Guide does not say that BarsType scripts are cloned (though I know they are at specific times behind the scenes).


        Can you clarify what the bug is that is causing an error in your script?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          While it does not say BarType is cloned, it is a NinjaScript object, which the life cycle does specifically talk about.

          The error is if you require bar to bar state within a BarType, then using Clone is the only way to properly propagate that state. When Clone is not called, you are starting fresh with no prior state.

          Comment


            #6
            Hello aslane,

            To confirm you are taking about the State property in OnStateChange is null?

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No, internal object state (i.e. private int x Thats why Clone is needed.

              Comment


                #8
                Hello aslane,

                Any custom internal variables values should be related to the current instance.

                As bars are being built the script instance does not need to be cloned and remains the same instance. Any internal variables would be kept in memory for that instance.

                I've made a modification to the Unirenko bars to add a private bool variable that defaults to false. This variable is changed when the State is Active as the script enables. The value remains true after it is changed for the life of the script instance.

                This would imply that the value is not being reset as bars are being built.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok, doing some more checking, I agree there is only a single instance with bars data. So, no need for a clone.

                  The reason for the confusion on my part is the OnDataPoint member is called once during Configure State, and then subsequent calls are in Active State. Why?

                  I think I can make this work now, but would like to understand that first OnDataValue call in the Configure state. Should it be ignored or is that a valid first tick of data?

                  For my bar type, the bars.Count is different on those two initial OnDataValue calls (i.e. 1034 in Configure -> 976 in Active). Almost like a trim has happened. Interestingly, this does not happen with your UniRenko example. My bar type is built with tick data and allows caching.

                  Comment


                    #10
                    Hello aslane,

                    I'll have to ask our developers about that.

                    I appreciate your patience.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello aslane,

                      Development says that the first OnDataPoint() is valid and processed.

                      I did not get a clear response on why State is State.Configure. If this is causing an issue with your code that cannot be worked around we can feature request for this to be changed.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks for the follow up. I can work with it, just needed to understand what was going on.

                        Comment


                          #13
                          aslane
                          I am commenting here bcuz I cannot comment on your user app share post for Better Renko

                          in your barstype cs file, you are setting the new BarsPeriod enumerator value to 17.

                          That conflicts with my installation as I have a custom bar type at enum index 17.

                          You should set your enum value to a very high index, which is unlikely to conflict with existing custom bar type enum indexes, and include a note describing this potential conflict so other users can know how to handle it when they get the error message:


                          Multiple Bartypes with the same BarsPeriodType were found

                          Comment


                            #14
                            Yes, people generally use higher values now (and should), but this code was developed long ago in in NT7 and needs to be backward compatible. You have the source, so can change.

                            I recently added in Ninja site, as it was no longer available elsewhere. At this point, it is really just a reference, as most people use much more exotic Renkos. If I ever update, I will add a comment explaining.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by yertle, Yesterday, 08:38 AM
                            7 responses
                            28 views
                            0 likes
                            Last Post yertle
                            by yertle
                             
                            Started by bmartz, 03-12-2024, 06:12 AM
                            2 responses
                            21 views
                            0 likes
                            Last Post bmartz
                            by bmartz
                             
                            Started by funk10101, Today, 12:02 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post funk10101  
                            Started by gravdigaz6, Yesterday, 11:40 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Yesterday, 10:49 PM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X