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

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 Waxavi, Today, 02:10 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by TradeForge, Today, 02:09 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post TradeForge  
                  Started by Waxavi, Today, 02:00 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by elirion, Today, 01:36 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post elirion
                  by elirion
                   
                  Started by gentlebenthebear, Today, 01:30 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post gentlebenthebear  
                  Working...
                  X