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 cre8able, Today, 01:16 PM
          2 responses
          9 views
          0 likes
          Last Post cre8able  
          Started by chbruno, 04-24-2024, 04:10 PM
          3 responses
          48 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by samish18, Today, 01:01 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by WHICKED, Today, 12:56 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by WHICKED, Today, 12:45 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X