My ultimate goal is to develop a multi-instrument strategy, using a multi-instrument indicator as part of its overall set up. In creating the code, I use:
- StrategyBuilder for strategy development, and
- NinjaScript Editor for indicator development.
My attempts to extend my strategy and my indicator to incorporate a secondary instrument have resulted in run-time errors saying that:
A. All those OTHER indicators which I use as inputs into TDENVIRONMENT have "(indicator name) tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load (primary security) Default: 5 Range"; and
B. "Value of property "prop1" of NinjaScript TDENVIRONMENT is 0 and not in valid range...". I have checked many times, I am not setting any of my parameters to 0...
I would appreciate any help/advice/insight from the NT community here re what should I do/where do I need to look to address these. In particular:
(1) Should my OTHER indicators, which feed into TDENVIRONMENT, also make calls on the secondary instrument? At this state, I have incorporated a call for the secondary instrument into multi-instrument indicator (please see below), but NOT into OTHER indicators that feed into it.
(2) Is it ok that my primary series and my secondary series share the same set of parameters, or should each one have their own set?
(3) Does BarsRequiredToPlot really need to be defined based on how many bars is needed for calculation of all the OTHER indicators? Eg if there is EMA(20) and EMA(600), does BarsRequiredToPlot need to be 600, or can it be 20?
(4) Does BarsRequiredToTrade in the strategy need to correspond to BarsRequiredToPlot in the indicator?
(5) Does anything in my script snippets below raise a concern?
Here is what I have done in my two multi-instrument scripts:
(1) Added two plots to the indicator and supplied default its default parameter values:
if (State==State.SetDefaults)
AddPlot(Brushes.Blue, "TDENVIRONMENT Primary Series");
AddPlot(Brushes.Green, "TDENVIRONMENT Secondary Series");
HMAcoreperiod =1800;
SMAcoreperiod =1800;
param1 = 300;
param2 = 200; etc.
(2) I have added secondary data series to both the strategy and to the indicator:
if (State==State.Configure)
AddDataSeries("XXXX", BarsPeriodType.Range, 5, Data.MarketDataType.Last);
(3) Initialised the Plots in the indicator. TDENVIRONMENT has a large number of parameters which it "inherits" from the OTHER single instrument indicators. For simplicity, I have cut down the number of these/removed their names below.:
// initialize the TDENVIRONMENT using the primary series and assign to TDENVIRONMENT1
TDENVIRONMENT1 = TDENVIRONMENT(BarsArray[0], param1,param2, param3);
// initialize the TDENVIRONMENT using the secondary series and assign to TDENVIRONMENT2
TDENVIRONMENT2 = TDENVIRONMENT(BarsArray[1], param1,param2, param3);
(4) Added BarsRequiredToPlot logic to the indicator
protected override void OnBarUpdate()
{
// ensure both series have at least one bar, and have sufficient number to plot
if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[0] <=BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
return;
// when secondary series are processing, set the secondary plot to the TDENVIRONMENT with the secondary series input
if (BarsInProgress == 1)
TDENVIRONMENTSecondary[0] = TDENVIRONMENT2[0];
// when the primary series is processing set the primary plot to the TDENVIRONMENT with the primary series input
if (BarsInProgress == 0)
{
TDENVIRONMENTPrimary[0] = TDENVIRONMENT1[0];
// if the secondary series did not close, set the current bar's value to the previous bar's value to prevent gaps
if (!TDENVIRONMENTSecondary.IsValidDataPoint(0))
TDENVIRONMENTSecondary[0] = TDENVIRONMENTSecondary[1];
(5) Have defined parameter fields in the indicator, including, amongst other parameters, the following:
[Browsable(false)]
[XmlIgnore]
public Series<double> TDENVIRONMENTPrimary
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> TDENVIRONMENTSecondary
{
get { return Values[1]; }
}
Many thanks
TD


Comment