• 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

Print StrategyID

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

    Print StrategyID

    Hello,

    how can I print the StrategyID of my automated Strategy in the outpout window?


    Many thanks and best Regards,
    Redmoon22

    #2
    Hello Redmoon22,

    Thank you for writing in. If you are using the AtmStrategyCreate() method, you will want to assign the strategy id to a variable first, and then print that variable:
    Code:
    #region Variables
        private string myAtmStrategyId;
    #endregion
    protected override void OnBarUpdate()
    {
        myAtmStrategyId = GetAtmStrategyUniqueId();
        AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
                TimeInForce.Day, GetAtmStrategyUniqueId(), "MyTemplate",
                myAtmStrategyId);
        Print("Strategy ID: " + myAtmStrategyId);
    }
    There is also an excellent example provided with the NinjaTrader platform which you can access by navigating to Tools -> Edit NinjaScript -> Strategy -> SampleAtmStrategy

    If you wish to print the strategy Id of the NinjaScript strategy itself, could you please clarify why you need to do this, to help me better assist you?

    Please let me know if you have any questions.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Hi,
      it's for my NinjaScript strategies. My Strategies are generating emails with Profit/Loss information (and also some other notes) after a finished trade. I want to be able to assign the StrategyID to the email subject and text to have a better overview about all trade results.

      I need to know how to get and transform the StrategyID into a string.

      In the Orders Tab at NinjaTrader I see the assingment of the NinjaScript StrategieID to the generated Orders, it should be possible to get this Information into my automatically generated emails.
      Last edited by Redmoon22; 07-02-2015, 07:33 AM.

      Comment


        #4
        Hello Redmoon,

        Thank you for clarifying. If you are not doing this with the express purpose of comparing the emails to what you see in the NinjaTrader Control Center, and simply need to differentiate between which strategy is sending the email, why not hardcode some sort of strategy identifier into the emails? This would allow you to differentiate between multiple instances of the same strategy and between different strategies. For example:

        StrategyA
        Code:
        #region Variables
        private string StratId;
        #endregion
        protected override void OnStartUp()
        {
            StratId = "StrategyA_" + DateTime.Now.ToString();
        }
        StrategyB
        Code:
        #region Variables
        private string StratId;
        #endregion
        protected override void OnStartUp()
        {
            StratId = "StrategyB_" + DateTime.Now.ToString();
        }
        Otherwise you should be able to access the strategy Id by using something like below:
        Code:
        Account.Strategies[Account.Strategies.IndexOf(this as StrategyBase)].Id.ToString()
        Please note: This code should not be called in quick succession in your strategy or it will likely crash your platform. You may want to call it one time only by assigning it to a variable, and then printing that variable out in your emails.

        Please let me know if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Hi,

          To check the string, I have put this into the statup void:
          Print ( Account.Strategies[Account.Strategies.IndexOf(thisas StrategyBase)].Id.ToString() );

          Following error message appears in the Output Window:
          **NT** Error on calling 'OnStartUp' method for strategy 'Strategy22/87ebd6f0ac9f40278ed4104766f931f1': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

          It doens't work. A solution with hard code isn't not what I am searching, because I am using several variations of the same strategies. Alle these strategies have different Labels.
          Maybe I can claryfy what I am searching for: I need to know how to get the labels of the strategies, because I want to be able to print this in the Output Window.

          For Example: I use the strategy code "Strategy22" to activate two strategies with the strategy labels "Strategy22 Version1" and "Strategy22 Version2 with TP".


          Comment


            #6
            Hello Redmoon22,

            Thank you for clarifying. I am unable to recreate this issue on my end. I have enabled 4 copies of the same strategy which print the Strategy Id in the OnStartUp() method without issue. Please ensure you are using the correct syntax that I provided and that you do not have any logical errors in the rest of your OnStartUp() code.

            Based on what you have said however you may be able to do something like this as well:
            Code:
            if(TP == false) //some condition that checks the parameters to see if you are using version one or version two
            	Print(this.Name + " Version 1");
            else
            	Print(this.Name + " Version 2 with TP");
            You could also simply add a parameter to your strategy where you type the label when adding the strategy to the chart and it just uses that parameter in the emails:
            Code:
            #region Variables
            private string strategyLabel;
            #endregion
            protected override void OnBarUpdate()
            {
                Print(strategyLabel);
            }
            #region Properties
            [Description("The label for this strategy that will be used when sending emails.")]
            [GridCategory("Parameters")]
            public string StrategyLabel
            {
                get { return strategyLabel; }
                set { strategyLabel = value; }
            }
            #endregion
            Please let me know if you have any questions.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              Hi,
              your suggestion with the strings could also work well, but your last suggestion has helped me to find a paths to a workable solution which I've found now:

              Print ( StrategyData.Strategy.Name ) ;

              This shows the Strategy Id/Label in the Output Window.


              Many Thanks for your help,
              Redmoon22

              Comment


                #8
                Hello Redmoon22,

                Thank you for posting your solution so other users with similar issues may benefit.

                Please let us know if we may be of further assistance anytime.
                Michael M.NinjaTrader Quality Assurance

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ajay8000, Yesterday, 11:31 PM
                5 responses
                18 views
                0 likes
                Last Post NinjaTrader_Marco  
                Started by simjs, Yesterday, 11:23 PM
                0 responses
                5 views
                0 likes
                Last Post simjs
                by simjs
                 
                Started by akuntysh, Yesterday, 10:41 PM
                0 responses
                4 views
                0 likes
                Last Post akuntysh  
                Started by Wolf1, Yesterday, 08:26 PM
                0 responses
                7 views
                0 likes
                Last Post Wolf1
                by Wolf1
                 
                Started by pparmley, Yesterday, 04:30 PM
                0 responses
                9 views
                0 likes
                Last Post pparmley  
                Working...
                X