Tom
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
Generate plot from external data Ninjascript
Collapse
X
-
Generate plot from external data Ninjascript
Hello forum. This is my first post as I have just started using NT8. I have an external program that generates a data point every 1 min. I am looking to generate a plot of these data points and overlay it on a ninja trader chart using Ninjascript and C#. I did not see any information regarding the external data attach/import portion. I did see the Series<T> as a possible data structure to store the data points. If anyone has advice, snippets or links, it would be greatly appreciated.
TomTags: None
-
Hello Tom,
Thanks for your post and welcome to the NinjaTrader forums!
I would suggest writing your data to a text file and then create an indicator that can read that file and put your data into a custom series which you can then perform any function from there such as plotting. A custom series would contain an element for every bar in the charts data series.
Here is a link to an example of reading a text file: https://ninjatrader.com/support/help...o_read_fro.htm
Here is a link for custom series: https://ninjatrader.com/support/help...8/?seriest.htm
Plots: https://ninjatrader.com/support/help...8/?addplot.htm
Paul H.NinjaTrader Customer Service
-
Hi Paul. Thanks for the reply and information. What I was able to do was use the NewtonSoft Json Deserializer to import my data into HistoryDataPoint[] history. What I have is a series of 30min data points that I now want to make into a plot. I am not sure how to take my HistoryDataPoint[] history and store them in the Values[0] series in OnBarUpdate. The included code is minimized to keep it to just the meat. Also I was originally using this Json dll (System.Text.Json) but it worked in VS but not in Ninjascript.
Code:private Series<double> myDoubleSeries; else if (State == State.Configure) { AddPlot(new Stroke(Brushes.Red, 1), PlotStyle.Line, "Import"); } else if (State == State.DataLoaded) { myDoubleSeries = new Series<double>(this, MaximumBarsLookBack.Infinite); string jsonString = File.ReadAllText("D:\\testdata\\data.json"); lastAdharaResponse = JsonConvert.DeserializeObject<QueryProjectionHistoryResponse>(jsonString); QueryProjectionHistoryResults results = lastAdharaResponse.results; HistoryDataPoint[] history = results.projHistory; //Holds the array of imported data points from deserialized json file Print("HistoryDataPoint[] history = results.projHistory;"); // Loop to extract one set (See attached Output) -------------------------------------------- for (int i = 0; i < history.Length; i++) { Print(history[i].unresolvedPricePrediction.ToString()); } -------------------------------------------- OnBarUpdate Value[0] = ?
Thanks.
Tom
Comment
-
Hello Tom,
Thanks for your reply.
Does your generated data also provide a time stamp?
If so then you could compare the timestamp of the current bar being processed and then pull that data point from your data.
When you apply the indicator to the chart, the script will begin processing on the very first historical bar in the data series, which at that moment would be the current bar. Once the end of your code is reached, the next bar is loaded and again the script will be executed, etc, etc, until it reaches real-time data or the end of historical bars. You can access the DateTime of the bar with Time[0]. Reference: https://ninjatrader.com/support/help...timeseries.htm
Paul H.NinjaTrader Customer Service
Comment
-
Comment
-
Paul. That was perfect, thank you. Additionally I want to be able to extend my plots to the right past the current bar as I don't get updates except on the half hour. On smaller time frames the new bars after update say on the 5 min don't have the plots up to them. Is there a way to do this? In the attached picture I want to extend the plot lines 5 bars to the right of the current bar. This section will be the last data point used to make this section of the plot a straight line. When the next update comes the data points will be refreshed with correct data and extend again.
Thanks.
Tom
Comment
-
Hello Tom,
Thanks for your reply.
We don't have a means for the plots to extend into the future.
With the smaller time frames, I would plot during BarsInProgress 0 (which is when the bar on the chart plot) and then your indicator will be plotted with a straight line until the next 30-minute update changes the value.
Another alternative would be to draw a temporary line using Draw.Line() method. While we do not recommend drawing into the future, with these methods it can be done by using a negative bars ago. Reference: https://ninjatrader.com/support/help...?draw_line.htm
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
27 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:33 PM
|
||
Started by wzgy0920, 04-23-2024, 09:53 PM
|
2 responses
49 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:29 PM
|
||
Started by Kensonprib, 04-28-2021, 10:11 AM
|
5 responses
193 views
0 likes
|
Last Post
by Hasadafa
Yesterday, 10:19 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,235 views
0 likes
|
Last Post Yesterday, 08:07 PM |
Comment