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

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, 08: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.



        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 Barry Milan, Yesterday, 10:35 PM
                5 responses
                16 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                12 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                11 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                8 views
                0 likes
                Last Post nandhumca  
                Working...
                X