• 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

sharing resources

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

    sharing resources

    Can script resources be shared amongst different charts and if so how?

    e.g.

    namespace NinjaTrader.Indicator
    {
    partial class Indicator
    {
    public static int myInt = 1000;
    }
    }

    1. do all chart scripts have access to myInt
    2. does myInt require "Multi-Threading Consideration" discussed in NT help.
    3. Are there other ways to share resources?

    Can someone please clarify, I think I may have misundestood?
    Last edited by futurenets; 03-16-2015, 05:41 AM.

    #2
    Hello,

    Thank you for the questions.

    By declaring the Static int in your indicator class this would attempt to give the class static access to the int. This means that if you placed another class inside of your script This would not do exactly what you are expecting.

    Here is an example of what I mean using what you had provided:


    Code:
    public class Test : Indicator
    {
          public static int myInt = 1000;
    
          protected override void OnBarUpdate()
          {
          }
    }
    
    public class Test2 
    {
         public void TestVoid()
         {
    		Test.myInt = 50;
          }
    }
    This would be using the variable in a static context. Because of the way NinjaTrader works this would not work outside of the script. If you tried this in another indicator you would get an error because it would not be visible outside of its instance.

    NinjaTrader is fairly specific in the fact that each script is its own instance, items like this or using variables in static context would not supported and there is not really any supported method to share information inbetween two scripts.

    The only exceptions is when using a strategy you have the ability to include indicators for signals, this would be reading the data from the indicator in a synced way that allows it to be used.

    If you were to use variables in static context they would not be synced with the bar series and could provide incorrect data if not always updated before used.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by futurenets View Post
      Can script resources be shared amongst different charts and if so how?

      e.g.

      namespace NinjaTrader.Indicator
      {
      partial class Indicator
      {
      public static int myInt = 1000;
      }
      }

      1. do all chart scripts have access to myInt
      2. does myInt require "Multi-Threading Consideration" discussed in NT help.
      3. Are there other ways to share resources?

      Can someone please clarify, I think I may have misundestood?
      Yes, all scripts that inherit from the Indicator base class will have access to myInt, and can modify it or read it, unless you declare the same in the script, in which case the local class variable declared in the script will override the publicly declared one in the Indicator base class.

      Comment


        #4
        sharing resources this way does appear to work ok

        but unable to export having done so.

        Comment


          #5
          Originally posted by futurenets View Post
          sharing resources this way does appear to work ok

          but unable to export having done so.
          In what file did you declare the static variable?

          Comment


            #6
            I created a new indicator called myCustomMethods and replaced the contents with

            namespace NinjaTrader.Indicator
            {
            partial class Indicator
            {
            public static string = "myString";
            }
            }

            Comment


              #7
              Originally posted by futurenets View Post
              I created a new indicator called myCustomMethods and replaced the contents with

              namespace NinjaTrader.Indicator
              {
              partial class Indicator
              {
              public static string = "myString";
              }
              }
              MyInt is an int: MyString is a string. I am not seeing the connection. We have to stay consistent in the discussion.

              Comment


                #8
                I created a new indicator called myCustomMethods and replaced the contents with

                namespace NinjaTrader.Indicator
                {
                partial class Indicator
                {
                public static int myInt = 1000;
                }
                }

                Comment


                  #9
                  Originally posted by futurenets View Post
                  I created a new indicator called myCustomMethods and replaced the contents with

                  namespace NinjaTrader.Indicator
                  {
                  partial class Indicator
                  {
                  public static int myInt = 1000;
                  }
                  }
                  In that case, to export, you will have to add that file to the export. If you read your log, you will see an error about a missing definition.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Yandychang, Today, 02:16 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Yandychang  
                  Started by priceisking, Today, 01:16 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Started by kashyapjdave, 03-23-2017, 12:12 AM
                  11 responses
                  1,956 views
                  0 likes
                  Last Post forextrader2003  
                  Started by Gav_G, 07-26-2018, 04:29 PM
                  5 responses
                  422 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Started by spikeruk, Today, 01:49 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post spikeruk  
                  Working...
                  X