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

Simple question

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

    Simple question

    private DataSeries highPass;
    #endregion

    protected override void Initialize()
    {
    highPass = new DataSeries(this);

    Hi,
    Struggling with Ninjascript her simple question: Why do you need to define
    highPass as a variable and then initialize it below. It seems redundant to me it looks like highPass has already been set to a new DataSeries and why the (this)

    Struggling oldtimer programmer
    any comments appreciated
    Greg

    #2
    Originally posted by steprog View Post
    private DataSeries highPass;
    #endregion

    protected override void Initialize()
    {
    highPass = new DataSeries(this);

    Hi,
    Struggling with Ninjascript her simple question: Why do you need to define
    highPass as a variable and then initialize it below. It seems redundant to me it looks like highPass has already been set to a new DataSeries and why the (this)

    Struggling oldtimer programmer
    any comments appreciated
    Greg
    That is because that is the way that all entities are declared. It may be possible in many cases to declare and initialize an object at the same time on one line, but that is simply shorthand that applies in those particular cases. DataSeries() takes the parent object itself as a parameter, which is why it has to be declared and initialized separately.
    Last edited by koganam; 06-29-2013, 02:55 PM.

    Comment


      #3
      Thanks for the reply. I hear the words just have a hard time conceptualizing and internalizing this type of programming. I will keep at it until something "clicks". Thanks
      Greg

      Comment


        #4
        Originally posted by steprog View Post
        Thanks for the reply. I hear the words just have a hard time conceptualizing and internalizing this type of programming. I will keep at it until something "clicks". Thanks
        Greg
        Think of it simply this way: if the object has to take its container as a parameter, then, ipso facto, it is a circular reference. The Initialize() method is written to, inter alia, resolve such a situation, so that the object can be created.

        If that situation does not exist to start with, then you should be able to declare and initialize the object at the same time.

        Comment


          #5
          Hello Greg,

          It is good practice when setting up variables to ensure that they are setup correctly.

          Also, it is to ensure that the DataSeries objects are synced up to the Primary Data Series as well.

          Happy to be of further assistance.
          JCNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by LawrenHom, Today, 10:45 PM
          0 responses
          3 views
          0 likes
          Last Post LawrenHom  
          Started by love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Working...
          X