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

Reading Name of Script?

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

    Reading Name of Script?

    How can I read the name of the actual running script, like
    actualScriptName = ...

    Thx

    #2
    BillCh,

    Don't know what you mean. The name is whatever you name it. There is no property to access it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have a main script, call it BillsMAINv06. I am saving versions with preset parameters not to have to change them every time, like BillsMAINv06_614_bb, BillsMAINv06_614_xh, BillsMAINv06_512_bb, BillsMAINv06_512_xh, ...

      As I want to create files with the scriptname being a part of the file name and want to write log entries (to output window etc.) referencing the particular scripts, I cannot hardcode the script name to each and every file. Also, my main script is under continous development, so my "master" script will change its name from BillsMAINv06 to BillsMAINv07 and so on. I than change the parameter presets for its variants (as above) and I do not want to have to hard code the scripts names as this would leave room for errors I wouldn't recognize immediately.

      As this is all some C# stuff and the script's name is some class or object or namespace or whatever (I am a trader, not a programmer), there sould be a way - any way - to get its name programmatically, right?

      Thx

      Comment


        #4
        This is not supported. You have to change it as you change file names.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Maybe some C#/.NET pro and non-NT-official can help me out here?

          As NT itself somehow can manage and differentiate individual scripts (like on the Strategies tab of the Control Center where one can clearly read the scripts name under the Strategy column) there must be a way to get this information.

          Thanks!

          Comment


            #6
            Bill,

            if you are looking for the class instance name of your indicator (is that what you mean by main-script?), you could try something like this (not tested):

            string fullname = this.ToString();
            string extractedName = fullname.Remove(fullname.IndexOf('('));
            Print("Extracted class instance name: " + extractedName)

            Regards
            Ralph

            Comment


              #7
              AWSOME Ralph!

              Works perfectly! Exactely what I needed, the name of the strategy!

              Thanks a lot!!

              P.S.: I don't want to overdo it, but do you also have a hint of how to get the selected account name/number? I once was told by NT staff it cannot be read. I am using IBs TWS, btw.

              Comment


                #8
                Don't know how to do that, Bill. Regards Ralph.

                Comment


                  #9
                  Again, thanks a lot for the name extraction stuff!

                  Comment


                    #10
                    Just one more comment regarding the name extraction. It is kind of static, the result doesn't change througout the entire runtime. Best location to performe the extraction therefore is the indicator's constructor. I would suggest to declare the variables as private in the standard variable section (where the wizard generated vars are located) and to execute the code in the constructor like this:

                    Code:
                    public class myInd : Indicator
                    {
                      private string fullname, extractedName;
                      ...
                      public myInd()
                      {
                        string fullname = this.ToString();
                        string extractedName = fullname.Remove(fullname.IndexOf('('));
                      }
                    }
                    Regards
                    Ralph

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mgco4you, Today, 09:46 PM
                    1 response
                    2 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by wzgy0920, Today, 09:53 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by f.saeidi, Today, 08:01 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X