• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart to Chart Communication

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

    Chart to Chart Communication

    can I allow several charts to run a script calling getUniqueID()

    Code:
    namespace NinjaTrader.Indicator
     {
     partialclass Indicator
     {
     public int id = 0;
     
     public int getUniqueID()
     {
     return id++; 
     }
    


    to receive a unique ID?

    are there potential issues I need to consider (racing, thread etc.)?


    Last edited by futurenets; 03-14-2015, 08:17 AM.

    #2
    Originally posted by futurenets View Post
    can I allow several charts to run a script calling getUniqueID()

    Code:
    namespace NinjaTrader.Indicator
     {
     partialclass Indicator
     {
     public int id = 0;
     
     public int getUniqueID()
     {
     return id++; 
     }
    


    to receive a unique ID?

    are there potential issues I need to consider (racing, thread etc.)?


    ints are passed by value, so that only works if your id variable is static, with all the caveats that being static entails. Further, you probably want to update the id before reporting it, so you might want to use "++id" instead of "id++".

    Comment


      #3
      would a Mutex help?

      Comment


        #4
        Originally posted by futurenets View Post
        would a Mutex help?
        Probably an unnecessary complication. You are only trying to set and retrieve an ID after all.

        Also, regardless, in c#, the only simple way for different classes to access the same unique variable is if the variable is declared static.
        Last edited by koganam; 03-14-2015, 07:01 PM.

        Comment


          #5
          ok thanks.

          I don't know much about the internals of Ninjatrader but does this fall into the category of shared resources accessed simultaneously by multiple threads?

          if so is there a recommended approach to handling this?
          Last edited by futurenets; 03-15-2015, 05:19 AM.

          Comment


            #6
            Originally posted by futurenets View Post
            ok thanks.

            I don't know much about the internals of Ninjatrader but does this fall into the category of shared resources accessed simultaneously by multiple threads?

            if so is there a recommended approach to handling this?
            It has nothing to do with NinjaTrader: it is c#. It is not about threading: it is about how the language works.

            You stay aware of the issues, and you use the constructs as you see fit. There are times when there is no choice but to use a static variable, so you use one, and stay aware of the caveats.

            Comment


              #7
              sorry I don't understand. are you saying that multiple threads don't exist in Ninjatrader?

              "It has nothing to do with NinjaTrader" ... what is "it"?

              if resources are shared between charts via "partial class" then surely those resources become critical and thread synchronization may be required regardless of the use of static - hence my post?
              Last edited by futurenets; 03-15-2015, 11:50 AM.

              Comment


                #8
                Originally posted by futurenets View Post
                sorry I don't understand. are you saying that multiple threads don't exist in Ninjatrader?
                I do not see where I said that. I said that the issue you are raising is not a question that is related to threading.
                "It has nothing to do with NinjaTrader" ... what is "it"?
                You asked a specific question: "I don't know much about the internals of Ninjatrader but does this fall into the category of shared resources accessed simultaneously by multiple threads?" The pronoun refers to that question, and the fact that what you are asking has nothing to do with the internals of NinjaTrader: it is a matter directly of the c# language and how it was designed to work.
                if resources are shared between charts via "partial class" then surely those resources become critical and thread synchronization may be required regardless of the use of static - hence my post?
                "Partial classes" have no implication about "criticality". "Partial classes" are merely a facility in the language that allows us to split a class into different files, a situation which is of particular use in creating libraries among other things. There is nothing critical in them, in and of themselves. They are more a convenience to the programmer, allowing fine isolation of related code, than anything else.

                I am not sure where you get the impression that: 'resources are shared between charts via "partial class"'. Charts are merely objects. Whether or not they can access other objects, and how, is a matter of how those other objects are coded. "Partial classes" do not make anything critical.

                Any partial classes that NinjaTrader uses internally as assemblies have no bearing on the matter, unless you are proposing to extend those base classes. Even then, that would depend on what you are writing.

                Comment


                  #9
                  ok thanks. All help appreciated.

                  this helped me from NinjaTrader Help:

                  Multi-Threading Consideration for NinjaScript

                  With the introduction of multi-threading in NinjaTrader when doing things like optimizations special considerations should be made when programming your NinjaScript indicators and strategies. Multi-threading basically allows NinjaTrader to take advantage of multi-core CPUs commonplace in modern computing to do multiple tasks at the same time. What this means for an optimization run is that multiple iterations can be tested by utilizing the various cores available to the computer.

                  Should you be using custom resources like text files, static members, etc. it is important to protect your resources from concurrent access. If NinjaTrader tried to use the resource at the same time you would run into errors similar to this one:

                  8/20/2010 12:14:29 PM|3|128|Error on calling 'OnBarUpdate' method for strategy 'SampleStrategy/1740b50bfe5d4bd896b0533725622400': The process cannot access the file 'c:\sample.txt' because it is being used by another process.
                  Last edited by futurenets; 03-16-2015, 03:45 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by pparmley, Today, 04:30 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post pparmley  
                  Started by tonynt, Today, 04:21 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post tonynt
                  by tonynt
                   
                  Started by williamzz, Today, 03:44 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Miguel_88, Yesterday, 06:41 PM
                  2 responses
                  26 views
                  0 likes
                  Last Post Miguel_88  
                  Started by williamzz, Today, 02:12 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_Jim  
                  Working...
                  X