|
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.
calculating rate of return |
cb888trader
|
Post subject: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 08:16
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
please advice how to:
given an amount and a target profit (USD) : open an order with a dynamic take profit level so that if the take profit is reached it will cover the losses of all currently opened (filled) orders.
|
|
|
|
 |
API Support
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 08:34
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 08:57
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
I'm sorry - I reviewed the links and it does not help.
please advice a code example of:
how to calculate a take profit level of a new order such that if price hits the take profit level - the profit will overcome all loosing open orders.
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 12:36
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
support - please help me with this. I cannot proceed without a code example.
|
|
|
|
 |
API Support
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 13:43
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Please specify which part of the algorithm you can't figure out how to implement.
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Wed 21 Nov, 2012, 15:38
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
Iterate over open orders and calculate: TotalGrossProfit TotalCommissions
TotalNet = TotalGrossProfit - TotalCommissions
Up to now I'm OK.
FutureCommission = Calculate the expected commission for the new order - How to Calculate??
FutureProfit = TotalNet + FutureCommission
TargetPrice = calculate based on the required FutureProfit How to Calculate??
For example: Total Net Profit of open orders is -$20
Lot Size = 0.1
FutureCommision = ?? TargetPrice = ??
Open new order with take profit set to TargetPrice
If Take Profit is reached - Total Profit = 0 (break even)
Please Help.
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Thu 22 Nov, 2012, 11:29
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
support - please respond.
|
|
|
|
 |
API Support
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Thu 22 Nov, 2012, 16:39
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
cb888trader wrote: FutureCommission = Calculate the expected commission for the new order - How to Calculate?? Commisions get applied to positions both on fill and close and can be retrieved by IOrder.getCommission, see: https://www.dukascopy.com/swiss/english/about/fee-schedule/#tradingCommissionsHence, in that regard there is no "future commission". However, all open positions are subject to overnight swaps, rates of which can be found here: https://www.dukascopy.com/swiss/english/forex/forex_trading_accounts/overnight/#Overnights don't count towards the commission, rather the overnight swap amount gets distracted from/added to the position by adjusting its open price. cb888trader wrote: Lot Size = 0.1
FutureCommision = ?? TargetPrice = ??
Open new order with take profit set to TargetPrice As mentioned above, there is no "future commission", then consider an approach similar to this: package jforex.orders;
import java.math.BigDecimal; import com.dukascopy.api.*; import static com.dukascopy.api.Instrument.*;
public class OrderCommissionsCompensate implements IStrategy { @Configurable("Order amount") public double amount = 0.1; private static final int MILLION = 1000000; private IEngine engine; private IConsole console; private IHistory history; @Override public void onStart(IContext context) throws JFException { engine = context.getEngine(); console = context.getConsole(); history = context.getHistory(); double totalCommission = 0; for(IOrder order : engine.getOrders()){ totalCommission += order.getCommissionInUSD(); } double openPrice = history.getLastTick(EURUSD).getBid(); double tpPrice = openPrice + totalCommission /(amount * MILLION); print("Total commission = %.2fUSD, tpPrice=%.5f, tp in pips=%.1f", totalCommission, tpPrice, ( tpPrice - openPrice) / EURUSD.getPipValue()); engine.submitOrder("compensateOrder", EURUSD, IEngine.OrderCommand.BUY, amount, openPrice, 10, 0, roundToPippette(tpPrice, EURUSD)); } private void print(Object o){ console.getOut().println(o); } private void print(String message, Object... args){ print(String.format(message,args)); } private static double roundToPippette(double amount, Instrument instrument) { return round(amount, instrument.getPipScale() + 1); } private static double round(double amount, int decimalPlaces) { return (new BigDecimal(amount)).setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP).doubleValue(); }
@Override public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
@Override public void onMessage(IMessage message) throws JFException {}
@Override public void onAccount(IAccount account) throws JFException {}
@Override public void onStop() throws JFException {}
}
Note that if the position will not get closed by merge then you need to double its amount i.e.: totalCommission += order.getCommissionInUSD();
Attachments: |
OrderCommissionsCompensate.java [2.15 KiB]
Downloaded 451 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.
|
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Thu 22 Nov, 2012, 17:43
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
can you please explain the following calculation:
totalCommission /(amount * MILLION)
MILLION = 1000000 is true if working in other currencies as well??
|
|
|
|
 |
API Support
|
Post subject: Re: calculating take profit |
Post rating: 0
|
Posted: Thu 22 Nov, 2012, 17:56
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
cb888trader
|
Post subject: calculating rate of return |
Post rating: 0
|
Posted: Wed 05 Dec, 2012, 06:36
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
I need help on how to calculate the rate of return per order -
Net Profit / Initial Investment
So -
Net Profit = getProfitLossInUSD - getCommissionInUSD (right?)
But how do I calculate Initial Investment (how much money did I payed in order to buy / sell ) ?
Please advice.
|
|
|
|
 |
API Support
|
Post subject: Re: calculating rate of return |
Post rating: 0
|
Posted: Wed 05 Dec, 2012, 08:21
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating rate of return |
Post rating: 0
|
Posted: Wed 05 Dec, 2012, 09:12
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
I don't understand -
Are you saying that:
Initial Investment = amount * MILLION ?
But what about the price at which the order was filled - how is that taken into the equation?
Can you please provide the formula for Initial Investment and not ask me to guess?
|
|
|
|
 |
API Support
|
Post subject: Re: calculating rate of return |
Post rating: 0
|
Posted: Wed 05 Dec, 2012, 09:39
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
cb888trader wrote: I don't understand -
Are you saying that:
Initial Investment = amount * MILLION ? Which place in our example made you infer that? cb888trader wrote: But what about the price at which the order was filled - how is that taken into the equation?
Can you please provide the formula for Initial Investment and not ask me to guess? You don't need to guess, it is rather straightforward: IOrder.getOpenPrice * IOrder.getAmount
|
|
|
|
 |
cb888trader
|
Post subject: Re: calculating rate of return |
Post rating: 0
|
Posted: Wed 05 Dec, 2012, 10:57
|
|
User rating: 0
Joined: Tue 22 Nov, 2011, 12:47 Posts: 130 Location: United States,
|
API Support wrote: Can you please provide a more complete calculation? I don't see the MILLION param. Also - please add support for multiple currencies.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|