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;} }
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!
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
NinjaTrader
Resetting/changing defaults in State.Configure
Collapse
X
-
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: -
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:[B]T[/B]estVar = result;
Code:TestVar = bool.Parse(result);
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
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
-
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
-
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 dustydbayer, Today, 01:59 AM
|
0 responses
1 view
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
||
Started by inanazsocial, Today, 01:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by inanazsocial
Today, 01:15 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
22 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by Davidtowleii, Today, 12:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by Davidtowleii
Today, 12:15 AM
|
||
Started by guillembm, Yesterday, 11:25 AM
|
2 responses
10 views
0 likes
|
Last Post
by guillembm
Yesterday, 11:58 PM
|
Comment