I agree this is NOT fixed (it was declared fixed in API x.47) but is in fact still not working...
Consider the output from the following multi-instrument indicator code.
It sets indicator context in onStart(), subscribes to 28 pairs as price inputs, develops currency strength values from these prices,
then aims to switch off the output on the chart for all but the two currencies in the chart instrument.
call to showValues(boolean) outputs only "going for the instrument" - the call to context().getInstrument() always returns NULL.
CAN YOU PLEASE fix this? Or provide another method to access the chart instrument from within the Indicator interface? There is no other way to get this information within the IIndicator context and it can be very useful...
public void onStart(IIndicatorContext context)
{
this.context=context;
this.console=context.getConsole();
indicatorsProvider = context.getIndicatorsProvider();
indicatorInfo = new IndicatorInfo("CurrencySlopeStrength", "Currency Slope Strength ", "Momentum Studies", false, false, false, 28, 4, 8);
// setup inputs from each of the 28 majors and cross instruments
InputParameterInfo eurUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurUsdInput.setInstrument(Instrument.EURUSD);
InputParameterInfo gbpUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
gbpUsdInput.setInstrument(Instrument.GBPUSD);
InputParameterInfo usdChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
usdChfInput.setInstrument(Instrument.USDCHF);
InputParameterInfo audUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
audUsdInput.setInstrument(Instrument.AUDUSD);
InputParameterInfo usdCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
usdCadInput.setInstrument(Instrument.USDCAD);
InputParameterInfo usdJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
usdJpyInput.setInstrument(Instrument.USDJPY);
InputParameterInfo eurGbpInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurGbpInput.setInstrument(Instrument.EURGBP);
InputParameterInfo eurChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurChfInput.setInstrument(Instrument.EURCHF);
InputParameterInfo eurAudInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurAudInput.setInstrument(Instrument.EURAUD);
InputParameterInfo eurCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurCadInput.setInstrument(Instrument.EURCAD);
InputParameterInfo eurJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
eurJpyInput.setInstrument(Instrument.EURJPY);
InputParameterInfo gbpChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
gbpChfInput.setInstrument(Instrument.GBPCHF);
InputParameterInfo gbpAudInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
gbpAudInput.setInstrument(Instrument.GBPAUD);
InputParameterInfo gbpCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
gbpCadInput.setInstrument(Instrument.GBPCAD);
InputParameterInfo gbpJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
gbpJpyInput.setInstrument(Instrument.GBPJPY);
InputParameterInfo audChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
audChfInput.setInstrument(Instrument.AUDCHF);
InputParameterInfo cadChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadChfInput.setInstrument(Instrument.CADCHF);
InputParameterInfo chfJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
chfJpyInput.setInstrument(Instrument.CHFJPY);
InputParameterInfo audCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
audCadInput.setInstrument(Instrument.AUDCAD);
InputParameterInfo audJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
audJpyInput.setInstrument(Instrument.AUDJPY);
InputParameterInfo cadJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.CADJPY);
InputParameterInfo nzdUsdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.NZDUSD);
InputParameterInfo audNzdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.AUDNZD);
InputParameterInfo eurNzdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.EURNZD);
InputParameterInfo gbpNzdInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.GBPNZD);
InputParameterInfo nzdJpyInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.NZDJPY);
InputParameterInfo nzdChfInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.NZDCHF);
InputParameterInfo nzdCadInput= new InputParameterInfo("Price", InputParameterInfo.Type.PRICE);
cadJpyInput.setInstrument(Instrument.NZDCAD);
// fill the inputs array
inputParameterInfos = new InputParameterInfo[] {eurUsdInput, gbpUsdInput, usdChfInput, audUsdInput, usdCadInput, usdJpyInput, eurGbpInput,
eurChfInput, eurAudInput, eurCadInput, eurJpyInput, gbpChfInput, gbpAudInput, gbpCadInput,
gbpJpyInput, audChfInput, cadChfInput, chfJpyInput, audCadInput, audJpyInput, cadJpyInput,
nzdUsdInput, audNzdInput, eurNzdInput, gbpNzdInput, nzdJpyInput, nzdChfInput, nzdCadInput};
optInputParameterInfos = new OptInputParameterInfo[]
{
new OptInputParameterInfo("TMA Period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(tmaPeriod, 1, 200, 1)),
new OptInputParameterInfo("ATR Period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(atrPeriod, 1, 500, 1)),
new OptInputParameterInfo("Ignore Future", OptInputParameterInfo.Type.OTHER, new BooleanOptInputDescription(ignoreFuture)),
new OptInputParameterInfo("Show This Pair Only", OptInputParameterInfo.Type.OTHER, new BooleanOptInputDescription(showThisPairOnly))
};
outputParameterInfos = new OutputParameterInfo[]
{
new OutputParameterInfo("USD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("EUR", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("GBP", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("JPY", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("AUD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("CAD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("CHF", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("NZD", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
};
outputParameterInfos[0].setColor(Color.green); // Color USD
outputParameterInfos[1].setColor(DodgerBlue); // Color EUR
outputParameterInfos[2].setColor(Color.pink); // Color GBP
outputParameterInfos[3].setColor(Color.red); // Color JPY
outputParameterInfos[4].setColor(DarkOrange); // Color AUD
outputParameterInfos[5].setColor(MediumOrchid); // Color CAD
outputParameterInfos[6].setColor(Chocolate); // Color CHF
outputParameterInfos[7].setColor(Color.darkGray); // Color NZD
for (int w=0; w < outputParameterInfos.length; w++)
{
outputParameterInfos[w].setLineWidth(2);
}
showValues(showThisPairOnly);
}
private void showValues(boolean show)
{
instrument = context.getInstrument();
console.getOut().println("going for the instrument..."); // WE MAKE IT THIS FAR....
if (instrument == null) return; // BUT THE INSTRUMENT IS ALWAYS NULL...
console.getOut().println(instrument.toString());
for (int i = 0; i <= maxCurrencies-1; i++)
{
if (!show && instrument.toString().indexOf(currencies[i])<0)
{
console.getOut().println("MADE IT!"); // ALAS THIS IS NEVER SEEN....
outputParameterInfos[i].setShowValueOnChart(false);
}
else { outputParameterInfos[i].setShowValueOnChart(true); }
}
}