Dukascopy
 
 
Wiki JStore Search Login

How to close a position with profit (rule 6.3)
 Post subject: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Wed 23 Jun, 2010, 10:23 
User avatar

User rating: 8
Joined: Wed 21 Apr, 2010, 10:42
Posts: 1167
Rule 6.3 says that "The maximum amount of profit on a single position should not exceed 50% of the balance of the previous day. If not, Dukascopy reserves the right to decrease the total balance of the account for the amount equal to the profit of the position."

So, how to make the strategy to close the position automatically when the profit is very close to 50% of Equity?

Our suggestion to you is to create a new function as follows:

   public void closeOrder() throws JFException {
      
      List<IOrder> orderList = engine.getOrders(myInstrument);
      for (IOrder order: orderList) {
         if (order.getState()== IOrder.State.FILLED) {
            if (order.getProfitLossInUSD()> (accountEquity-order.getProfitLossInUSD())*0.45) {
               order.close();
            }
         }
         
      }
      
   }



To retrieve the amount of Equity you need to declare a new variable and update it in onAccount method:

private double accountEquity;

   @Override
   public void onAccount(IAccount account) throws JFException {
      
      accountEquity = account.getEquity();

   }




 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Tue 29 Jun, 2010, 03:26 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
I think order.getState()== IOrder.State.OPENED should be order.getState()== IOrder.State.FILLED

as OPENED is for an order that's sent but not filled


 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Tue 29 Jun, 2010, 14:17 
User avatar

User rating: 8
Joined: Wed 21 Apr, 2010, 10:42
Posts: 1167
Yes, you're right! :oops:


 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Thu 01 Jul, 2010, 15:06 

User rating: 0
Joined: Tue 25 May, 2010, 04:21
Posts: 21
Contest Support wrote:
Yes, you're right! :oops:


I think that is why my first trade did not close with 50% profit. I did not pay much attention to this because I thought that since I am using the Dukascopy code, it should work. Now its too late and I cannot change the code.

According to the rule, I understand that the profit will be reduced and I won't be disqualified. I think my strategy will try to make profit more than 50% of previous balance(if the trade wins) all the time(in the entire competition if it works the way I intended).


 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Thu 01 Jul, 2010, 15:39 
User avatar

User rating: 8
Joined: Wed 21 Apr, 2010, 10:42
Posts: 1167
Arnab, please change the code of your strategy. But additionally, send us the code of old strategy along with strategy ID to [email protected]. We will take into account this change.


 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Thu 05 Aug, 2010, 10:00 

User rating: -
the rule 6.3 says a trade can not be close for more than 50% of the previous days equity with no restriction on length of trade. So, it might not necessarily be best to close a position whenever it hits 50% of previous day's equity in profit. If a position is held for several days, for example:

start with 100000 equity

- day one, trade hits 70% profit ( equity: 170'000 at end of day)
- day two, pull back of 30% (equity 119'000) , then climbs 60% ( equity 190'400)

at that point we close the trade. When the trade is closed, it is for less than 50% of the previous days equity (170'000 -> 190'400 => 12% increase). So we complied with the rule, but because it was held longer, we made more than 50% on the total trade.

Basically, as it is worded, rule 6.3 says a trade should not be closed for more than 50% of the equity of the previous day, but since there are no restricitions on how many days the trade can be left open, it just means that on the _last_ day of the trade we have to look at the previous day. So only the last day, and the one preceding day, counts.

Please confirm this !


 
 Post subject: Re: How to close a position with profit (rule 6.3) Post rating: 0   New post Posted: Fri 06 Aug, 2010, 09:53 
User avatar

User rating: 8
Joined: Wed 21 Apr, 2010, 10:42
Posts: 1167
The rules say:
Quote:
The maximum amount of profit on a single position should not exceed 50% of the balance of the previous day. If not, Dukascopy reserves the right to decrease the total balance of the account for the amount equal to the profit of the position.


This rule can be interpreted differently. When the positions is long term, it does not clarify which day is considered the previous. So, we will try to clarify this paragraph in more details for September. For the time being, you can still interpret it differently and trade in the way how you understand this rule.

however, the example code that we have published was also modified:

public void closeOrder() throws JFException {
     
      List<IOrder> orderList = engine.getOrders(myInstrument);
      for (IOrder order: orderList) {
         if (order.getState()== IOrder.State.FILLED) {
            if (order.getProfitLossInUSD()> (accountEquity-order.getProfitLossInUSD())*0.45) {
               order.close();
            }
         }
         
      }
     
   }




 

Jump to:  

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