Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IIndicatorContext.getInstrument() returns NULL
 Post subject: IIndicatorContext.getInstrument() returns NULL Post rating: 0   New post Posted: Fri 13 Jul, 2012, 07:36 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
This issue 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); }
        }
    }



 
 Post subject: Re: APICLIENT-193 IIndicatorContext.getInstrument() returns NULL Post rating: 0   New post Posted: Mon 16 Jul, 2012, 16:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Documentation clearly states that the method IIndicatorContext.getInstrument "returns instrument of the primary input when called from IIndicator.calculate or IIndicator.setInputParameter methods", not from the onStart method, there's nothing to fix here.


 
 Post subject: Re: APICLIENT-193 IIndicatorContext.getInstrument() returns NULL Post rating: 0   New post Posted: Tue 17 Jul, 2012, 00:51 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
API Support wrote:
Documentation clearly states that the method IIndicatorContext.getInstrument "returns instrument of the primary input when called from IIndicator.calculate or IIndicator.setInputParameter methods", not from the onStart method, there's nothing to fix here.


Where is that documentation of which you speak? Could provide a link please? I've read a fair bit of the JForex documentation and am very familiar with the API class documentation.

Seems odd that we can't get the chart instrument in onStart().


 
 Post subject: Re: IIndicatorContext.getInstrument() returns NULL Post rating: 1   New post Posted: Tue 17 Jul, 2012, 07:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
f451 wrote:
Where is that documentation of which you speak? Could provide a link please?
https://www.dukascopy.com/client/javadoc/com/dukascopy/api/indicators/IIndicatorContext.html#getInstrument()


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com