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
Calling AddDataSeries on both a hosted and hosting Indicator
Collapse
X
-
Thank you both so much. I was able to get it to work by using the tips given here in conjunction with making sure the GUEST Indicator explicitly returned a 0 when the GUEST was not set with some data yet.
-
Hi swcooke thanks for your reply.
I was able to get this to work. You're never filling your public series so the indicator calling it can not see the series.
Code:public class SampleLastEveryTick : Indicator { //public Series<double> sjClose; private double close; private int activeBar = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = "Test Indicatro"; Name = "SampleLastEveryTick"; BarsRequiredToPlot = 0; Calculate = Calculate.OnEachTick; DrawOnPricePanel = false; IsOverlay = false; DisplayInDataBox = true; } else if(State == State.Configure){ AddDataSeries("MSFT"); sjClose = new Series<double>(this); } } protected override void OnMarketData(MarketDataEventArgs e) { if(BarsInProgress == 0)return; if(e.MarketDataType == MarketDataType.Last) { close = e.Price; } } protected override void OnBarUpdate() { if(BarsInProgress != 0)return; if (CurrentBar < activeBar) //CurrentBar is -1 return; if (CurrentBar > activeBar) { activeBar = CurrentBar; } sjClose[0] = close; } [Browsable(false)] [XmlIgnore] public Series<double> sjClose; }
Please let me know if I can assist any further.
Leave a comment:
-
OnBarUpdate() in the HOST is only invoked when HOST changes occur. Behind the scenes NT makes sure that the GUEST indicator is synchronized and processed first. So checking for GUEST updates should not be needed.
With a second data input series there manual syncrhonization might be necessary, which was discussed here https://ninjatrader.com/support/foru...ther-indicator.
Synchronization is a difficult problem, if you don't want to deal with the complexity, it is easier to duplicate the GUEST code in the HOST instead of using a GUEST indicator.
Code duplication is undesirable, in case you're skilled enough you can move the logic of the GUEST to a third class and use it in the HOST and the GUEST.
Another way would be to add a reference to the HOST to the GUEST indicator.
Code:public class SampleLastEveryTick : Indicator { public CallBuySell HOST = null; ... protected override void OnBarUpdate() { ... if(HOST != null) HOST.process();
Code:public class CallBuySell : Indicator { ... else if (State == State.DataLoaded) { GUEST = SampleLastEveryTick(); GUEST.HOST = this; } ... public void process() { }
Last edited by MojoJojo; 02-20-2020, 02:20 AM.
Leave a comment:
-
Thanks MojoJojo,
One follow up question. Is there any way to only process updates from my GUEST? Conceptually, something like this:
Code:if(BarsInProgress == GUEST){ //do stuff }
Leave a comment:
-
Probably making sure that only the main data is being processed in the host is enough to get rid of the error.
Code:if(BarsInProgress != 0)return;
Code:if (GUEST.CurrentBars[0] < 0)return;
As long as the logic isn't too complicated and you want to have both the host and the guest indicator, it is in my opinion best to move the logic to a helper class and use it instead of the guest indicator.Last edited by MojoJojo; 02-19-2020, 08:46 AM.
Leave a comment:
-
Yes, it plots fine. I was careful in my post to point that out. The Indicator works well. I just can't call it. I can't see why the Print Statement would cause any issue but I commented it anyway and compiled and still see the error. I will take a look at the OrderFlow Indicator however, for the sake of seeing this with a really simple example, could you run my code and see if you are able to get it to work?
Leave a comment:
-
Hi swcooke, thanks for your note.
It might be coming from this print in the SampleLastEveryTick indicator:
Print(sjClose[1]); Does the SampleLastEveryTick indicator work on its own?
A good example would be the OrderFlow indicators. Those indicators add a 1 tick series, therefore all indicators using an OrderFlow+ indicator need to add the 1 tick series as well.
I look forward to hearing from you.
Leave a comment:
-
Calling AddDataSeries on both a hosted and hosting Indicator
I am reviewing the page about Multi-Time Frame and Instruments. Specifically, the section that talks about making sure you call AddDataSeries in State.Configure for both a hosting indicator and the hosted indicator. Is there an Indicator somewhere that best demonstrates how to do this? I have tried and can't seem to get it to work. Here is my host Indicator which is just supposed to provide the data for a hosting Indicator. Note that my issue is not with the data this indicator puts out. That is accurate. It's about calling it from a hosting indicator:
Code:public class SampleLastEveryTick : Indicator { private Series<double> sjClose; private double close; private int activeBar = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = "Test Indicatro"; Name = "SampleLastEveryTick"; BarsRequiredToPlot = 0; Calculate = Calculate.OnEachTick; DrawOnPricePanel = false; IsOverlay = false; DisplayInDataBox = true; } else if(State == State.Configure){ AddDataSeries("MSFT"); sjClose = new Series<double>(this); } } protected override void OnMarketData(MarketDataEventArgs e) { if(BarsInProgress == 0)return; if(e.MarketDataType == MarketDataType.Last) { close = e.Price; } } protected override void OnBarUpdate() { if(BarsInProgress != 0)return; if (CurrentBar < activeBar) //CurrentBar is -1 return; if (CurrentBar > activeBar) { Print(sjClose[1]); activeBar = CurrentBar; } sjClose[0] = close; } [Browsable(false)] [XmlIgnore] public Series<double> SjClose { get {return sjClose;} } }
Code:public class CallBuySell : Indicator { SampleLastEveryTick GUEST = null; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "CallBuySell"; Calculate = Calculate.OnEachTick; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; IsSuspendedWhileInactive = true; } else if(State == State.Configure){ AddDataSeries("MSFT"); } else if (State == State.DataLoaded) { GUEST = SampleLastEveryTick(); } } protected override void OnBarUpdate() { if (CurrentBar < 0)return; Print(GUEST.SjClose[0]); } }
Code:Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Last edited by swcooke; 02-18-2020, 04:40 PM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by frankthearm, Yesterday, 09:08 AM
|
14 responses
47 views
0 likes
|
Last Post Today, 02:19 PM | ||
Is it possible to have a drawing, such as a line, cycle through different colors?
by gentlebenthebear
Started by gentlebenthebear, Today, 01:30 AM
|
2 responses
13 views
0 likes
|
Last Post Today, 02:05 PM | ||
Started by Kaledus, Today, 01:29 PM
|
2 responses
8 views
0 likes
|
Last Post
by Kaledus
Today, 02:04 PM
|
||
Started by PaulMohn, Today, 12:36 PM
|
2 responses
16 views
0 likes
|
Last Post
by PaulMohn
Today, 01:48 PM
|
||
Started by Conceptzx, 10-11-2022, 06:38 AM
|
2 responses
56 views
0 likes
|
Last Post
by PhillT
Today, 01:47 PM
|
Leave a comment: