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.

Effecient way to transfer information to indicator
 Post subject: Effecient way to transfer information to indicator Post rating: 0   New post Posted: Fri 25 Sep, 2009, 21:42 

User rating: 0
Joined: Fri 25 Sep, 2009, 21:35
Posts: 5
I am working on a JForex indicator that requires access to multiple currency information. As far as I know indicators only have access to the instrument they are applied to. Currently I have the strategy calculating the necessary values and writing them to a file that the indicator reads and displays. This is causing display and IO problems because of the frequent reading and writing of the file by two different classes. I have tried a double locking method, but this significantly slows down the strategy degrading the performance. I have also seen the indicators and strategies appear to use two different class loaders, preventing using a common library to share the same information. Because of these problems I am looking for a more efficient way to transfer this information to the indicator for display. Here are my questions:

Is there any way to access multiple currency information from an indicator?

Is there a mechanism available within JForex to transfer information (such as an array of doubles) from a Strategy to an Indicator?

Is there a way within the JVM to transfer this information to a memory location or some other method accessible by both the Strategy and Indicator?

Any information or pointers you may have would be greatly appreciated.


 
 Post subject: Re: Effecient way to transfer information to indicator Post rating: 0   New post Posted: Wed 30 Sep, 2009, 08:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Indicators are designed as simple functions that take some input prices and calculate some results based on those prices. They are not designed to do main business functionality. Instead you should use strategy, where you are able to access your created indicators. In your situation, where you are using different instruments and making calculations, you should consider to use strategy where you can write main logic and make some indicator which will do the math calculations. In strategy you are able to access indicator passing them any instrument. When you are creating indicators, there is several things that you should take into account - for indicator you should initialize three main parts: IndicatorInfo, InputParameterInfo, OutputParameterInfo. As well you could initialize
OptInputParameterInfo if there is need for that. Use method calculate to make necessary math calculations on incoming data.

Use of IndicatorInfo:
name - gives a name by which you will bee able to call it from strategy (should be simple);
title - gives a title to this indicator - more detailed name which are used in JForex "add indicator" dialog window;
groupName - specifies directory where it would bee accessible thru JForex in "add indicator" dialog window;
overChart - true if indicator should be drawn over candles/ticks;
overVolumes - true if indicator should be drawn over volume information;
unstablePeriod - true if indicator has unstable period (like EMA or SAR). This will add more candles in every call to stabilize function;
candlesticks - true if indicator should be shown over bars;
numberOfInputs - number of inputs that user should provide;
numberOfOptionalInputs - number of optional inputs;
numberOfOutputs - number of outputs, that function returns;

For example:
new IndicatorInfo("ENTROPY", "Calculates entropy number", "My indicators",false, false, false, 1, 1, 1);


Use InputParameterInfo to describe your input data:
1)name - name of the input;
2)type - type of the input (InputParameterInfo.Type);

For example:
new InputParameterInfo("Input data", InputParameterInfo.Type.PRICE);


Use OutputParameterInfo to describe type of output data and drawing style:
name - name of the output
type - type of the output
drawingStyle - specifies how to draw this output (OutputParameterInfo.DrawingStyle)

For example:
new OutputParameterInfo("Output data", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);


Use OptInputParameterInfo to describe optional input parameters:
name - name of the optional input
type - type of the optional input (OptInputParameterInfo.Type)
description - object that describes possible values of the optional input (OptInputDescription)

For example:
new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER,new IntegerRangeDescription(2, 2, 100, 1));


More detail description https://www.dukascopy.com/swiss/docs/api/index.htm

To get access to data from newly created indicator, should use one of calculateIndicator methods.

For example:
   indicators.calculateIndicator(Instrument.EURUSD,Period.TICK,new OfferSide[] {OfferSide.BID},"ENTROPY",
                                    new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, new Object[]{1},1);



We added strategy as sample that shows how to call and get data from your own indicator.

package jforex;

import com.dukascopy.api.*;

public class TestMyIndicatorStrategy implements IStrategy {
    private IConsole console;
    private IIndicators indicators;
   
    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        this.indicators = context.getIndicators();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
       
        //making calculations on current instrument and period with manually created indicator ENTROPY
        Object[] outputs = indicators.calculateIndicator(instrument,                         
                                                         period,
                                                         new OfferSide[] {OfferSide.BID},
                                                         "ENTROPY",
                                                         new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                                                         new Object[]{1},
                                                          1);
       
        //getting output on console
        for (int i=0;i<outputs.length;i++){
            this.console.getOut().print("output["+i+"]: "+(Double)outputs[i]);
        }       
        this.console.getOut().println();
    }
}


Attachments:
Entropy.java [3.9 KiB]
Downloaded 865 times
TestMyIndicatorStrategy.java [1.62 KiB]
Downloaded 814 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.
 

Jump to:  

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