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.

Any idea how to do a custum currency index chart ?
 Post subject: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Thu 22 Mar, 2012, 10:07 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hello,

I'm working with a currency index strategy that prints me a report based on
the weighting of strong to weak currencies. (I compare all pairs to each other based
on some multi currency / multi timeframe calculations).

The report prints every minute and looks like this :
You have the time, the currency, the relative strength of the currency

08:49:02 JPY 390 | GBP 280 | USD 230 | CHF 20 | CAD -20 | EUR -160 | NZD -330 | AUD -390
08:48:03 JPY 390 | GBP 280 | USD 230 | CHF 20 | CAD -20 | EUR -160 | NZD -330 | AUD -390
08:47:02 JPY 390 | GBP 300 | USD 230 | CHF 20 | CAD -10 | EUR -160 | NZD -330 | AUD -420


I'd like to go a step further by drawing a chart in order to have some convenient historical visualization.
It will enable me to see if technical analysis of this index on a chart could help me improving my returns.

How could I draw this directly from a strategy ? (I don't want to code an indicator, I'm very bad at this)
Is their a way I can create some custom Instrument to draw on a chart ? (I can adapt to not have negative
strength values).
Drawing directly on an existing chart and making the candles transparent (This is dirty but could maybe work)


All ideas are welcome !

Best regards


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Thu 22 Mar, 2012, 12:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
nicofr0707 wrote:
Is their a way I can create some custom Instrument to draw on a chart ? (I can adapt to not have negative
strength values).
This sounds like an overkill, if we understood your algorithm correctly, then you want a collection of RSI's drawn on a separate chart panel, which is what an indicator could do for you, the strategies for now don't have such capabilities.
nicofr0707 wrote:
Drawing directly on an existing chart and making the candles transparent (This is dirty but could maybe work)
Say you have EUR/USD chart with price range 1.3000 to 1.3500, where would you plot the RSI's of JPY 390 | GBP 280 | USD 230 | CHF 20 | CAD -20 | EUR -160 | NZD -330 | AUD -390? An indicator could do the job. We adjusted the following wiki example:
https://www.dukascopy.com/wiki/#Indicato ... nstruments
to
package jforex.indicators;

import com.dukascopy.api.*;

import com.dukascopy.api.indicators.*;

public class CurrencyRSIIndicator implements IIndicator {
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
    private IBar[][] inputBars = new IBar[3][];
    private double[][] outputs = new double[3][];
   
    public void onStart(IIndicatorContext context) {
       
        //indicator info
        indicatorInfo = new IndicatorInfo("RSI_CURR", "RSI for various instruments", "", false, false, true, 3, 0, 3);

        //indicator inputs
        InputParameterInfo gbpUsdInput = new InputParameterInfo("Input data", InputParameterInfo.Type.BAR);
        gbpUsdInput.setInstrument(Instrument.GBPUSD);
        InputParameterInfo audCadInput = new InputParameterInfo("Input data", InputParameterInfo.Type.BAR);
        audCadInput.setInstrument(Instrument.AUDCAD);
        InputParameterInfo eurJpyInput = new InputParameterInfo("Input data", InputParameterInfo.Type.BAR);
        eurJpyInput.setInstrument(Instrument.EURJPY);       
        inputParameterInfos = new InputParameterInfo[] {  gbpUsdInput, audCadInput, eurJpyInput};
       
        OutputParameterInfo gbpUsdOutput = new OutputParameterInfo("gbpUsd_MA", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);
        OutputParameterInfo audCadOutput = new OutputParameterInfo("audCad_MA", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);
        OutputParameterInfo eurJpyOutput = new OutputParameterInfo("eurJpy_MA", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE);
       
        outputParameterInfos = new OutputParameterInfo[] {  gbpUsdOutput, audCadOutput, eurJpyOutput};
    }

    public IndicatorResult calculate(int startIndex, int endIndex) {
        //calculating startIndex taking into an account the lookback value
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
       
        //i - input array iterator, j - output array iterator
        int i, j;
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
            //k: 0 = GBPUSD; 1 = AUDCAD; 2 = EURJPY
            for (int k = 0; k < outputs.length; k++){
                //TODO: change this to real RSI algorithm
                if( i < inputBars[k].length){
                    outputs[k][j] = inputBars[k][i].getClose() / inputParameterInfos[k].getInstrument().getPipValue() % 10;
                }
            }
        }
        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) {
        inputBars[index] = (IBar[]) array;
    }

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

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


Please update the calculate method to fit your algorithm.


Attachments:
CurrencyRSIIndicator.java [3.74 KiB]
Downloaded 325 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: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Thu 22 Mar, 2012, 17:42 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Ok thanks.

I wasn't very clear, but this strategy has nothing to do with the RSI indicator.

I would be very grateful if you can make it a little bit more specific for me
to see how I understand your previous example.

My strategy uses a lot of different calculation so I'll try to simplifie the description, let's say :

1 - I have 18 instruments in input (which must not be drawn in indicator window)
2 - I have 8 currencies in output (those whose value will be drawn from analyzeMarket())

// analyzeMarket returns an [] [] with the list and the weighting of each currency
// I must cast do double and draw the values returned by that method in my indicator

private String [][] analyzeMarket() {

   // I have to call some indicators to compare the strength for each for example EUR based pairs
    aligatorStrengh = getAlligatorTrend(correctInstrument, period);
    pivotStrengh = getPivot(correctInstrument, period);
   //.....
   
   strengthValue = aligatorStrengh + pivotStrengh;

    // For exemple returns EUR ; 100
   // For exemple returns AUD ; 200
   // For exemple returns JPY ; -100
   return [currency][strengthValue]
}

private int getAlligatorTrend(correctInstrument, period){

  // Can I call an indicator like this within an indicator file ?
  double[] myAlligator1 = indicators.alligator(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 13, 8, 5, 1);

     
        if (myAlligator1 is bullish) {
            trendResult = 10;
        } else if (myAlligator1 is bearish) {
            trendResult = -10;
        } else {
            trendResult = 0;
        }
  return trendResult
}

private int getPivot(correctInstrument, period){
   // same type of calculation than getAlligatorTrend
  return trendResult
}


To sum up, I don't ask you to do my job I need just an example of an indicator :

1 - inputting instruments
2 - outputting int or double
3 - do some other indicators calculations in analyzeMarket()
4 - in calculate, drawing the values from an array returned by analyzeMarket()

I hope my explanation is understandable.

Best regards


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Fri 23 Mar, 2012, 09:49 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
nicofr0707 wrote:
I wasn't very clear, but this strategy has nothing to do with the RSI indicator.
We just abbreviated it, the example indicator also does not have anything to do with it.
nicofr0707 wrote:
My strategy uses a lot of different calculation so I'll try to simplifie the description, let's say :

1 - I have 18 instruments in input (which must not be drawn in indicator window)
2 - I have 8 currencies in output (those whose value will be drawn from analyzeMarket())
Our provided example indicator has 3 input instruments and 3 CRS (currency relative strengths), change inputBars to 18, outputs to 8, in indicatorInfo assignment change values to ...,18,0,8); and add the additional infos to inputParameterInfos and outputParameterInfos arrays.

nicofr0707 wrote:
1 - inputting instruments
2 - outputting int or double
The example indicator already does that.
nicofr0707 wrote:
3 - do some other indicators calculations in analyzeMarket()
4 - in calculate, drawing the values from an array returned by analyzeMarket()
Take a look at the calculate method. Consider logging inputs and outputs array values to see the values that you work with (e.g., see helper methods at the end of the indicator in this topic viewtopic.php?f=6&t=45773).

Quote:
// Can I call an indicator like this within an indicator file ?

https://www.dukascopy.com/wiki/#Indicator_that_uses_the_output_of_another_indicator
beforehand you might want to find out the indicator inputs, outputs, optional inputs:
https://www.dukascopy.com/wiki/#Indicator_metadata/Retrieve_indicator_metadata


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Fri 23 Mar, 2012, 10:14 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Thanks, I'll should be able to figure it out.

Yet to be able to make my trendline strategy work on this, I didn't figure out
how to use addToSubChart. Let's say I will add a ray line to an indicator window, please see my test :


IBar barLineHandle = history.getBar(chart.getInstrument(), chart.getSelectedPeriod(), OfferSide.BID, 40);
ITick lastTick = history.getLastTick(chart.getInstrument());

      IRayLineChartObject lineSub = chart.getChartObjectFactory().createRayLine(objectKey + "_indi",
            lastTick.getTime(), 50,
            barLineHandle.getTime(), 50);
      chart.addToSubChart(0, 0, lineSub);


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Fri 23 Mar, 2012, 10:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
nicofr0707 wrote:
Yet to be able to make my trendline strategy work on this, I didn't figure out
how to use addToSubChart.
The functionality will be fixed with the future releases.


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Sun 25 Mar, 2012, 20:45 

User rating: 4
Joined: Mon 19 Sep, 2011, 09:55
Posts: 29
Location: Germany,
You can obtain a custom tab and draw the data points there the way you want—without the need to further interact with the jforex api.


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Mon 26 Mar, 2012, 07:48 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
@astro
Yes I thought about it, but the problem is I can't use dukascopy's tools on it can I ? (chart objects...)


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Mon 26 Mar, 2012, 09:44 

User rating: 4
Joined: Mon 19 Sep, 2011, 09:55
Posts: 29
Location: Germany,
No.
But you have all the Java at hand, no need for anything else.
I'm doing like so to have a complete trading interface (candles, indicators, trade-execution..) within JForex, don't care for anything else from JForex but the tick data.


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Thu 12 Jul, 2012, 04:12 

User rating: 0
Joined: Wed 27 Jun, 2012, 14:47
Posts: 1
I got this error

03:01:24 Instrument AUD/CAD not subscribed, cannot add indicator

Any ways to work around it?


 
 Post subject: Re: Any idea how to do a custum currency index chart ? Post rating: 0   New post Posted: Thu 12 Jul, 2012, 07:49 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Make sure you have opened the instrument in the platform.


 

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