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.

What is the best practice for sanitizing entry order prices?
 Post subject: What is the best practice for sanitizing entry order prices? Post rating: 0   New post Posted: Fri 22 Feb, 2013, 01:28 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
Suppose I have some number x, and would like to set the trigger price for an order to be as close as possible to x. How would you recommend accomplishing this simple task?

My current solution is: IOrder.setOpenPrice(sanitizePrice(x))
where...
    protected static double sanitizePrice(double price) {
        double pipValue = 0.0001;
        double atom = pipValue / 10;
        return Math.round(price / atom) * atom;
    }


However, for some x this doesn't work. For example, you can check for yourself in Java that sanitizePrice(1.32907)==1.3290700000000002

So IOrder.setOpenPrice(sanitizePrice(1.32907)) results in
ORDER_CHANGED_REJECTED message wrote:
Invalid price format - please use increments of 0.1 pip.


How should it be done?


 
 Post subject: Re: What is the best practice for sanitizing entry order prices? Post rating: 0   New post Posted: Fri 22 Feb, 2013, 01:44 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
Well, this seems to work, at least for 1.32907:
    protected static double sanitizePrice(double price) {
        double pipValue = 0.0001;
        double atomInverse = 10.0/pipValue;
        return Math.round(price * atomInverse) / atomInverse;
    }


But will it work in all cases? Do you have any standard best-practice method?


 
The Best Answer  Post subject: Re: What is the best practice for sanitizing entry order prices? Post rating: 0   New post Posted: Fri 22 Feb, 2013, 08:17 
User avatar

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


 

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