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:
But in NT8, the following just gives me errors:
Does anyone know of a better way?
Can you help answer these questions from other members on futures io?
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).
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?
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.
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; }
}
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.
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?
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).
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 ...
The following user says Thank You to choke35 for this 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!
The following user says Thank You to wuileng for this post: