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.

Convert pip to currency
 Post subject: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 14:52 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
I have made some try to convert the pip with the current currency. It's seems there some errors: if i use it on EUR/USD or GBP/USD on an account on EUR, all is right. However, if i do the same thing on USD/JPY (for exemple) and i keep my account in EUR, the result is different from what it must to be (i have used https://www.dukascopy.com/swiss/english/ ... xcalc/pip/ to check it).
For exemple, on a lot size, of 100 000 JFutil return me 8.326 (ask = 78.675, eur/usd=1.24548) and dukascopy calculator give me a result of 10.21. Did i forgot to do something ?
By advance, thanks.


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 14:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Could you please provide the example strategy and the launch scenario?


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 15:17 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
Ok so:

@Configurable("Instrument 1")
    public Instrument instrument1 = Instrument.EURUSD;
   
    @Configurable("Instrument 2")
    public Instrument instrument2 = Instrument.EURGBP;
   
    @Configurable ("Instrument 3")
    public Instrument instrument3 = Instrument.EURJPY;
     
    @Configurable ("Instrument 4")
    public Instrument instrument4 = Instrument.GBPUSD;
     
    @Configurable ("Instrument 5")
    public Instrument instrument5 = Instrument.USDJPY;
     
    @Configurable ("Instrument 6")
    public Instrument instrument6 = Instrument.USDCAD;
     
    @Configurable ("Instrument 7")
    public Instrument instrument7 = Instrument.USDCHF;
     
    @Configurable ("Instrument 8")
    public Instrument instrument8 = Instrument.AUDCAD;

    @Configurable("Decimal separator in Excel")
    public String decSepa = ",";

    @Configurable("Type sheet name")
    public String  sheetName = "SPOT";
   
    @Configurable("Langage of Excel")
    public String lang="FR";


    private final Set<Instrument> instruments = new HashSet<Instrument>(Arrays.asList(new Instrument[] {
           instrument1,
           instrument2,
           instrument3,
           instrument4,
           instrument5,
           instrument6,
           instrument7,
           instrument8
    }));

 @Override
    public void onStart(IContext context) throws JFException {
         
        conversation = new DDEClientConversation();
        console = context.getConsole();
        context.setSubscribedInstruments(instruments);
       
         int i = 10;
        while (!context.getSubscribedInstruments().containsAll(instruments)) {
            try {
                console.getOut().println("Instruments not subscribed yet " + i);
                Thread.sleep(100);
            } catch (InterruptedException e) {
                console.getOut().println(e.getMessage());
            }
            i--;
        }
       
       
         
        try {
            conversation.connect("Excel", sheetName);    //I would like to have this values in a excel sheet
         
            JFUtils utils=context.getUtils();
           
           
            int rows=3;
             for (Instrument instrument : instruments) {
                 
                 double curr1=utils.convertPipToCurrency(instrument, context.getAccount().getCurrency());
                 Double Curr1 = new Double (curr1);
                 conversation.poke(getCell(rows,1),convertToDecimal(Curr1.toString()));
                 rows++;
                 
             }
 
         
 
        } catch (DDEClientException e) {
            print(e.toString());
        }
         
         
         
    }

/....

public String convertToDecimal (String value)
   {
        String strToConvert;
        strToConvert =(decSepa ==",") ? value.replace('.', ',') :  value; //(because i use excel in french)
        return strToConvert;
       
     
   }


 public String getCell(int row, int column) { //To adapt on some other langages
       
        String str="";
        if (lang=="FR")
        {
          str="L"+row+"C"+(column);
        }
        else if (lang =="EN")
        {
            str="R"+row+"C"+(column);
        }
       
       else if (lang=="GE")
        {
            str="R"+row+"K"+(column);
        }
       
     
        return str;
    }


As you can see, i use it to retrieve this values in an excel sheet (nammed "SPOT").
Thanks.


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 15:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
API Support wrote:
and the launch scenario?
- How do you launch it? In historical tester (please provide the settings) or with live data?


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 15:22 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
In live data...


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 15:33 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Unfortunately we cannot provide support for excel usage. Could you please take a look at the following example:
https://www.dukascopy.com/wiki/#JForex_utils/Conversion_of_pip_cost_-_multiple_currencies_and_instruments
Change the instrument and currency sets to the ones that you use and see if the results are correct.


 
 Post subject: Re: Convert pip to currency Post rating: 0   New post Posted: Tue 05 Jun, 2012, 16:22 
User avatar

User rating: 4
Joined: Wed 21 Dec, 2011, 10:21
Posts: 30
Location: France, Sallanches
In fact, it seems that this portion of code doesn't work:
           ...
            int rows=3;
             for (Instrument instrument : instruments) {
                 
                 double curr1=utils.convertPipToCurrency(instrument, context.getAccount().getCurrency());
                 Double Curr1 = new Double (curr1);
                 conversation.poke(getCell(rows,1),convertToDecimal(Curr1.toString()));
                 rows++;
                }
          ...


So i have replaced by this in the onTick method:


   
            ...
            double curr1=utils.convertPipToCurrency(instrument1,currency);
             Double Curr1 = new Double (curr1);
             conversation.poke(getCell(3,5),convertToDecimal(Curr1.toString()));   
           ...


for each of the instruments i want. Now it's work perfectly.


 

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