Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find indicator location programmatically?

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

    How to find indicator location programmatically?

    I have made an indicator which creates a new text file for values storage.
    However rather than just saying the location is here........

    Code:
    NinjaTrader.Core.Globals.UserDataDir + @"bin\Custom\Indicators\Sim22\" + Name + ".txt";
    ....... I would like to find the windows explorer location of the actual indicator (via ninjascript) so that I can create the text file in the same subfolder as the indicator. If someone else chooses to change the subfolder location of the indicator it could cause all sorts of confusion

    Code:
    NinjaTrader.Core.Globals.UserDataDir + @"bin\Custom\Indicators\[B]<Current Location>[/B]\" + Name + ".txt";
    Thank you,

    regards,

    Simon.

    #2
    Are you asking how to find the indicator name of your own indicator?

    Comment


      #3
      Originally posted by sledge View Post
      Are you asking how to find the indicator name of your own indicator?
      No, not the name itself. But thank you.

      I want to say something like this:

      Code:
      string str = NinjaTrader.NinjaScript.Indicators.Sim22.myRSI.[B]Location[/B].toString();
      Of course 'Location' is fictional...... perhaps.

      so I want my string to return something like this:

      Code:
      "C:\Users\User\Documents\NinjaTrader 8\bin\Custom\Indicators\bin\Custom\Indicators\Sim22\"
      It will tell me the exact folder the indicator 'myRSI' is stored.

      Idea: I noticed 'namespace' has the details I want since it includes the subfolder name as well....... Not sure how to tap into that.
      Last edited by Sim22; 02-25-2016, 11:33 PM.

      Comment


        #4
        Hello,

        Thank you for the question.

        If you want to find the files folder by its namespace, you can, but that assumes the namespace matches the folder which in theory it should.

        One way would be the following:

        Code:
        string myPath = System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "bin", "Custom", this.GetType().Namespace.Replace(this.GetType().BaseType.Name + "s", this.GetType().BaseType.Name).Replace("NinjaTrader.NinjaScript.","").Replace(".","\\"));
        This is overly complicated because the custom namespaces do not match the folder structure exactly. I.E. the namespace:
        NinjaTrader.NinjaScript.Indicators
        maps to the folder
        Documents\NinjaTrader 7\bin\Custom\Indicator

        The actual folder lacks the plural or the S at the end, so that needs to be accounted for in whatever string formatting you use.

        This also assumes that the file in question exists in the namespace NinjaTrader.NinjaScript. which all items should and trims that off of the namespace leaving only the folders it would lie in.
        Also this assumes you have the same Class name as the File name.

        For example, a indicator in the folder Tests named MyTest might return the following line:

        C:\Users\MyUser\Documents\NinjaTrader 8\bin\Custom\Indicator\Tests
        If you wanted to include the filename you could build the string in this way:

        Code:
        string myPath = System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "bin", "Custom", this.GetType().Namespace.Replace(this.GetType().BaseType.Name + "s", this.GetType().BaseType.Name).Replace("NinjaTrader.NinjaScript.","").Replace(".","\\"), this.GetType().Name + ".cs");
        C:\Users\MyUser\Documents\NinjaTrader 8\bin\Custom\Indicator\Tests\MyTest.cs
        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 02-26-2016, 09:08 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Well done. Kudos to you Jesse. You are a magician!

          For NT8 this is a little different since the 'Indicator' folder actually is 'Indicators'. So anyone else looking at this just do the following:

          Code:
          string myPath = System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "bin", "Custom", this.GetType().Namespace.Replace("NinjaTrader.NinjaScript.","").Replace(".","\\"), this.GetType().Name + ".cs"); //.txt in my case
          Last edited by Sim22; 02-28-2016, 04:10 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kevinenergy, 02-17-2023, 12:42 PM
          117 responses
          2,765 views
          1 like
          Last Post jculp
          by jculp
           
          Started by Mongo, Today, 11:05 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by SightCareAubetter, Today, 12:55 PM
          0 responses
          3 views
          0 likes
          Last Post SightCareAubetter  
          Started by traderqz, Today, 12:06 AM
          8 responses
          16 views
          0 likes
          Last Post traderqz  
          Started by SightCareAubetter, Today, 12:50 PM
          0 responses
          2 views
          0 likes
          Last Post SightCareAubetter  
          Working...
          X