Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

bar type

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

    bar type

    Im working on changing one of my custom bar types.


    i defined a constructor eg.

    private UtilityClass _myClass;

    public MyXXType() : base()
    {

    //in here i create instance of another utility class
    //and store the reference..

    _myClass = new UtilityClass();

    }

    When i put some prints in here i get many multiple calls of the constructor showing,
    So i created a singleton of my UtilityClass above .... UtilityClass.Instance and invoke this way.

    Is it normal/expected for the bartype constructor to be called many times ?
    Is it called / is a new bartype object created for every bar added to a chart / every session. I cant seem to find anything in help reference.

    I need to better understand the creation process of this as i need the _myClass reference to be reliable. If i have a singleton defined for utilityclass

    public static UtilityClass Instance
    {
    // in here i invoke the constructor .. which should be once...
    }

    for some reason the print statement in my UtilitClass constructor which is defined as private was getting called multiple times ...

    So you see i am trying some different approaches here ....
    as i need to know the sequece of when i open a new chart ....

    When the data is loaded are the historical bars then added to the chart addbar ?
    or do the bars get created as the data loads from history in sequence ....
    and then once this is complete any indicators can now reference the bars object...

    i did look at the object lifecycle but is doesnt cover this part .... if there is something i have missed please point me to that

    thanks

    #2
    Hi soulfx,

    Good questions.

    After some testing with a print in my own BarType constructor, I have noticed this being called multiple times but it is not being called for the creation of each individual bar. I have observed OnDataPoint() and AddBar() will be called to create a bar historical, or realtime.

    I am checking with the development team to see if they can provide some more information on when BarTypes are created.

    Thanks for your patience while I look into this further.

    Comment


      #3
      Thanks, ill await your checking with development team.

      the singleton i sorted and constructor of utility called once, but on reflection this is not what i need as would be once instance for the whole ninja session. So i ditched that part.

      Will be useful to know the process in custom bartype and the constructor process and glad you are seeing the same ie is not for every bar - it seems on loading chart there are multiples then it stops

      thanks

      Comment


        #4
        Hi soulfx,

        Thanks for your patience.

        The development team would not advise to using a constructor in a BarType because it can be cached multiple times. There is not a set in stone answer that they will be able provide for when exactly these are created. The exact answer gets complicated and it boils to be being an unadvised approach that would not be supported.

        It is advised, however, to use the state system to create objects that are to have a reliable reference. BarTypes will process through the following states:
        1. SetDefaults
        2. Configure
        3. Active
        4. Terminated
        https://ninjatrader.com/support/helpGuides/nt8/en-us/?onstatechange.htm

        If there is anything else I can do to assist, please let me know.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        561 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 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
        547 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