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

NT8 String Conversion

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

    NT8 String Conversion

    Hello,

    In NT7 I could simply add a string with the following and it provided a default string and allowed me to change it:

    public class SMA : Strategy
    {
    string instrString = "SPY";

    ---------------------------------------------------------------------------------------------------
    #region Properties
    [Description("Trade Instrument")]
    [GridCategory("Parameters")]
    [Gui.Design.DisplayName("Description Here")]
    [RefreshProperties(RefreshProperties.All)]
    public string InstrString
    {
    get { return instrString; }
    set { instrString = value;}
    }

    How do I do the same thing in NT8?

    Thanks,

    Lee

    #2
    Hello Lee,

    The attributes have changed from NinjaTrader 7 to NinjaTrader 8.
    Please see the help guide to see the available attributes along with examples of how to use them.


    Returning a private variable from a public variable is still possible with NT8 and that same code you have posted with some changes to the attributes would still work. However, in both NT7 or NT8, if the object is serializable already (such as string, int, double) you can choose not to return a private variable.

    A simple way to create a public input in NinjaTrader 8 looks like the following:
    Code:
    [NinjaScriptProperty]
    [Display(Name="InstrString", Description="Trade Instrument", Order=1, GroupName="NinjaScriptStrategyParameters")]
    public string InstrString
    { get; set; }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thank you for the info. The only issue I am having now is I can't get NT8 to use
      string InstrString = "SPY"; as a default to populate the strategy properties list like in NT7. I have it added under: protected override void OnStateChange()

      It's as if it is completely ignoring the string I added. And when I select the strategy for the chart, it gives me an error saying "Error on getting value for property "InstrString". Object reference not set to an instance of the object". If I select ok on the error window, I can then manually populate the string field and the strategy works fine. So I'm just trying to figure out how to put a default value in for "InstrString" so its not an empty field causing an error

      Thanks,

      Lee
      Last edited by lee612801; 08-12-2016, 11:28 AM.

      Comment


        #4
        Hello Lee,

        I would recommend that you try using the Strategy Builder to create an input to see how this looks in NinjaTrader 8.

        Attached is an example exported script that creates a string public input.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok, that was too easy. I just had to remove "string" from "string InstrString = "SPY";".

          Thank you for the help.

          Regards,

          Lee
          Last edited by lee612801; 08-12-2016, 01:11 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, Yesterday, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          191 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,230 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X