NexusFi: Find Your Edge


Home Menu

 





NT8 - Multi Instrument Indicators


Discussion in NinjaTrader

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




 
Search this Thread

NT8 - Multi Instrument Indicators

  #1 (permalink)
 wuileng 
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
Posts: 26 since Aug 2012
Thanks Given: 13
Thanks Received: 9

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 NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
REcommedations for programming help
Sierra Chart
Increase in trading performance by 75%
The Elite Circle
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
12 thanks
  #3 (permalink)
 choke35 
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558


Your syntax is incorrect.

For the correct syntax see:
NinjaTrader 8

Reply With Quote
  #4 (permalink)
 wuileng 
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
Posts: 26 since Aug 2012
Thanks Given: 13
Thanks Received: 9


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
  #5 (permalink)
 choke35 
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558


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
  #6 (permalink)
 wuileng 
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
Posts: 26 since Aug 2012
Thanks Given: 13
Thanks Received: 9


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
  #7 (permalink)
 choke35 
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558


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
  #8 (permalink)
 wuileng 
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
Posts: 26 since Aug 2012
Thanks Given: 13
Thanks Received: 9


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
  #9 (permalink)
 choke35 
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558


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
  #10 (permalink)
 wuileng 
Kuala Lumpur + Malaysia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: ES
Posts: 26 since Aug 2012
Thanks Given: 13
Thanks Received: 9



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




Last Updated on February 4, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts