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

Is it safe to modify a Strategy's this.Name during State.Configure/State.DataLoaded?

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

    Is it safe to modify a Strategy's this.Name during State.Configure/State.DataLoaded?

    Hello

    I am running NT 8.0.18.0 64-bit

    During State.Configure or State.DataLoaded, I would like to programmatically change the Strategy's this.Name to reflect how the Strategy has been configured. This provides a much more informative name and better sorting mechanism on the Control Center tabs.

    This appears to work for normal operation of a Strategy, but fails when backtesting (the dreaded "Object reference not set..." message appears when running the backtest).
    I could avoid the problem by disabling this code when backtesting.

    Other than the problem with backtesting, is it safe to modify this.Name during State.Configure or State.DataLoaded?

    Thank you

    #2
    Hello Zigfried,

    What specifically are you using in the name when you get the Object reference not set.error? That indicates something you are using is null.

    Not all tools are identical so you may see errors if you for example use a property of the chart which is not present in a backtest. Just checking for null and giving a different string should be sufficient if you are using something that is null in a backtest:

    Code:
    string myString = ChartControl != null ? "UseAPropertyFromTheChart" : "MyStringWhenNotNull";
    To answer the question you can change the name in any state and actually there is an override for that purpose as well: https://ninjatrader.com/support/help...ub=displayname

    The DisplayName override property can be used for custom naming, you can also use the State object there.

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

    Comment


      #3
      Hello Jesse

      There are no nulls in the programmatically determined name, but there is a period(.).

      A typical name that I want to use would be as follows:
      PCM1-00-P-Trade-AX-ABCD-30-0.6

      I tried the DisplayName override, but that doesn't seem to change anything in the Control Center tabs. It changes the Strategy stuff at the top-right corner of the chart.

      In the Control Center, I know that the Parameters column gives most of the information that I want, but it is way too verbose in my applications, so the information I am interested in is hard to easily find.

      In summary, I am trying to use a column in the Control Center to concisely show specific info about the strategy configuration. I was trying to use Strategy Name column, which appears on the Strategies tab. That way I could quickly scan all my running Strategies in the Control Center, and more easily know exactly what they all do.

      Thank you

      Comment


        #4
        Hello Zigfried,

        Thank you for the reply.

        Yes the name should be able to be set in any state, you would need to check the other values you are using to see what is null in that use case. The error you reported specifically means something is null which was used.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse

          I am using the following info to derive the Name: EDIT-Does Account.Connection.Options.Name exist for Backtest?

          1) Account.Connection.Options.Name
          2) Strategy Properties, all of which have an Enum associated with them, so they can't be null (and I am not testing this by Optimizing, where a null could possibly be entered for a Property).

          Note that I am performing ToString and Replace operations to grab the info and format it more clearly, and I am always getting the proper name, and I am not replacing anything with null.
          When I comment out the code that changes the Name, Backtest works fine.

          But I think you answered my question by saying that the name can be changed in those states. So I will just defeat the name change when Backtesting. The Strategy Name appears as part of my Order Names, so I can still track down what I need in the Bactest/Optimize results.

          Thanks again
          Last edited by Zigfried; 11-15-2019, 05:06 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Quanto, Today, 02:17 PM
          0 responses
          1 view
          0 likes
          Last Post Quanto
          by Quanto
           
          Started by Skifree, Today, 11:21 AM
          3 responses
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by manueldecastro, Today, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tradingnasdaqprueba, Today, 03:42 AM
          9 responses
          35 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by llanqui, Yesterday, 03:51 PM
          6 responses
          27 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X