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.

how use css in own indicator?
 Post subject: how use css in own indicator? Post rating: 0   New post Posted: Tue 23 Apr, 2019, 13:51 

User rating: 0
Joined: Sun 14 Apr, 2019, 13:15
Posts: 3
Location: Poland,
I coded indicator which use CSS (CurrencySlopeStrength indicator).
I want get array of double[8] and make some calculation with this.
My code give null pointer exception - in log file error is outside my indicator - in CSS indicator code:
context.getFeedDescriptor() == null.

I probably wrong initialize CSS indicator. Can you help me with this?

This is my code:
package jforex3;

import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.indicators.*;

public class paramCSSind implements IIndicator {

    private IIndicatorContext context;
    private IConsole console;
    private IIndicator css;
   
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
   
    private IBar[][] inputs = new IBar[1][];
    private double[][] outputs = new double[1][];
    private double[][] outCSS;
   
    int inpNr, inpOptNr, outNr;

public void onStart(IIndicatorContext context) {
        this.context = context;       
        this.console = context.getConsole();
        IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
        css = indicatorsProvider.getIndicator("CSS");

        IndicatorInfo infoCSS = css.getIndicatorInfo();
        inpNr = infoCSS.getNumberOfInputs();
        inpOptNr = infoCSS.getNumberOfOptionalInputs();
        outNr = infoCSS.getNumberOfOutputs();

        indicatorInfo = new IndicatorInfo("paramCSSind", "raw CSS for pair", "My indicators",
                false, false, false, 1, 0, 1);

        inputParameterInfos = new InputParameterInfo[] {
            new InputParameterInfo("Bars", InputParameterInfo.Type.BAR)
        };

        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE,
                OutputParameterInfo.DrawingStyle.LINE)
        };
    }
    public IndicatorResult calculate(int startIndex, int endIndex) {
        //calculating startIndex taking into account lookback value
        if (startIndex - getLookback() < 0) {
            startIndex = getLookback();
        }
        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }
        css.setInputParameter(0, inputs[0]);
        double[][] outCSS = new double[outNr][endIndex - startIndex + 1];
        for (int i = 0; i < outNr; i++) {
            css.setOutputParameter(i, outCSS[i]);
        }
        console.getOut().format("%d %d %d %d %d %d \n", startIndex, endIndex, inputs.length, inputs[0].length, outCSS.length, outCSS[0].length  );
        css.calculate(0, inputs[0].length -1 );
        int i, j;       
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
            outputs[0][j] = outCSS[0][j];
            console.getOut().format("%.3f ", outCSS[0][j] );
        }
        console.getOut().println();
        return new IndicatorResult(startIndex, j);
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        if (index < inputParameterInfos.length) {
            return inputParameterInfos[index];
        }
        return null;
    }

    public int getLookback() {
        return 0;
    }

    public int getLookforward() {
        return 0;
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index) {
        if (index < optInputParameterInfos.length) {
            return optInputParameterInfos[index];
        }
        return null;
    }

    public OutputParameterInfo getOutputParameterInfo(int index) {
        if (index < outputParameterInfos.length) {
            return outputParameterInfos[index];
        }
        return null;
    }

    public void setInputParameter(int index, Object array) {
        inputs[index] = (IBar[]) array;
    }

    public void setOptInputParameter(int index, Object value) {
    }

    public void setOutputParameter(int index, Object array) {
        outputs[index] = (double[]) array;
    }
   
   }


Error in lines:
// my indicator
css.calculate(0, inputs[0].length -1 );

// css indicator
DataType dataType = context.getFeedDescriptor().getDataType();



 
The Best Answer  Post subject: Re: how use css in own indicator? Post rating: 0   New post Posted: Wed 08 May, 2019, 09:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For correct Currency Slope Strength indicator use you need to specify and pass IIndicatorContext into it. To do this, use another getIndicator() method.

css = indicatorsProvider.getIndicator("CSS", context);


 

Jump to:  

cron
  © 1998-2024 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