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.

Probleme calculating drawdown with getBaseEquity() and getEquity()
 Post subject: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Tue 22 Oct, 2013, 11:41 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hi,

It's been a while since I haven't posted !

My strategy can open up to 16 orders with very low leverage at the same time.
Instead of putting a stoploss on each order, it calculates the total profit/loss in % for all opened orders.
If the total amount of opened order losses is bigger than 2% of the account equity, it is closing all positions.

When I backtest, the problem is that getBaseEquity() returns a number where the price never managed
to go, causing my trades to be stopped out to early.

I tried to retrieve manually getBaseEquity() by using getProfitLossInAccountCurrency(), the same issue.
I tried to replace getBaseEquity() with getBalance(), the same issue.

Maybe the problem is coming from getProfitLossInAccountCurrency() not returning the result
in the account currency of the backtest (EURO) but in USD ?

For an easier understanding please see the screenshot bellow and a part of my code.
If you have an other working solution I'll be glad.

Thanks for helping me.
Best regards
Nicolas.

Image

Here is my code in onBar :

  double pctProfitLossTotal = 0;
        double pctProfitLossBalance = 0;
        double baseAccountEquity = 0;
        double currentAccountEquity = 0;

        if (period.equals(Period.ONE_MIN) && instrument == Instrument.EURUSD) {

            double totalProfitLoss = 0;
            baseAccountEquity = account.getBaseEquity();
            currentAccountEquity = account.getEquity();


            for (IOrder order : engine.getOrders()) {
                if (order.getState() == IOrder.State.FILLED) {
                    totalProfitLoss = totalProfitLoss + order.getProfitLossInAccountCurrency();
                }
            }

            double currentBalance = account.getBalance();
            pctProfitLossBalance = roundFloor(((currentAccountEquity - currentBalance) / currentBalance) * 100, 100);
            pctProfitLossTotal = roundFloor(((currentAccountEquity - (currentAccountEquity - totalProfitLoss)) / (currentAccountEquity - totalProfitLoss)) * 100, 100);
            pctProfitLoss = roundFloor(((currentAccountEquity - baseAccountEquity) / baseAccountEquity) * 100, 100);

            if (pctProfitLoss < maxPctEquityLoss) {

                for (IOrder order : engine.getOrders()) {
                    order.close();
                }
            }
        }

        if (period.equals(Period.ONE_MIN)) {
            commentOnChart(instrument, "currentAccountEquity : " + String.valueOf(currentAccountEquity) + "\n"
                    + "baseAccountEquity : " + String.valueOf(baseAccountEquity) + "\n"
                    + "Equity P/L : " + String.valueOf(pctProfitLoss) + "%\n"
                    + "Balance P/L : " + String.valueOf(pctProfitLossBalance) + "%\n"
                    + "Total P/L : " + String.valueOf(pctProfitLossTotal) + "%\n");
        }


 
 Post subject: Re: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Thu 24 Oct, 2013, 15:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please extract a full example strategy which replicates the case. Please provide a screenshot of the Historical Settings that you use.


 
 Post subject: Re: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Thu 24 Oct, 2013, 15:58 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hi,

How can I send you my complete strategy personally ? I don't want to post it on the forum.
It should reproduce the issue on your computer without any doubt.
But I should warn you, it is quite messy at the time because I'm in the research process.

Best regards
Nicolas


 
 Post subject: Re: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Thu 24 Oct, 2013, 16:07 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Drop a mail to [email protected], with of course the problem description.


 
 Post subject: Re: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Thu 24 Oct, 2013, 20:38 

User rating: 3
Joined: Sat 04 May, 2013, 03:34
Posts: 33
Location: CanadaCanada
I wrote a strategy which is close to what you want. I ran into the same issue. You have to know where in the loop you calculate it

viewtopic.php?f=65&t=50121


It is based off a Free Dukascopy Strategy in the JSTORE
Search JSTORE for a Strat called "Total Stop Loss"

Description
A strategy shows an example how to limit a total loss to some percent of an initial account equity.


 
 Post subject: Re: Probleme calculating drawdown with getBaseEquity() and getEquity() Post rating: 0   Post Posted: Fri 25 Oct, 2013, 07:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
nicofr0707 wrote:
How can I send you my complete strategy personally ? I don't want to post it on the forum.
We did not ask you for the original strategy, we ask you to create a case - an example strategy which replicates the case and the launch conditions, i.e., Historical Tester settings.


 

Jump to:  

  © 1998-2026 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