Thanks
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
Indicator different time frame
Collapse
X
-
Indicator different time frame
Hi,is it possible have an indicator with a different time frame than the chart?
ThanksTags: None
-
Hello Italianforex,
Thank you for your post.
Yes, you can absolutely have an indicator plotting on a different time frame from your chart.
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 your indicator calculate on that secondary series, but apply it to plot over your primary data series.
Here is an example of how to plot an indicator based off of a 5 minute chart, but plotted over a 2 minute chart:
* 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 your own indicator that utilizes a secondary data series.
Here's a simple example that plots a 5 minute EMA over any other primary time frame using some best practices, including checking on the current bar, using BarsInProgress to plot on the primary data points, and using a private EMA variable to hold our EMA values from the secondary series:
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];
}
Here is a link to our help guide with additional information regarding working with multiple data series/time frames in NinjaScript:
If I may be of further assistance, please let me know.
Kate W.NinjaTrader Customer Service
- Likes 1
-
Hello gplatis,
Thank you for your post.
The first portion of my example, setting the chart up with two time frames and then hiding one, will work on both NT7 and NT8.
More information about working with multi-series scripts can be found here: https://ninjatrader.com/support/help...nstruments.htm
Here's an example for NT7:
Code:protected override void Initialize() { // adding a 10 minute series of the same instrument to the script Add(PeriodType.Minute, 10); } protected override void OnBarUpdate() { // make sure that all series contain enough bars before beginning // this is checking to see that each series contains at least one bar if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return; // in my example, I just want the stochastics D value of the primary series to be printed if the primary series is calling OnBarUpdate() and the stochastics D value of the secondary series to be printed if the secondary series is calling OnBarUpdate() if (BarsInProgress == 0) Print(Stochastics(BarsArray[0], 3, 14, 7).D[0]; if (BarsInProgress == 1) Print(Stochastics(BarsArray[1], 3, 14, 7).D[0];
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
- Likes 1
Comment
-
Originally posted by NinjaTrader_Kate View PostHello Italianforex,
Thank you for your post.
Yes, you can absolutely have an indicator plotting on a different time frame from your chart.
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 your indicator calculate on that secondary series, but apply it to plot over your primary data series.
Here is an example of how to plot an indicator based off of a 5 minute chart, but plotted over a 2 minute chart:
* 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 your own indicator that utilizes a secondary data series.
Here's a simple example that plots a 5 minute EMA over any other primary time frame using some best practices, including checking on the current bar, using BarsInProgress to plot on the primary data points, and using a private EMA variable to hold our EMA values from the secondary series:
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];
}
Here is a link to our help guide with additional information regarding working with multiple data series/time frames in NinjaScript:
If I may be of further assistance, please let me know.
Comment
-
Hello sashol3,
Thanks for your notes.
If you followed the first set of instructions, you could consider setting the candle color properties for the second data series candles to Transparent to 'hide' those candles.
Right-click on the chart window, select 'Data series', select the second data series on the left side of the Data Series window, use the 'Color for up bars' drop-down menu in the Properties section on the right to set the color to 'Transparent', use the 'Color for down bars' drop-down menu in the Properties section to set the color to 'Transparent', and click OK.
See the 'How to edit Data Series parameters' section of this help guide page for more information: https://ninjatrader.com/support/help...price_data.htmBrandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johnMoss, 03-04-2024, 01:53 PM
|
3 responses
43 views
0 likes
|
Last Post
by AndyM
Today, 06:13 PM
|
||
Started by algospoke, Today, 06:01 PM
|
0 responses
6 views
0 likes
|
Last Post
by algospoke
Today, 06:01 PM
|
||
Started by cre8able, Today, 05:53 PM
|
0 responses
6 views
0 likes
|
Last Post
by cre8able
Today, 05:53 PM
|
||
Started by Wessel, 03-23-2024, 02:37 PM
|
3 responses
23 views
0 likes
|
Last Post Today, 04:58 PM | ||
Started by martini, Yesterday, 04:45 PM
|
4 responses
32 views
0 likes
|
Last Post
by martini
Today, 04:48 PM
|
Comment