Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Displaying Multiple timeframe indicators on a strategy
Collapse
X
-
Yeah, it seems so. I searched the Ninjatrader forums and found this for a related topic.
Note from the AddChartIndicator() 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)"
-
Looking at this more I realize that it does no display effectively because of how it processes bars. It doesnt really align them up to each other. the reason you get one not showing up when you do the lower time frame as the primary is because it just dumps out all the 1 min but does not space them out to align with the 30 second bars.
Leave a comment:
-
It seems that for display purposes using the larger 1 min time frame as the primary works better. Weird result if you do the lower first. Thanks for looking at this!
Leave a comment:
-
I'm wondering if it's the fact that I was on the 30 sec and the added time frame was the 1 min. It almost seemed like it was adding it's plots after every bar, so it ended halfway through. I tried to reverse it, and use the 1 min chart and added the 30 sec on there and now both show up from start to finish.
Leave a comment:
-
Ok. BarsArray is correct. I added the Print(BarsArray[1].BarsPeriod) to determine the type, and they are 30 sec and 1 min for Bars[1] and 2 respectively.
Leave a comment:
-
Where did you get this code? Do you have a copy of the original?
Leave a comment:
-
I'm not entirely sure. I haven't really worked with the stochastic too much, I added Prints when you calculate the .D[0] for both, but they don't seem to be adding up to the values being plotted on the charts, and there is that issue of it cutting off for the 1 min one.
Leave a comment:
-
Did you have to add any other configurations? Does it only need one data aeries? Sorry for the simple questions I'm kind of new to this.
Leave a comment:
-
Hmm..I've copy/pasted your code, and aside from needing to add a BarsRequired portion to the code, I found that I actually did get both to plot on the screen....sort of. I'm currently in playback mode and I only have data for one day, but both stochastics start at the same time, but the second one ends in the middle of the day. If you set your strategy and scroll to the beginning, do you see it plotting temporarily?
Leave a comment:
-
I'm not totally sure how to answering that. I built this from what comes with Ninja trader as an example for a multi time frame strategy. I'm not sure I totally understand. But I put this strategy on a 30 second chart. And only one stochastic shows up.
Leave a comment:
-
Do you only have those two data series? Or are you adding those two data series in addition to the one you already have? If it is only the two, then shouldn't it be BarsArray[0] and [1]?
Leave a comment:
-
I should add that at this point it seems that only one of the indicators is showing up. The first stochastic should come from the 30 second time frame and that is showing. The second stochastic should be calculated from the 1 min time frame, there is a frame fro it but it is empty,
Leave a comment:
-
Displaying Multiple timeframe indicators on a strategy
//
// Copyright (C) 2024, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleMultiTimeFrameTwoStochastics : Strategy
{
private Series<double> primarySeries;
private Series<double> secondarySeries;
private Stochastics fifteenSecNineStochastic;
private Stochastics OneMinNineStochastic;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
//Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMultiTimeFrameFourStoch;
Name = "SampleMultiTimeFrameTwoStochastics"; //NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleMultiTimeFrameFourStoch;
// This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = false;
}
else if (State == State.Configure)
{
// Add a 15 minute Bars object to the strategy
AddDataSeries(Data.BarsPeriodType.Second, 30);
// Add a 5 minute Bars object to the strategy
AddDataSeries(Data.BarsPeriodType.Minute, 1);
}
else if (State == State.DataLoaded)
{
fifteenSecNineStochastic = Stochastics(BarsArray[1], 3,9,1);
fifteenSecNineStochastic.IsOverlay = false;
fifteenSecNineStochastic.Panel = 2;
AddChartIndicator(fifteenSecNineStochastic);
OneMinNineStochastic = Stochastics(BarsArray[2],3, 14,1);
OneMinNineStochastic.IsOverlay = false;
OneMinNineStochastic.Panel = 3;
AddChartIndicator(OneMinNineStochastic);
}
}
protected override void OnBarUpdate()
{
if (OneMinNineStochastic.D[0] < 20 && fifteenSecNineStochastic.D[0] < 20)
{
Draw.ArrowUp(this, "SwingHigh_" + CurrentBar, false, 0, Low[0] - TickSize * 2, Brushes.Green);
}
}
}
}
[/CODE]Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by hunghnguyen2016, Today, 08:00 PM
|
0 responses
6 views
0 likes
|
Last Post
![]() |
||
Started by cbentrikin, Today, 03:49 PM
|
0 responses
11 views
0 likes
|
Last Post
![]()
by cbentrikin
Today, 03:49 PM
|
||
Started by MiCe1999, 04-14-2025, 06:54 PM
|
7 responses
75 views
0 likes
|
Last Post
![]()
by b.j.d
Today, 03:45 PM
|
||
Started by NISNOS69, Today, 02:20 PM
|
0 responses
18 views
0 likes
|
Last Post
![]()
by NISNOS69
Today, 02:20 PM
|
||
Started by hunter7, Today, 01:09 PM
|
0 responses
26 views
0 likes
|
Last Post
![]()
by hunter7
Today, 01:09 PM
|
Leave a comment: