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.

Average Price
 Post subject: Average Price Post rating: 0   New post Posted: Tue 21 Dec, 2010, 11:09 

User rating: 0
Joined: Mon 04 Oct, 2010, 15:11
Posts: 3
Since I can programme the average price of several income?


 
 Post subject: Re: Average Price Post rating: 0   New post Posted: Mon 27 Dec, 2010, 09:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Could you please clarify what exactly do you need?


 
 Post subject: Re: Average Price Post rating: 0   New post Posted: Mon 10 Jan, 2011, 12:44 

User rating: 0
Joined: Mon 04 Oct, 2010, 15:11
Posts: 3
Support wrote:
Hi,
Could you please clarify what exactly do you need?

That instruction of program is in use for determining the average price of several positions?


 
 Post subject: Re: Average Price Post rating: 0   New post Posted: Tue 18 Jan, 2011, 18:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please consider the following code to calculate filled orders average price:
    public void calculateAveragePrice() throws JFException {
       double sumOfPrices = 0;
       int orderCount = 0;
       for (IOrder order: engine.getOrders()) {
          if (order.getState().equals(IOrder.State.FILLED)){
             sumOfPrices += order.getOpenPrice();
             orderCount ++;
          }
       }
       console.getOut().println("Aerage price for " + orderCount + " orders: " + (sumOfPrices/ orderCount));
    }


 

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