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.

equity and rounded lots ??
 Post subject: equity and rounded lots ?? Post rating: 0   New post Posted: Fri 07 Jan, 2011, 11:00 

User rating: 0
Joined: Thu 02 Dec, 2010, 10:43
Posts: 2
Hello,
I have this linecode for setting the lot amount:
double Lot = eq/bidBar.getOpen()/1000*prc/100;

which give not rounded lots amount (for example 0.0023 or 0.0452, etc.)

How can I have round lots amount (with a leverage 2)
for example
if equity=0.01053 lot= 0.02 (rounded equity*2)
if equity=0.01103 lot= 0.022
if equity=0.01199 lot= 0.022
if equity=0.01201 lot= 0.024

Do I have to use something like round.math() or something else?
Thank you


 
 Post subject: Re: equity and rounded lots ?? Post rating: 0   New post Posted: Fri 21 Jan, 2011, 10:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Sorry for not answering for a long time. If you want to truncate a double number to 3 digits after comma, you need to multiple the number with 1000, convert a number to a long type, then divide the number with 1000 and convert to a double:
private double truncate(double x) {
   long y = (long) (x * 1000);
   return (double) y / 1000;
}

To calculate an order amount based on the account equity, please try the following code:
      double lot = truncate(account.getEquity())*2;


 

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