|
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.
Child Accounts linked to main accounts |
zhao
|
Post subject: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Mon 28 May, 2012, 13:34
|
|
User rating: 0
Joined: Sun 27 May, 2012, 11:48 Posts: 13
|
hello Admin,
is it possible to do the following?
assume my account is $50000
I want to trade the 2 or more pairs in the same strategy and each pair i want to allocate only 10000 each. is it possible to keep track of the equity balance for each pair? for example: allocate 10k for EURUSD and another 10k for GBPUSD out of the 50k in the account.
thank you
|
|
|
|
 |
API Support
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Mon 28 May, 2012, 14:16
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
zhao wrote: is it possible to keep track of the equity balance for each pair? You can retrieve all active instrument orders by IEngine.getOrders(Instrument instrument) and then before submitting a new order check if the new order amount will make the total instrument equity to get exceeded. See more here: https://www.dukascopy.com/wiki/#Order_Management
|
|
|
|
 |
zhao
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Mon 28 May, 2012, 16:30
|
|
User rating: 0
Joined: Sun 27 May, 2012, 11:48 Posts: 13
|
Hello Admin,
how do i keep track of the Profit and Loss then per instrument equity?
e.g if i allocated 10k each to EURUSD and GBPUSD, when there are TP or SL for each instrument how do i keep track of it?
best regards.
|
|
|
|
 |
API Support
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Tue 29 May, 2012, 08:27
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
zhao wrote: how do i keep track of the Profit and Loss then per instrument equity? See https://www.dukascopy.com/wiki/#Order_Management the example "Get all profitable/losing orders". There you just remove the if condition and sum all order profit/losses.
|
|
|
|
 |
zhao
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Tue 29 May, 2012, 15:10
|
|
User rating: 0
Joined: Sun 27 May, 2012, 11:48 Posts: 13
|
Hello APISupport,
is it possible to have child equity account linked to the main account?
e.g My equity account is $50k, my strategy will create 2 child accounts each $10K. My strategy will then treat each child account like a main account, one child account will be used to trade EURUSD while the other will trade USDCHF, and when trading EURUSD, the strategy will only see $10k but profits and loss will also be reflected in the main account.
is it possible?
|
|
|
|
 |
API Support
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Wed 30 May, 2012, 08:08
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
zhao wrote: is it possible to have child equity account linked to the main account? It is possible to emulate such logic in your strategy, but it is not possible to set it up from platform side.
|
|
|
|
 |
zhao
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Wed 30 May, 2012, 10:47
|
|
User rating: 0
Joined: Sun 27 May, 2012, 11:48 Posts: 13
|
Hello APISupport,
do you have some example code on how to emulate it in code?
best regards.
|
|
|
|
 |
API Support
|
Post subject: Re: 1 Equity Account Per pairs |
Post rating: 0
|
Posted: Wed 30 May, 2012, 12:05
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
zhao
|
Post subject: Child Accounts linked to main accounts |
Post rating: 0
|
Posted: Wed 30 May, 2012, 12:24
|
|
User rating: 0
Joined: Sun 27 May, 2012, 11:48 Posts: 13
|
hello APISupport,
i wish to do the following.
assume my current account has $50K.
In my strategy, i want to have child accounts. each child account will have a fraction of the current account of 50K, the total amount of money in all child accounts must be equal or less compared to the main account.
so if i want to have 2 child accounts each with 10K.
so ChildAccount1 = $10k ChildAccount 2 = $10K
ChildAccount1 will be used to trade EURUSD or any other instruments ChildAccount2 will be used to trade EURCHF or EURUSD or other instruments
i should be able to call ChildAccount1.getEquity() or similiar to get the equity in ChildAccount1, of cos the main account will still keep track of the overall equity.
can this be done?
|
|
|
|
 |
API Support
|
Post subject: Re: Child Accounts linked to main accounts |
Post rating: 0
|
Posted: Thu 21 Jun, 2012, 12:37
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Find the instructions in the source code: package jforex.account;
import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;
import com.dukascopy.api.*; import static com.dukascopy.api.Instrument.*;
/** * The strategy demonstrates how to maintain multiple sub-accounts * and calculate their equities. * * In order to test the strategy, launch it with live-data and do * manual trading with the instruments that have been defined for the mini accounts * */ public class MutliEquities implements IStrategy {
private IConsole console; private List<MiniAccount> miniAccounts = new ArrayList<MiniAccount>(); MiniAccount eurAccount, usdAccount; @Override public void onStart(IContext context) throws JFException { console = context.getConsole();
//define two mini accounts with base equity of 10K USD and designated set of instruments miniAccounts.add(new MiniAccount(10000, EURUSD, EURCHF)); miniAccounts.add(new MiniAccount(10000, USDCAD, USDJPY, USDCHF)); }
@Override public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if(instrument != Instrument.EURUSD || period != Period.TEN_SECS){ return; } //print data of all sub-accounts for (MiniAccount miniAccount : miniAccounts){ console.getOut().println(miniAccount); } }
@Override public void onMessage(IMessage message) throws JFException { //on any order fill add it to MiniAccount which has the particular instrument if(message.getType() == IMessage.Type.ORDER_FILL_OK){ IOrder order =message.getOrder(); //add order to particular mini account if the mini account has the order's instrument for (MiniAccount miniAccount : miniAccounts){ if(miniAccount.hasInstrument(order.getInstrument())){ miniAccount.addOrder(order); } } } }
@Override public void onAccount(IAccount account) throws JFException {}
@Override public void onStop() throws JFException {}
}
/** * The class represents a sub-account which has a designated base equity * and contains its own set of orders */ class MiniAccount { private final List<IOrder> orders = new ArrayList<IOrder>(); private final Set<Instrument> instruments; private final double baseEquity; public MiniAccount (double baseEquity, Instrument...instruments){ this.instruments = new HashSet<Instrument> (Arrays.asList(instruments)); this.baseEquity = baseEquity; } public void addOrder (IOrder order){ orders.add(order); } public boolean hasInstrument(Instrument instrument){ return instruments.contains(instrument); } public double getEquity(){ double profitLoss = 0d; for (IOrder o : orders){ profitLoss += o.getProfitLossInUSD(); } double equity = baseEquity + profitLoss; return equity; } @Override public String toString(){ return String.format("%s account of base equity %.5f has %s orders and current equity: %.5f", instruments.toString(), baseEquity, orders.size(), getEquity()); } }
Attachments: |
MutliEquities.java [3.51 KiB]
Downloaded 348 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|