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

How do I get the time inside the Initialize() method?

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

    How do I get the time inside the Initialize() method?

    I put Today.ToString() inside a Print string in my Initialize() method. That gets the runtime error :
    "BarsInProgress" property can't be accessed from within "Initialize" method
    So how am I supposed to get the time while still in Initialize()?

    -----

    Is there anything I can read about the overall system architecture? I am really astonished that by the time I have a chart up and a user brings up the indicators dialog, my initialization method has no access to basic things like time, or (of course) to ChartControl. It jsut sounds as if I am being called before those upstream from me have had time to do their own initialization.

    I'm not trying to critique the architecture, but it would make my life easier if I understood it rather than running into all of these weird cases, one-by-one.

    --EV

    #2
    Hello ETFVoyageur,

    I'm not sure what you're trying to do with Today here. ToDay() is a NinjaScript method that will take the date portion of a date time object and convert into an integer. Is this what you're using?

    ToDay(Time[0])
    Bar objects do not yet exist in Initialize() if you're trying to access from there.

    There is available OnStartUp() method if you need to set certain values only once. Initialize() is reserved for setting built in properties like EntriesPerDirection, CalculateOnBarClose, etc.

    There is for sure a learning curve to understanding the framework. We document all supported methods and properties in our help guide. You may find this alphabetical reference useful.

    You can also track the flow of your code with print statements or by connecting to Visual studio.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      I must apologize. Being new to both C# (my experience is C++) and to NT, I sometimes forget to pay attention to the difference. In this case, I did not stop to think I was asking a C# question, which is something I should discover and understand on my own. I have now done so and my time question is handled.

      > There is for sure a learning curve to understanding the framework. We document all supported methods and properties in our help guide.

      The help guide is certainly well done and very useful -- I use it a lot. It is, however, a list of details. It does not even try to talk about system architecture. My question/observation was somewhat between rhetorical and hopeful --- learning a bunch of details is not the best way to come to an understanding of the larger system architecture. Inferences I make from the details may or may not turn out to be correct. I was hoping there might be an architectural overview paper or something that I could read.

      > You can also track the flow of your code with print statements or by connecting to Visual studio.

      I do use Print statements. Have not debugged that way in years! Pretty primitive, but it is all I have for now. My Visual Studio is too old for you to work with ... I'll see about upgrading one of these days.

      --EV

      Comment


        #4
        Thanks for your feedback, EV. We're always looking to improve documentation and ease the learning curve. I will forward your request for an architecture overview.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan,

          To give you a good example, consider when to do cleanup. Your documentation for OnTerminate() says:
          Note: Please do NOT overload the Dispose() method. Dispose() method could be triggered much later than expected resulting in resources not being released early enough.
          According to my print statements, Dispose() was called several times, while OnTerminate() was not called at all while going through a full cycle from adding the indicator to removing it. Fortunately, based on some other code I saw, my cleanup is in Dispose() -- if it had been in OnTerminate() it would have never gotten done. So much for what the Help page says about that.



          That's my problem with a list of details -- obviously there is something different going on here that the Help writer thought about. Problems like that happen all the time when you try to operate by memorizing a list of details instead of understanding the overall environment. It just cannot be done effectively.


          Another example -- according to my prints, Initialize() is actually called quite a lot. In one case, Plot() was called. Then I reconfigured the indicator and the next thing that got called was Initialize() -- no Dispose() or OnTerminate() in between. After seeing all of this, I am not at all clear just when Initialize() does get called, but it is most certainly not just once initially. It even gets called when the indicator dialog comes up, even if the indicator itself is not on my chart.


          Enough rambling ... I hope you see what I mean about understanding just what is going on. What Initialize() can expect, when to clean up, etc are just not clear and the Help documentation sure does not answer that sort of question. Not to mention that it said to use OnTerminate() for cleanup, but OnTerminate() never got called.


          Before I cause a misunderstanding, I am not complaining about anything. I am just making the case that the existing documentation is little help in understanding the system.



          --EV

          Comment


            #6
            Thank you. We have noted your feedback. It would definitely be useful to have some kind of overview to refer, in order to understand the structure.

            Initialize() documentation notes that it can be called more than once.

            Dispose() is a C# method and in the scope of NinjaScript is intended for advanced users. There is a lot of resource cleanup that goes on under the hood without the user needing to call this. This sample on custom events uses dispose, and is about the only place within our supported framework you'll find reference to it. We intend for this type of sample to be a jumping off point if you start working with resources you later need to clean up.

            We want to provide you the tools and documentation to get started right away writing indicators and automated strategies. Since you have the C# connection, there is always going to be more you're capable of doing than we offer support and documentation for.
            Last edited by NinjaTrader_RyanM1; 01-11-2011, 04:02 PM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by AttiM, 02-14-2024, 05:20 PM
            11 responses
            184 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by fernandobr, Today, 09:11 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by timmbbo, Today, 08:59 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by KennyK, 05-29-2017, 02:02 AM
            2 responses
            1,281 views
            0 likes
            Last Post marcus2300  
            Started by itrader46, Today, 09:04 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X