Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Multi timeframe ema
Collapse
X
-
Hi,
You can check again the post #2, the second method could be useful for you. Values[2] is not used in this method but you have the same output parameters in OnBarUpdate() code.
-
Hi,
How do i get access to a secondary dataseries, ie Values[2] from the SMA object
//class level variable
private SMA mySMA;
//State.Configure
AddDataSeries(BarsPeriodType.Minute, 15);
//State.DataLoaded
mySMA = SMA.SecondarySeries(BarsArray[1], 20); // how do get Values[2][0] from the SMA object?
Edit : I worked that out with the following;
Code:// Global Objects private Indicator _Ex5min private Series<double> Bar_info_5m; else if (State == State.DataLoaded) { var Ex5min = ExIndicator();// 1. add the indicator to a local varable : its calculations are all based of 5 minute data series Bar_info_5m = Ex5min.Series; // 2. access the series from the ind. & send it to a global series _Ex5min = Ex5min; // 3. Now store the indicator in a global indicator object }
The indicator or 'class' that i built (that i'm trying to import) has all of its calculations based on the 5m dataseries.
> if i load it directly of a 5m chart to test, it works well on a 5minute chart.
But... when i change it to primary bars array to a 1 minute , then the indicator's values distort.
That same problem is occurring, when, when i import it into the new script & display it on a 1 minute chart.
* since all of the calculations are based on the 5 minute data series, i was hoping the timeframe i display it on would be irrelevant & not distort the calculations.
Is there a known solution for this?
Thanks.Last edited by yertle; 07-11-2024, 11:55 AM.
Leave a comment:
-
Originally posted by NinjaTrader_Kate View PostHello chartish,
Thank you for your post.
You could do this in one of two ways. One would be to use a secondary data series on the chart and simply have the EMA calculate on that secondary series, but apply it to plot over your primary data series.
To add an indicator based off of a 5 minute chart, plotted over a 2 minute chart, please follow the instructions below:
* First create a 2 minute chart as usual (File>New>Chart...)
* Right click within your chart window and select Data Series...
* Add a second data series, the same instrument as your 2 minute chart, but set the parameters to be a 5 minute chart
* You should now see two-paneled chart with 2 minute on top and 5 minute below
* Next, right click and select Indicators... Find your indicator in the top left hand corner, and click New to add it.
* In the parameters to the right, set your Input Series to your 5 minute data series (Close)
* Set your Panel to 1,and click OK
* Next, move your pointer to the right of your price axis (y-axis) on the top panel of your chart window, and right click>Maximize.
You now should see a 2 minute chart, with an indicator plotted over it based off of a 5 minute Data series.
Your other option would be to create an indicator as you've started doing.
You are basically assigning the ema data series to current bar of the plot, so all you theoretically need is to change that line to this:
Value[0] = EMA(Closes[1], 20)[0];
However, working with multiple data series is a bit more complicated than using a single data series in an indicator.
Here's a simple example using some better practices, including checking on the current bar, using BarsInProgress to plot on the 2 minute data points, and using a private EMA variable to hold our EMA values from the secondary series. (I've attached the full code for this below):
private EMA EMA1; // we create a new array of EMA values
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "EMAon5minData";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(Brushes.LightCoral, "EMAPlot");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 5); //add our secondary 5 minute data series for calculating the EMA
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(BarsArray[1], 20); //set EMA here so we make sure it's calculated on the secondary data series
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1 || CurrentBars[1] < 20) // make sure there's at least one bar for primary series and at least 20 of the secondary series prior to processing
return;
if(BarsInProgress == 0) // if OnBarUpdate was called from the primary bar series, then set the current value to the latest EMA1 value
Value[0] = EMA1[0];
}
If I may be of further assistance, please let me know.
Leave a comment:
-
Hello leonardomocci,
Thanks for your notes.
If you are calling AddDataSeries() and are calculating the SMA in the script based on the BarsArray of the added series, the SMA would calculate from that added series, not from the primary series.
For example:
//class level variable
private SMA mySMA;
//State.Configure
AddDataSeries(BarsPeriodType.Minute, 15);
//State.DataLoaded
mySMA = SMA(BarsArray[1], 20);
See this help guide page for more information about Multi-TimeFrame/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
Leave a comment:
-
Hey guys. I did the simple solution using data series to plot a 15min 20SMA on a 5min chart, but if I change time frames to the 15min on this 5min chart and then return to 5min, that 15min 20SMA is now 5min 20SMA... is there anyway to fix this; I mean, to be able to change timeframes without having to plot it all again on the data series?
Thanks
Leave a comment:
-
Hello satmatw,
Thanks for your notes.
This is the expected behavior of the EMAon5minuteData script shared on post # 2 when it is applied to the chart window with a lower timeframe, such as a 1-minute chart.
If the script is applied to a higher timeframe chart, such as a 10-minute chart, the indicator will not display as 'steps'.
Leave a comment:
-
-
Originally posted by NinjaTrader_Kate View PostHello russ4444h,
Thank you for your reply.
Yes, you can modify the indicator (either the version for NinjaTrader 7 or NinjaTrader 8 above). The only necessary change would be the added data series.
For the NinjaTrader 7 version:
Add(PeriodType.Minute, 5);
Would need to be changed to
Add(PeriodType.Tick, 10000);
For NinjaTrader 8:
AddDataSeries(Data.BarsPeriodType.Minute, 5);
Would need to be changed to
AddDataSeries(Data.BarsPeriodType.Tick, 10000);
That should be all that's necessary to change to have this calculate off a 10000 tick series.
Please let us know if we may be of further assistance to you.
Leave a comment:
-
Hello russ4444h,
Thank you for your reply.
Yes, you can modify the indicator (either the version for NinjaTrader 7 or NinjaTrader 8 above). The only necessary change would be the added data series.
For the NinjaTrader 7 version:
Add(PeriodType.Minute, 5);
Would need to be changed to
Add(PeriodType.Tick, 10000);
For NinjaTrader 8:
AddDataSeries(Data.BarsPeriodType.Minute, 5);
Would need to be changed to
AddDataSeries(Data.BarsPeriodType.Tick, 10000);
That should be all that's necessary to change to have this calculate off a 10000 tick series.
Please let us know if we may be of further assistance to you.
Leave a comment:
-
I'm looking for this exact same thing, but I'd like to have a 10000 tick chart 20 EMA on my 2000 Tick chart. Is there a way to change this indicator?
Leave a comment:
-
Hello UltraNIX,
Thank you for your reply.
You're perfectly welcome to modify the indicator, however, it is intended as an example - a jumping off point to design your own logic. You could certainly make modifications to allow you to select the price type. However, for your second item I would caution that dynamically adding data series is unsupported and could result in errors.
Please let us know if we may be of further assistance to you.
Leave a comment:
-
NinjaTrader_Kate can we expand this indicator in 2 ways:
1) select price type (open / high / low / close) - (now it's CLOSE)
2) select more data series options (like Minute/Hour/Day/Week/Month/Year + Value (like Minute + 1 = 1 minute/ Hour + 4 = 4 hour).
So this way we would be able to access multiple time frames data from strategy without adding data series and refactoring code,
Leave a comment:
-
Thank you for the quick response. Your attached code worked perfectly. Exactly what I needed.
Thanks again.
Leave a comment:
-
Hello goodspirit,
Thank you for your note.
This post is in the NinjaTrader 8 section of the forum and the example is for NinjaTrader 8 and is not compatible with NinjaTrader 7 due to large changes in NinjaScript between the two versions. However, I have created a version for NinjaTrader 7 as well.
Please let us know if we may be of further assistance to you.Attached Files
Leave a comment:
-
NinjaTrader 7 says that the above file "EMAon5minuteData.zip" is corrupted and cannot be opened. Can you send me a clean version for NT 7?
Thanks.
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by sclay115, 02-10-2025, 03:58 PM
|
4 responses
20 views
0 likes
|
Last Post
![]()
by sclay115
Today, 04:17 PM
|
||
Started by MikeTR, Today, 03:55 PM
|
0 responses
2 views
0 likes
|
Last Post
![]()
by MikeTR
Today, 03:55 PM
|
||
Started by sclay115, Today, 02:14 PM
|
0 responses
4 views
0 likes
|
Last Post
![]()
by sclay115
Today, 02:14 PM
|
||
Started by helmutmedina, Today, 01:57 PM
|
0 responses
6 views
0 likes
|
Last Post
![]()
by helmutmedina
Today, 01:57 PM
|
||
Started by renosdim01, 02-13-2025, 05:46 AM
|
2 responses
18 views
0 likes
|
Last Post
![]()
by renosdim01
Today, 01:43 PM
|
Leave a comment: