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.

getFXSentimentIndex(Instrument instrument, long time)
 Post subject: getFXSentimentIndex(Instrument instrument, long time) Post rating: 0   Post Posted: Mon 17 Dec, 2012, 00:26 
User avatar

User rating: 0
Joined: Sun 16 Dec, 2012, 23:39
Posts: 8
Hello support,

Im in a process of coding SWFX Sentiment indicator (couldnt find one on wiki or on forums)

I've noticed that each time I call
getFXSentimentIndex(Instrument instrument, long time) 
JForex client hangs (has to kill jvm in task manager and restart client).

After changing to
getFXSentimentIndex(Instrument instrument) 
indicator works fine but its not what I need.

Another thing is following call:
this.ds = context.getDataService();


It crashes with java.lang.SecurityException unless indicator class is decorated with @RequiresFullAccess
Please provide more information on this, why getDataService() call requires this.

Am I doing something wrong?
I will appreciate any help.

My code:

import com.dukascopy.api.IBar;
import com.dukascopy.api.IFXSentimentIndex;
import com.dukascopy.api.IDataService;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IIndicatorContext;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.IndicatorResult;
import com.dukascopy.api.indicators.InputParameterInfo;
import com.dukascopy.api.indicators.OptInputParameterInfo;
import com.dukascopy.api.indicators.OutputParameterInfo;

import com.dukascopy.api.Instrument;

import com.dukascopy.api.RequiresFullAccess;

@RequiresFullAccess
public class SSI_Indicator implements IIndicator {
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
    private IBar[][] inputs = new IBar[1][];
    private IDataService ds;
    private Instrument instrument;

    public void onStart(IIndicatorContext context) {
        this.ds = context.getDataService();
        this.instrument = Instrument.USDJPY;
    indicatorInfo = new IndicatorInfo("SWFX_SSI", "Sentiment index", "", false, false, false, 1, 0, 1);
        inputParameterInfos = new InputParameterInfo[] {
            new InputParameterInfo("Price", InputParameterInfo.Type.BAR)
        };
        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("SSI", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM)
        };
    }

public IndicatorResult calculate(int startIndex, int endIndex) {
        IFXSentimentIndex ssi = null;
        int i, j;   

        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
            if (this.ds == null) outputs[0][j] = Double.NaN; else {
                ssi = this.ds.getFXSentimentIndex(this.instrument, inputs[0][i].getTime());  // this one hangs JForex client
                ssi = this.ds.getFXSentimentIndex(this.instrument);   // this one works
                if (ssi == null) {
                    outputs[0][j] = Double.NaN;
                } else {
                    outputs[0][j] = ssi.getIndexValue();
                }
            }
        }
        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) {
        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;
    }
}


 
 Post subject: Re: getFXSentimentIndex(Instrument instrument, long time) Post rating: 0   Post Posted: Mon 17 Dec, 2012, 08:26 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The indicator you posted does not compile. You can find the indicator in platform Common -> Sentiment Index bar. For indicator sources see:
https://www.dukascopy.com/wiki/#Platform_indicator_source_files


 
 Post subject: Re: getFXSentimentIndex(Instrument instrument, long time) Post rating: 0   Post Posted: Mon 17 Dec, 2012, 12:22 

User rating: 1
Joined: Sun 22 Jul, 2012, 13:35
Posts: 40
Hi,

Try this. It is for 3 instruments...


Attachments:
SentimentIndexIndicator.jfx [8.04 KiB]
Downloaded 318 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: getFXSentimentIndex(Instrument instrument, long time) Post rating: 0   Post Posted: Mon 17 Dec, 2012, 20:52 
User avatar

User rating: 0
Joined: Sun 16 Dec, 2012, 23:39
Posts: 8
Thanks for help - it is what I was looking for. I didnt know there are indicators in "common" folder - silly me.


 

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