Thanks!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Plotting Multiple Timeframes
Collapse
X
-
Plotting Multiple Timeframes
Is there a way to plot a SMA(5) on the 1 minute chart for the 1, 5, and 15 minute timeframe? I've seen it done on other platforms and I was wondering if it works here. I have code that should be outputting, but it simply refuses to add the other timeframes to the chart I'm on. I'm wondering if NT isn't set up to do that. Or if it is, how...
Thanks!Tags: None
-
Hello alphatango,
Thank you for your post.
Yes, you can do so with AddPlot(). Set the Value for the plot to the value of your 1, 5, or 15 minute SMA.
For example,
Please let us know if you have any further questions.Code:protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "Examples Indicator"; AddPlot(Brushes.Blue, "SMA1"); AddPlot(Brushes.Red, "SMA2"); } if (State == State.Configure) { AddDataSeries(BarsPeriodType.Minute, 5); } } protected override void OnBarUpdate() { //plot using primary data series for the SMA SMA1[0] = SMA(BarsArray[0], 14)[0]; //plot using secondary 5 minute series for the SMA SMA2[0] = SMA(BarsArray[1], 14)[0]; } [Browsable(false)] [XmlIgnore] public Series<double> SMA1 { get { return Values[0]; } } [Browsable(false)] [XmlIgnore] public Series<double> SMA2 { get { return Values[1]; } }
-
It threw up a ton of errors over the "browsable" section. I imagine that's part of a declaration. Which one is that part of? Why would it say 'Type or Namespace name 'BrowsableAttribute' could not be found..."?
This is what I have. The first 2 show up just fine. The other 4 show up in the "indicators" information but never manifest on the chart. I'm certain it's a syntax thing or just needs to be placed elsewhere. It's part of a Strategy, but I would like it added to the chart with the strat. Lmk what I am missing.
Code:else if (State == State.DataLoaded) { // Instantiate indicators sma5B0 = SMA(BarsArray[0], 5)[0]; sma50B0 = SMA(BarsArray[0], 50)[0]; sma5B1 = SMA(BarsArray[1], 5)[0]; sma50B1 = SMA(BarsArray[1], 50)[0]; sma5B2 = SMA(BarsArray[2], 5)[0]; sma50B2 = SMA(BarsArray[2], 50)[0]; // Add indicators to the chart with specified colors sma5B0.Plots[0].Brush = Brushes.GreenYellow; sma50B0.Plots[0].Brush = Brushes.Green; sma5B1.Plots[0].Brush = Brushes.Yellow; sma50B1.Plots[0].Brush = Brushes.Goldenrod; sma5B2.Plots[0].Brush = Brushes.Orange; sma50B2.Plots[0].Brush = Brushes.Red; // Add indicators to the chart AddChartIndicator(sma5B0); AddChartIndicator(sma50B0); AddChartIndicator(sma5B1); AddChartIndicator(sma50B1); AddChartIndicator(sma5B2); AddChartIndicator(sma50B2);Last edited by alphatango; 08-16-2024, 12:55 PM.
Comment
-
Hello alphatango,
Apologies, I was under the impression you were creating an indicator as this is posted in the Indicators section of the forum.
AddChartIndicator() will only use the primary data series. This is noted in the Help Guide:
"An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)"
As far as the errors, are you seeing compile errors? If so, send a screenshot of the error long with the lines of code referenced in the error.
Comment
-
The errors are for this
It doesn't like any of this.Code:[Browsable(false)] [XmlIgnore] public Series<double> SMA1 { get { return Values[0]; } }
Also yes. It is the indicator portion of the strategy. I didn't think it would be any different. It's all good.
If "AddChartIndicator" Is only for the primary data series, is there a way to plot things from other data series' we've added?Last edited by alphatango; 08-16-2024, 04:01 PM.
Comment
-
Hello alphatango,
Can you please post the entire compile error along with the exact line of code it is referencing?
If you want to use AddChartIndicator() with other data series, you would need to do as the Help Guide instructs:
""An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)"
You'd need to create copies of the SMA indicator that use the series you want.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
600 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
346 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment