Could you please post some code showing how you add plots dynamically in Configure state? I've been tripping over something, but don't know what. Tried to do in Default and Configure state, yet no luck. http://ninjatrader.com/support/forum...ad.php?t=85229
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Adding Plots Dynamically
Collapse
X
-
Hi, gregid,Originally posted by gregid View Post
Could you please post some code showing how you add plots dynamically in Configure state? I've been tripping over something, but don't know what. Tried to do in Default and Configure state, yet no luck. http://ninjatrader.com/support/forum...ad.php?t=85229
-
Thanks Patrick
I forgot (again) that the same functionality would also be beneficial for Lines - as the same issue applies (I simply generate more plots than lines)
Leave a comment:
-
Hello gregid,
Thank you for your post.
I will forward to development.
Leave a comment:
-
adding Plots.Remove(Plot) and Plots.RemoveAll()
I have been successfully adding plots dynamically from Configure state for a while now.
There is only one caveat to the functionality - plots added in Configure state are never visible in the property grid. Since they are generated basing on other properties and Configure is executed only after pressing OK button it is understandable but I wanted to suggest a possible solution to make it possible to preview the plots in the property grid.
If Plots would have Remove method (ie. Plots.Remove(Plot) and Plots.RemoveAll() we could generate plots first in SetDefaults then in Configure remove all plots and generate them again (this time with changed settings). This would give us an option to eg. manually adjust generated plot details if desired.
So my question is - would it be possible to add these methods?
Leave a comment:
-
Update:Originally posted by NinjaTrader_Dierk View PostIt would accelerate the process of ironing out issues if you could post your requirements right away so we would not need to revisit similar issues again and again...
1) on AddLine: the same logic change will be applied there. Thanks for reporting
2) on PropertiesGrid: we will test the Apply logic
3) there is no need for a dictionary since you always could find a plot by name like this
Code:Plots.FirstOrDefault(p => name == "MyName")
on 2) Unfortunately not doable without significant under-the-hood changes which is why we will leave that.
Leave a comment:
-
That will also work, interestingly ToArray() doesn't have IndexOf yet Array does.Originally posted by NinjaTrader_Dierk View PostWhy not keeping things simple(have not tested though)?
Code:double d = Values[Array.IndexOf(Plots, Plots.First(p => p.Name == "MyName"))][0];
Thanks.
Leave a comment:
-
Why not keeping things simple(have not tested though)?
Code:double d = Values[Array.IndexOf(Plots, Plots.First(p => p.Name == "MyName"))][0];
Leave a comment:
-
Long time ago I did this with indexes but found it not estethically pleasing
Pure Linq would not be the most user friendly as IEnumerable doesn't have GetIndex natively implemented, so accessing values with pure Linq would be something like:
Fortunately there are Lists which have FindIndex so it gets simpler:Code:DynamicPlotsSMA(14,30).Values[Plots.Select((p, i) => new {Plot = p, Index = i}).Where(x => x.Plot.Name == "TestPlot").Select(x => x.Index)][0];
Still not great but I liked your challenge so here is extension class that makes it simple:Code:DynamicPlotsSMA(14,30).Values[Plots.ToList().FindIndex(p => p.Name == "TestPlot")][0];
Now my code looks like this:Code:namespace NinjaTrader.NinjaScript.Indicators { public static class PlotsExtension { public static int GetIndex(this IEnumerable<Plot> plots, string name) { return plots.ToList().FindIndex(p => p.Name == name); } public static Series<double> FindPlotValues(this Indicator ind, string name) { return ind.Values[ind.Plots.GetIndex(name)]; } } }
I'll have to check what is more performant but thanks for the challenge!Code:DynamicPlotsSMA(14,30).FindPlotValues("TestPlot")[0];
Leave a comment:
-
on 3): pls check out .Plots and .Values. They match -> you can find the right series in .Values by findings the right index in .Plots. Linq might come in handy... using a dictionary does not yield performance gains for a 'small' number of items in the collection.
The team works in different timezones...
Leave a comment:
-
Point takenOriginally posted by NinjaTrader_Dierk View PostIt would accelerate the process of ironing out issues if you could post your requirements right away so we would not need to revisit similar issues again and again...
3: not really - this brings only Plot object which doesn't hold Values (Series<T>) and that's the point of the dictionary -> to map plot to its valuesOriginally posted by NinjaTrader_Dierk View Post1) on AddLine: the same logic change will be applied there. Thanks for reporting
2) on PropertiesGrid: we will test the Apply logic
3) there is no need for a dictionary since you always could find a plot by name like this
Code:Plots.FirstOrDefault(p => name == "MyName")
Do you guys ever sleep?
Leave a comment:
-
It would accelerate the process of ironing out issues if you could post your requirements right away so we would not need to revisit similar issues again and again...
1) on AddLine: the same logic change will be applied there. Thanks for reporting
2) on PropertiesGrid: we will test the Apply logic
3) there is no need for a dictionary since you always could find a plot by name like this
Code:Plots.FirstOrDefault(p => name == "MyName")
Leave a comment:
-
Excellent! This is really a huge deal for me.Originally posted by NinjaTrader_Dierk View PostThat will be changed with next beta (#8198): you then could add plots even in state .Configure.
Thanks for reporting.
Just in case: I suppose AddLine will work from Configure as well?
If possible, the user friendly addition would be to refresh PropertyGrid on Apply if there has been changes introduced in Configure state (such as Plots, colors in my example). This is minor issue in comparison to the change you are making so I could live without it, but would be nice.
Also, whenever I work with dynamic plots I always implement in my code a dictionary which maps plot name to Values[x]:
this way I can easily request plot values by its name (crucial for dynamic plots) eg.Code:public Dictionary<string, Series<T>> PlotMap
I've found it to be extremely helpful so if you feel like implementing it yourself in the base class I wouldn't mindCode:DynamicPlotsSMA(14,30).PlotMap["sma17"][0]

Thanks again.
Leave a comment:
-
That will be changed with next beta (#8198): you then could add plots even in state .Configure.
Thanks for reporting.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by kinfxhk, 07-13-2026, 10:18 AM
|
0 responses
30 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 10:18 AM
|
||
|
Started by kinfxhk, 07-13-2026, 09:50 AM
|
0 responses
24 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 09:50 AM
|
||
|
Started by kinfxhk, 07-13-2026, 07:21 AM
|
0 responses
30 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 07:21 AM
|
||
|
Started by kinfxhk, 07-11-2026, 02:11 AM
|
0 responses
27 views
0 likes
|
Last Post
by kinfxhk
07-11-2026, 02:11 AM
|
||
|
Started by SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
141 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|

Leave a comment: