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.

Pip value
 Post subject: Pip value Post rating: 0   New post Posted: Tue 23 Apr, 2013, 18:25 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Hi,

I have a very simple question. Is there any method to know the value of a pip on the base currency of the account?

I thought that was the result of getPipValue() but it isn't.

ie: My account is in EUR. I would like to know, if I trade USDNOK, how many euros is a NOK. Of course I could use the EURNOK rate, but for example, for xau or xag it wouldn't work. I just look for a factor, as when we get the intraday report, at the bottom comes the rates (JPY:0,008 NOK: 0,13003,...).

Thanks a lot.


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Tue 23 Apr, 2013, 19:22 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
I have found this:

convertPipToCurrency

double convertPipToCurrency(Instrument instrument,
Currency currency)
throws JFException

on the interface JFUtils.

But I dont know how to use it. I tried this but didn't work:

double price=JFUtils.convertPipToCurrency(instrument, EUR) throws JFException;


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Tue 23 Apr, 2013, 22:02 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi carlosfx:

On the second parameter of function you need to pass a Currency object... Not tested but i think you can try with Currency.getInstance("EUR")...

More information here, here and here.

Hope that helps

JL


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 07:44 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Hi, jlongo

Thanks for your help. Yes, you are right, I wansn't passing a currency object. Now I have defined a currency object (curr), an instrument (par) and a double variable (price):

price=JFUtils.convertPipToCurrency(par, curr);

but I get the following error message:

non-static method convertPipToCurrency(com.dukascopy.api.Instrument,java.util.Currency) cannot be referenced from a static context

I am a beginner with java (I'm just learning to try to code some simple strategies), I suppose is a simple structural coding mistake.

Thanks


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 09:48 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi carlosfx:

I don't have tried, but seems you can't use directly the method of JFUtils... you need to create a object from JFUtils and them use the object... something like:

JFUtils myJFUtils = new JFUtils();

myJFUtils.convertPipToCurrency...

Hope that helps

JL


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 10:04 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Much better, thanks. No red line on Netbeans.

But... it throws the exception "Not supported yet."


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 10:43 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#JForex_utils


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 11:04 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
OK, better, it is almost done. But I get a red message window and the value is null. Every instrument is suscribed.

I attach the piece of code that I wrote to try to get the pip price for every open position I have.

Thanks for your help

for (IOrder order : engine.getOrders())
{
par=order.getInstrument();

double price = utils.convertPipToCurrency(par, context.getAccount().getCurrency());
print ("par:"+par+" price:"+price);
}


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 11:05 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Sorry I forgot to tell that I get the message Class not accepted


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 11:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide a full example strategy which replicates the case. Post all the messages that you receive, also please post what you receive by printing all of your orders to the console, hence:
for(IOrder o : engine.getOrders()){
    console.getOut().println(o);
}


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 11:56 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Just adding the line...

JFUtils utils = context.getUtils();

... to my strategie, triggers the message "Class not accepted". Even if I don' t call the method. But as soon as I remove that line it doesn't send any message.

I attach the code.


package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class pipvalue implements IStrategy {
    private IAccount cuenta;
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private static Instrument par;
    Locale locale = Locale.GERMANY;
    Currency curr = Currency.getInstance(locale);
    double risk;
    double riesgo[];
    double pipPrice;
   
   
    JFUtils utils = context.getUtils();   
   

     
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
       
       
       
        getValue();
       
    }

    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 {
    }
     public void getValue() throws JFException
    {

       for (IOrder order : engine.getOrders())
       {
        par=order.getInstrument();
        double carga=order.getAmount();
        double value=par.getPipValue();
       
     
       
       
        pipPrice = utils.convertPipToCurrency(par, curr);
       
     
         print ("par:"+par+" carga:"+carga+" valor:"+ pipPrice);
       }
    }
   
     public void print(String string)
        {
            this.console.getOut().println(string);
        }
}


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 13:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You are initializing the JFUtils the wrong way, please see the examples from the link that we posted above.


 
 Post subject: Re: Pip value Post rating: 0   New post Posted: Wed 24 Apr, 2013, 14:23 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
OK, I got it. I was initialitating on the wrong place. Thank you for your help.


 

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