In all topics (like this: http://ninjatrader.com/support/forum...ad.php?t=83380 ) NT Support describes how to do that. However, that's theorical explanation, and can anyone give show the real example of code, how to do that?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
MTF (MultiTimeframe) Indicator example?
Collapse
X
-
MTF (MultiTimeframe) Indicator example?
I've seen several topic (searching solution for "Error on calling 'OnStateChange' method: 'AddChartIndicator' cannot be called from this state.).
In all topics (like this: http://ninjatrader.com/support/forum...ad.php?t=83380 ) NT Support describes how to do that. However, that's theorical explanation, and can anyone give show the real example of code, how to do that?Tags: None
-
Hello selnomeria,
Below I am including some publicly available links to the help guide.
An example would be:
Code:protected override void OnStateChange() { if (State == [B]State.DataLoaded[/B]) { AddChartIndicator(SMA(20)); } }
If you are trying to add additional series, these cannot reference the primary series.
Code:AddDataSeries(BarsPeriodType.Minute, 5);
From the help guide:
"Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."Chelsea B.NinjaTrader Customer Service
-
Multi-Timeframe Instances of Same Indicator
Hi ChlseaB,Originally posted by NinjaTrader_ChelseaB View PostHello selnomeria,
Below I am including some publicly available links to the help guide.
An example would be:
Code:protected override void OnStateChange() { if (State == [B]State.DataLoaded[/B]) { AddChartIndicator(SMA(20)); } }
If you are trying to add additional series, these cannot reference the primary series.
Code:AddDataSeries(BarsPeriodType.Minute, 5);
From the help guide:
"Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."
Can one use the AddDataSeries to plot a second instance of an indicator for a higher time frame on the same lower time frame chart?
For example, I have a simple 1M chart with ATR(14) plotted in panel 2. How can one plot a 5-minute ATR(14) superimposed on panel 2? Can the AddDataSeries be used here? Is there a sample indicator?
I know this is possible by plotting a supper imposed instance of a transparent 5M chart, then plot the ATR for the 5M chart. But, that is not what I am asking.
Many thanks.
Comment
-
Hello aligator,
Yes, you can add a series using a different time frame and use this for the input series of an indciator call and then add this to a chart with AddChartIndicator().
Below is a public link to an example of using an added series to an indicator.
Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful forChelsea B.NinjaTrader Customer Service
Comment
-
Thank you so much ChelseaB,Originally posted by NinjaTrader_ChelseaB View PostHello aligator,
Yes, you can add a series using a different time frame and use this for the input series of an indciator call and then add this to a chart with AddChartIndicator().
Below is a public link to an example of using an added series to an indicator.
https://ninjatrader.com/support/foru...ead.php?t=3572
The script is for a strategy and I only want indicators, but it got me started with this Multi_SMA indicator. It compiles but it will draw the two SMAs at zero. I am new to AddDatSeries, what is missing here please?
Many thanks.Code:namespace NinjaTrader.NinjaScript.Indicators { public class SMAMulti : Indicator { private Series<double> sma1; private Series<double> sma2; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Indicator will draw a secondarary sma for a different (i.e.5-min) timeframe"; Name = "SMAMulti"; IsOverlay = true; IsSuspendedWhileInactive = true; Period = 14; AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Line, "sma1"); AddPlot(new Stroke(Brushes.Red, 4), PlotStyle.Line, "sma2"); } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Minute, 5); } else if (State == State.DataLoaded) { // Syncs a DataSeries object to the primary bar object sma1 = new Series<double>(SMA(BarsArray[0], Period)); sma2 = new Series<double>(SMA(BarsArray[1], Period)); } } protected override void OnBarUpdate() { if (CurrentBar < Period) return; Value[0] = sma1[0]; Value[1] = sma2[0]; } #region Properties [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "Parameters", Order = 0)] public int Period { get; set; } #endregion } }
Comment
-
Hello aligator,
I can see where this example may have confused you as it creates its own series.
This example should be better.
You would need to call the SMA and pass the secondary series as the input series and assign the return indicator to a variable. Then call AddChartIndicator using that variable.Chelsea B.NinjaTrader Customer Service
Comment
-
ChelseaB,Originally posted by NinjaTrader_ChelseaB View PostHello aligator,
I can see where this example may have confused you as it creates its own series.
This example should be better.
You would need to call the SMA and pass the secondary series as the input series and assign the return indicator to a variable. Then call AddChartIndicator using that variable.
Fantastic, as always great support!
Many thanks.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
54 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
71 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|
Comment