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.

using Instrument.getPipValue()
 Post subject: using Instrument.getPipValue() Post rating: 0   New post Posted: Fri 23 Mar, 2012, 11:21 
User avatar

User rating: 0
Joined: Mon 09 Jan, 2012, 20:51
Posts: 9
Location: Luxembourg, Wormeldange
hi,
What's the expected output from Instrument.getPipValue()?
Is the return value in units or millions or what?

I tried this:
package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class Strategy implements IStrategy {
   
    public void onStart(IContext context) throws JFException {
        context.getConsole().getOut().println("For 1M EUR/USD, 1 pip is worth $" + String.format("%8f", Instrument.EURUSD.getPipValue()));
    }

    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 {    }
}


And get the result:
10:13:18 For 1M EUR/USD, 1 pip is worth $0.000100


I expected an answer of approx $75

cheers,
lux


 
 Post subject: Re: using Instrument.getPipValue() Post rating: 0   New post Posted: Fri 23 Mar, 2012, 12:03 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
lux_interior wrote:
What's the expected output from Instrument.getPipValue()?
It's the price value not the amount - it is either 0.01 or 0.0001.
lux_interior wrote:
I expected an answer of approx $75
Have a look at the following:
https://www.dukascopy.com/wiki/#JForex_utils/Conversion_of_pip_cost


 
 Post subject: Re: using Instrument.getPipValue() Post rating: 0   New post Posted: Fri 23 Mar, 2012, 16:50 
User avatar

User rating: 0
Joined: Mon 09 Jan, 2012, 20:51
Posts: 9
Location: Luxembourg, Wormeldange
JFUtil.convertPipToCurrency() didn't seem to reliably give me the result I wanted either.
However, this works for me:
        Instrument ins = Instrument.EURUSD;
        ITick lastTick = context.getHistory().getLastTick(ins);
        double midPrice = (lastTick.getAsk() + lastTick.getBid()) / 2.0;
        double amount = 1000000.0;
       
        double pipCost = (1.0 / midPrice * ins.getPipValue()) * amount;
       
        context.getConsole().getOut().println(String.format("At position size %.0f, 1 pip of %s is worth %s %.6f", amount, ins.toString(), ins.getPrimaryCurrency(), pipCost));


Output:
15:44:24 At position size 1000000, 1 pip of EUR/USD is worth EUR 75.341485


Many thanks for your help


 

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