NT8 - Multi Instrument Indicators - futures io
futures io futures trading



NT8 - Multi Instrument Indicators


Discussion in NinjaTrader

Updated
    1. trending_up 4,952 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 13 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

NT8 - Multi Instrument Indicators

(login for full post details)
  #1 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received

Has anyone tried writing a multi instrument/spread indicator in NT8?

I was wondering if there was a way to add a secondary series which takes on the BarsPeriodType and BarsPeriod of the primary series without having to hardcode.

Used to be able to do this in NT7 using something like:

 
Code
Add("XYZ", BarsPeriods[0].Id, BarsPeriods[0].Value);
But in NT8, the following just gives me errors:

 
Code
AddDataSeries("XYZ", BarsPeriods[0].BarsPeriodType, BarsPeriods[0].Value);
Does anyone know of a better way?

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
What blockvolume is visible? - order processing
NinjaTrader
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
COTbase for quant trading?
Elite Algorithmic NinjaTrader Trading
How to implement this?
MultiCharts
MACD line not plotting after change of plot order
NinjaTrader
 
 
(login for full post details)
  #3 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


Your syntax is incorrect.

For the correct syntax see:
NinjaTrader 8

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received


choke35 View Post
Your syntax is incorrect.

For the correct syntax see:
NinjaTrader 8

Thanks for your response. I don't think the syntax is incorrect as I have already made the code-breaking adjustments required from NT7 to NT8 and it compiles fine.

The problem is that the primary bars have not been loaded yet by State.Configure (where you are supposed to add additional data series) so you can't really reference them by means of BarsPeriods[0].BarsPeriodType and BarsPeriods[0].Value. In NT7 I used to be able to do this within Initialize().

For an indicator which I'd like to have work on both a daily and minute bar strategy, it's quite annoying having to hard code two separate versions (even more needed if you use different minute bars and you'd like both minute data series the same).

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


wuileng View Post
Thanks for your response. I don't think the syntax is incorrect as I have already made the code-breaking adjustments required from NT7 to NT8 and it compiles fine.

The problem is that the primary bars have not been loaded yet by State.Configure (where you are supposed to add additional data series) so you can't really reference them by means of BarsPeriods[0].BarsPeriodType and BarsPeriods[0].Value. In NT7 I used to be able to do this within Initialize().

For an indicator which I'd like to have work on both a daily and minute bar strategy, it's quite annoying having to hard code two separate versions (even more needed if you use different minute bars and you'd like both minute data series the same).

No hardcoding needed; think you didn't get different syntax options right ...

Esp for spreads try (within State.Configure)

AddDataSeries(secondInstrument, BarsPeriod.BarsPeriodType, barValue, Data.MarketDataType.Last);

where barValue is
barValue = Math.Max(1, base.BarsPeriod.Value);

Reply With Quote
 
(login for full post details)
  #6 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received


choke35 View Post
No hardcoding needed; think you didn't get different syntax options right ...

Esp for spreads try (within State.Configure)

AddDataSeries(secondInstrument, BarsPeriod.BarsPeriodType, barValue, Data.MarketDataType.Last);

where barValue is
barValue = Math.Max(1, base.BarsPeriod.Value);

Thanks again for your help.

I just tried your syntax, and am getting the same error I was getting using my syntax:


Quoting 
Indicator 'MyIndicator': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

When I do not reference anything to do with BarsPeriod or BarsPeriods though (and hardcode), it works fine. Have you tried it on the latest version of the beta?

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


wuileng View Post
Thanks again for your help.

I just tried your syntax, and am getting the same error I was getting using my syntax:



When I do not reference anything to do with BarsPeriod or BarsPeriods though (and hardcode), it works fine. Have you tried it on the latest version of the beta?

I use exactly the above snippet for spreads in the latest NT8 version.
Please post your State.Configure.

Reply With Quote
 
(login for full post details)
  #8 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received


choke35 View Post
I use exactly the above snippet for spreads in the latest NT8 version.
Please post your State.Configure.

 
Code
else if (State == State.Configure)
{
	int barValue = Math.Max(1, base.BarsPeriod.Value);
	AddDataSeries(RefInstrument, base.BarsPeriod.BarsPeriodType, barValue, Data.MarketDataType.Last);
	//AddDataSeries(RefInstrument, BarsPeriods[0].BarsPeriodType, BarsPeriods[0].Value);
	//AddDataSeries(RefInstrument, BarsPeriodType.Minute, 5);
	
	Calculate			= Calculate.OnBarClose;
	IsOverlay			= false;
	DrawOnPricePanel    = true;
	DisplayInDataBox    = true;
	IsAutoScale			= true;
}
The commented lines are what I use normally (the first one doesn't work for me though which is why I'm having this problem). RefInstrument is defined earlier in State.SetDefaults too.

One last thing if you don't mind, perhaps you could try my syntax out as well? I'm starting to think this is a problem specific to my system, so perhaps I'll try installing on another machine over the weekend before I waste any more of your time.

Thanks again!

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


wuileng View Post
 
Code
else if (State == State.Configure)
{
	int barValue = Math.Max(1, base.BarsPeriod.Value);
	AddDataSeries(RefInstrument, base.BarsPeriod.BarsPeriodType, barValue, Data.MarketDataType.Last);
	//AddDataSeries(RefInstrument, BarsPeriods[0].BarsPeriodType, BarsPeriods[0].Value);
	//AddDataSeries(RefInstrument, BarsPeriodType.Minute, 5);
	
	Calculate			= Calculate.OnBarClose;
	IsOverlay			= false;
	DrawOnPricePanel    = true;
	DisplayInDataBox    = true;
	IsAutoScale			= true;
}
The commented lines are what I use normally (the first one doesn't work for me though which is why I'm having this problem). RefInstrument is defined earlier in State.SetDefaults too.

One last thing if you don't mind, perhaps you could try my syntax out as well? I'm starting to think this is a problem specific to my system, so perhaps I'll try installing on another machine over the weekend before I waste any more of your time.

Thanks again!

The [0] line is evidently faulty. Line 1 and 3 are "supposed to work" ... strange.
Just to make sure that the error isn't caused by your RefInstrument the snippet I use for setting the second instrument of my spreads from Properties:

[Description("Second instrument")]
[NinjaScriptProperty]
[Display(Name="2nd Instrument", Order=1, GroupName="Parameters")]
public string secondInstrument
{
get { return secondInstrument; }
set { secondInstrument= value; }
}

Reply With Quote
 
(login for full post details)
  #10 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received



choke35 View Post
The [0] line is evidently faulty. Line 1 and 3 are "supposed to work" ... strange.
Just to make sure that the error isn't caused by your RefInstrument the snippet I use for setting the second instrument of my spreads from Properties:

[Description("Second instrument")]
[NinjaScriptProperty]
[Display(Name="2nd Instrument", Order=1, GroupName="Parameters")]
public string secondInstrument
{
get { return secondInstrument; }
set { secondInstrument= value; }
}

Okay, I just tried several things out. All three lines work when applying the indicator to a chart.

However, when calling the indicator from a strategy, only the third (the hardcode) works. Sorry for not being specific earlier that I was trying to get it to work in the context of a strategy.

Started this thread Reply With Quote
 
(login for full post details)
  #11 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


wuileng View Post

However, when calling the indicator from a strategy, only the third (the hardcode) works. Sorry for not being specific earlier that I was trying to get it to work in the context of a strategy.

ad 1.)
Pardon, but the first sentence doesn't make sense.
Indicators are supposed to be called by strategies.
So - if called correctly - why should a call deliver less than the indicator can do?

ad 2.)
From a performance point of view:
Why would one pack x time series into a strategy that uses indicators that hold these time series anyway?

Reply With Quote
 
(login for full post details)
  #12 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received


choke35 View Post
ad 1.)
Pardon, but the first sentence doesn't make sense.
Indicators are supposed to be called by strategies.
So - if called correctly - why should a call deliver less than the indicator can do?

ad 2.)
From a performance point of view:
Why would one pack x time series into a strategy that uses indicators that hold these time series anyway?

What I meant is that when I try to use my indicator from within a strategy (via AddChartIndicator), the strategy fails to run because the indicator is referencing BarsPeriod. However, this does not cause problems when the indicator is just added to a chart (for visual purposes only).

Started this thread Reply With Quote
 
(login for full post details)
  #13 (permalink)
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
 
Posts: 2,668 since Feb 2013
Thanks: 5,099 given, 6,555 received


wuileng View Post
What I meant is that when I try to use my indicator from within a strategy (via AddChartIndicator), the strategy fails to run because the indicator is referencing BarsPeriod. However, this does not cause problems when the indicator is just added to a chart (for visual purposes only).

Ok, so the problem was more basic
AddChartIndicator is nothing but a visual representation without any flexibility concerning calculations.
But that is also made clear in the manual ...

Reply With Quote
The following user says Thank You to choke35 for this post:
 
(login for full post details)
  #14 (permalink)
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
 
Posts: 26 since Aug 2012
Thanks: 13 given, 9 received


choke35 View Post
Ok, so the problem was more basic
AddChartIndicator is nothing but a visual representation without any flexibility concerning calculations.
But that is also made clear in the manual ...

I've played around with it a bit more. It seems a workaround for this problem would be to not define my indicator in State.Configure, but instead wait till OnBarUpdate to do so (of course with logic implemented so this code snippet is only called once). It's working fine now, tested with all three lines of AddDataSeries.

I guess the only drawback is that since it's not defined in State.Configure, I can't AddChartIndicator, so I don't have the visual representation but I can live with that. It would be nice to have though, and am surprised this took a step back since it worked fine in NT7.

Thanks again for your help!

Started this thread Reply With Quote
The following user says Thank You to wuileng for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > NT8 - Multi Instrument Indicators


Last Updated on February 4, 2016


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts