• 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

How to choose setup multiple sets of Parameters

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

    How to choose setup multiple sets of Parameters

    Hi,

    I would like to have different sets of parameters that I can preselect via a string input for multiple instruments. Here is an example of what I am trying to do:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Strategy Name";
    Name = "Name";
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TradeInstrument = "SPY";

    if (TradeInstrument == "SPY")
    {
    Parameter1 = 10;
    Parameter2 = 100;
    Parameter3 = 200;
    }

    if (TradeInstrument == "IVV")
    {
    Parameter1 = 20;
    Parameter2 = 50;
    Parameter3 = 200;
    }


    #region Properties

    [NinjaScriptProperty]
    [Display(Name="TradeInstrument", Description="Enter Instrument Ticker To Trade", GroupName="NinjaScriptParameters", Order = 1)]
    public string TradeInstrument
    { get; set; }


    The problem is I cannot get it to change from the default that is set. So if I have it set to say SPY, even changing the input does not change to the other set of parameters. Is there a way to do this? Any help would be greatly appreciated.

    Thank you,
    Lee
    Last edited by lee612801; 07-03-2017, 07:54 AM.

    #2
    Hello Lee,

    Thanks for opening the thread.

    It is possible to override the values that are set in the parameters window. I would suggest to do this in State.DataLoaded where class level variables are initialized. State.SetDefaults is intended to push the default parameters to the UI.

    Keep in mind that it would not be possible to add a separate data series dynamically based off of a parameter. Additional data series must be hard coded in the strategy or indicator. You could use a string parameter to select a different data series that you have hard coded in, however.

    I will attach links to the documentation on OnStateChange() and the NinjaScript Lifecycle for further reference.

    OnStateChange() - https://ninjatrader.com/support/help...tatechange.htm

    NinjaScript Lifecycle - https://ninjatrader.com/support/help...fecycle_of.htm

    Caveats and documentation on using additional data series can be found here as well.

    AddDataSeries() -https://ninjatrader.com/support/helpGuides/nt8/en-us/?onstatechange.htm

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      Thanks for the response. I've added the State.DataLoaded as you suggested and am not trying to add another data series, just load a different set of parameters based on the string. Here is what I have:

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Strategy Name";
      Name = "Name";
      TradeInstrument = "SPY";
      Parameter1 = 10;
      Parameter2 = 100;
      Parameter3 = 200;
      }

      else if (State == State.Configure)
      {

      }

      else if (State == State.DataLoaded)
      {

      if (TradeInstrument == "SPY")
      {
      Parameter1 = 10;
      Parameter2 = 100;
      Parameter3 = 200;
      }

      if (TradeInstrument == "IVV")
      {
      Parameter1 = 20;
      Parameter2 = 50;
      Parameter3 = 200;
      }
      }

      After doing this, it shows the default values for the string and parameters in the strategy window, but when I go to enable the strategy, nothing happens. It just flashes and won't enable the strategy. Any ideas?

      Comment


        #4
        Hello Lee,

        Thanks for the reply.

        Without the full code I am unable to reproduce the issue you are encountering. I have created a short video demonstrating how changing parameter values can be done and I have attached the code I used so you can test on your end.

        https://www.screencast.com/t/eGViwqf8d

        Keep in mind that we do not write or debug code for our clients and this sample is meant as a demonstration. If you would like to hire someone to assist in debugging your code, you can write in to platformsupport[at]ninjatrader[dot]com with the text "Attention Jim" and the thread URL. I could then connect you with our Business Development team who can pass over a list of Certified NinjaScript Consultants who would be happy to help debug the code.

        Please let me know if you have further questions or if I may be of further assistance.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by lee612801 View Post
          Hi Jim,

          Thanks for the response. I've added the State.DataLoaded as you suggested and am not trying to add another data series, just load a different set of parameters based on the string. Here is what I have:

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Strategy Name";
          Name = "Name";
          TradeInstrument = "SPY";
          Parameter1 = 10;
          Parameter2 = 100;
          Parameter3 = 200;
          }

          else if (State == State.Configure)
          {

          }

          else if (State == State.DataLoaded)
          {

          if (TradeInstrument == "SPY")
          {
          Parameter1 = 10;
          Parameter2 = 100;
          Parameter3 = 200;
          }

          if (TradeInstrument == "IVV")
          {
          Parameter1 = 20;
          Parameter2 = 50;
          Parameter3 = 200;
          }
          }

          After doing this, it shows the default values for the string and parameters in the strategy window, but when I go to enable the strategy, nothing happens. It just flashes and won't enable the strategy. Any ideas?
          What is the error, if any, in your log?

          Comment


            #6
            Hi Jim/Koganam,

            Thank you for the video and help. I got it to work. I looked at the output and noticed I had a stray BarsRequiredToTrade in the wrong state when I was moving things around that was preventing it from working. I removed it and used the same format Jim showed in the video, and not it works!

            Thanks for all the help, I have been trying to figure out how to do this for a long time.

            Best Regards,
            Lee

            Comment


              #7
              Hi Jim,

              How would I do the same approach on NT7? What is the NT7 version of the State == State.DataLoaded?

              Thanks,
              Lee

              Comment


                #8
                Originally posted by lee612801 View Post
                Hi Jim,

                How would I do the same approach on NT7? What is the NT7 version of the State == State.DataLoaded?

                Thanks,
                Lee
                Use OnStartUp() in NT7. Even in NT8, State.Configure might be a better place to do that which you want to do.

                ref: https://ninjatrader.com/support/help...?onstartup.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by saltminer, Today, 05:19 PM
                0 responses
                3 views
                0 likes
                Last Post saltminer  
                Started by martyn73, Today, 04:18 PM
                0 responses
                2 views
                0 likes
                Last Post martyn73  
                Started by aprendiz, Today, 03:42 PM
                0 responses
                2 views
                0 likes
                Last Post aprendiz  
                Started by 1001111, Today, 09:10 AM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by usero86, Today, 06:02 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Working...
                X