• 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

Resetting/changing defaults in State.Configure

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

    Resetting/changing defaults in State.Configure

    I would like to know the proper design pattern for when to fetch something from a url that is going to be used as a setting. Here is what I have right now:

    Code:
    bool testVar;
    if (State == State.SetDefaults) {
        //this should show when the user selects the indicator but does not load it
        testVar = false;
    }else if (State == State.Configure) {
        string result = string.Empty;
        string url = @"http://167.99.146.72/es-weights";
    
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.AutomaticDecompression = DecompressionMethods.GZip;
    
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        using (Stream stream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(stream))
        {
            result = reader.ReadToEnd();
        }
        //http request returns true
        Print(result);
        //how can I change the UI from false to true?
        testVar = result;
    
    }
      [Display(Name = "Test", Order = 0, GroupName = "General Settings")]
      public bool TestVar{
        get {
          return testVar;
        }
        set{testVar = value;} 
      }
    The result of my http GET is a string "true" which I am trying to use to set the default value of the UI. In other words, I want one set of default settings to show when the user is in the SetDefaults state. But once the user commits to using the Indicator and the state switches to Configure, I want to fetch the correct setting from a URL and change it in the user interface.

    #2
    Hello swcooke,

    Does this work as you would expect if you instead use the public property? You are currently setting the backing field which would not update the UI but only store the value for later use.

    Does the following change your result?

    Code:
    TestVar = result;
    Also you noted this is a string, you may need to parse this into a bool before setting it:
    Code:
    TestVar  = bool.Parse(result);
    Please ensure to completely remove the indicator instance and reapply it while testing code changes in OnStateChange as well.


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

    Comment


      #3
      If I put the HTTP request aside and just try to set the public property to something different in State.Configure, it still will not work.

      Code:
      // Putting this in State.Configrue will not change it from false which was set in State.SetDefaults
      TestVar = true;

      Comment


        #4
        Hello swcooke,

        Thank you for clarifying.

        What you explained in post 1 should be what is happened now when using the Public property specifically and not the backing field. You can affect the default the user sets in the indicator menu by changing its value in State.Configure as you are doing now, however, this would only be visible after the menu is closed or in the chart specifically.

        If you have the indicators Label displayed in the chart, you should see the indicators public property value to "true" after the http request. However, when you re-open the indicator's menu, you should see the updated value being displayed. By nature what you are doing is not going to be possible from State.Configure to update the SetDefaults UI. You would either need to do the web request in State.SetDefaults, or you would need to indicate this in some way in the chart which could include the indicators label or other text/drawings.


        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 10-01-2018, 11:02 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Is this kind of thing typically done in State.Defaults? I can't imagine other developers don't make http requests for settings like this. Where do they typically do it?

          Comment


            #6
            Hello swcooke,

            It would really depend on the scope of what this is supposed to do. I can't imagine that there are a lot of web requests being done from SetDefaults specifically unless it was to get a default setting from a server. Even in that case, you have done what would be suggested or move that logic to Configure. SetDefaults is called for all indicators when you open the window so it would be called very frequently which may slow the menus down.

            You should see an update in the chart after the user selects the new setting and clicks either OK or Apply. This would also reflect the new configured default should the user reopen the indicator's menu. The only part which would not reflect would be the existing SetDefaults where the user is currently working on the settings.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by futurenick, Today, 06:26 AM
            1 response
            7 views
            0 likes
            Last Post nkhoi
            by nkhoi
             
            Started by NinjaCustomer, Today, 12:29 PM
            0 responses
            1 view
            0 likes
            Last Post NinjaCustomer  
            Started by Steve L, Today, 11:32 AM
            0 responses
            2 views
            0 likes
            Last Post Steve L
            by Steve L
             
            Started by prabbala, Today, 10:41 AM
            0 responses
            2 views
            0 likes
            Last Post prabbala  
            Started by bebbus, Today, 10:36 AM
            0 responses
            3 views
            0 likes
            Last Post bebbus
            by bebbus
             
            Working...
            X