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.

Risk Management
 Post subject: Risk Management Post rating: 0   New post Posted: Mon 06 Feb, 2012, 11:59 

User rating: 0
Joined: Mon 23 Jan, 2012, 20:42
Posts: 5
Location: SwitzerlandSwitzerland
Hi,

I am encountering a small problem.
My account is in CHF. I need a function that calculates the amount that I have to put in a currency, knowing that my stop is x pips and that I want a maximum risk of 3% of my account value in the base currency.

For example:
I would like to take a position in EURUSD with a stop of 50 pips.
Account value CHF 15000. I don't want to loose more than 3% (CHF 450).
What would be the amount of EURUSD I should take for these above parameters.

Can you help me with such a function ?

Many thanks in advance !


 
 Post subject: Re: Risk Management Post rating: 0   New post Posted: Wed 08 Feb, 2012, 15:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please consider the following code

        ITick tickEURCHF = history.getLastTick(Instrument.EURCHF);
        double risk = 0.01;
        double stopLossPips = 20;
       
        double riskAmountEUR = account.getEquity() * tickEURCHF.getAsk() * risk;
        double riskAmountMilEUR = riskAmountEUR / 1000000; // amount is counted in millions not ones
        double orderAmountMilEUR = riskAmountMilEUR / (Instrument.EURUSD.getPipValue() * stopLossPips);
       
        print(orderAmountMilEUR);


 
 Post subject: Re: Risk Management Post rating: 0   New post Posted: Thu 09 Feb, 2012, 12:47 
User avatar

User rating: 2
Joined: Tue 16 Aug, 2011, 19:01
Posts: 70
Location: ItalyItaly
Hi Support,
a consideration:

let's suppose:
1. I have an account in CHF
2. I have 15000 CHF
3. EURCHF = 1.2103

so in EUR I'll have

15000 CHF / 1.2103 = 12393.62 €


so the line 5 should be

double riskAmountEUR = (account.getEquity() / tickEURCHF.getAsk() ) * risk;



Best regards,
Frank


 

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