|
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.
Simple hedge - plz help |
Inzider
|
Post subject: Simple hedge - plz help |
Post rating: 0
|
Posted: Sun 11 Jan, 2015, 00:09
|
|
User rating: 0
Joined: Thu 01 Jan, 2015, 19:30 Posts: 5 Location: CanadaCanada
|
Please help!
I been searching for similar code, trying to learn java, Jvisual, tested/compiled code, etc... kinda frustrated now.
I want a simple hedging strategy that would:
1- put 2 opposite order of half open position at market, at let say 20 and 40 pips. 2-that would activate only over a specific lot size enter on the market order, exemple 0.1 million 3-if possible that both order get erase when original order get close 4-if possible, both hedge order should adapt to partial close of original market order and even erase under a specific remaining amouth, exemple 0.01 million.
It need not to affect previous orders already opens.
I would like to have the file into a java format so I can manage it under my live account without complication as Jvisual do for me.
This would be very kind! Thx in advance.
|
|
|
|
 |
API Support
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Mon 12 Jan, 2015, 09:29
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
tcsabina
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Mon 12 Jan, 2015, 15:16
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
Hi,
It is easier to start step by step. Easier for you understand the steps that you have implemented, and it is easier also to offer help in a particular problem. As Support pointed out, there are tons of examples in the wiki basically about everything. If you try to create/code something, and face issues, just create a topic specifically with that problem.
Alternatively you could consider hiring someone to do the coding.
|
|
|
|
 |
Inzider
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Wed 14 Jan, 2015, 14:25
|
|
User rating: 0
Joined: Thu 01 Jan, 2015, 19:30 Posts: 5 Location: CanadaCanada
|
Hi, Thx for both of your reply. As said I tried to take some codes (opposite orders was one of them) and modified it but if I get it to compile, then over the historical tester I get the error message : ''cannot create label for order that already exist.'' All I'm hoping is that someone who know java coding look at my prototype and find the mistake. Most of the structure must be good, it just need a little fix I bet. Im surely not asking for someone here to do the full job for me, I will pay if this attempt dosen't work. code attach - thx! tcsabina wrote: Hi,
It is easier to start step by step. Easier for you understand the steps that you have implemented, and it is easier also to offer help in a particular problem. As Support pointed out, there are tons of examples in the wiki basically about everything. If you try to create/code something, and face issues, just create a topic specifically with that problem.
Alternatively you could consider hiring someone to do the coding.
Attachments: |
DoubleHedgeBeta1.java [3.63 KiB]
Downloaded 69 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.
|
|
|
|
|
 |
tcsabina
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Wed 14 Jan, 2015, 20:55
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
Hi, For the error that you have mentioned ("cannot create label for order that already exist"): You have to create a unique label for every order. This can be done several ways, a plain simple example is: //For Filled Long--- if (isLong) { //Double Hedge long orders engine.submitOrder("BUY1" + System.currentTimeMillis(), selectedInstrument, OrderCommand.SELLSTOP_BYASK, (order.getAmount()/2), order.getOpenPrice()- (instrument.getPipValue()*hedge1)); engine.submitOrder("BUY2" + System.currentTimeMillis(), selectedInstrument, OrderCommand.SELLSTOP_BYASK, (order.getAmount()/2), order.getOpenPrice()- (instrument.getPipValue()*hedge2)); } // For filled Short--- if (isShort) { //Double Hedge Short orders engine.submitOrder("SELL1" + System.currentTimeMillis(), selectedInstrument, OrderCommand.BUYSTOP_BYBID, (order.getAmount()/2), order.getOpenPrice()- (instrument.getPipValue()*hedge1)); engine.submitOrder("SELL2" + System.currentTimeMillis(), selectedInstrument, OrderCommand.BUYSTOP_BYBID, (order.getAmount()/2), order.getOpenPrice()- (instrument.getPipValue()*hedge2)); }
|
|
|
|
 |
Inzider
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Thu 15 Jan, 2015, 02:00
|
|
User rating: 0
Joined: Thu 01 Jan, 2015, 19:30 Posts: 5 Location: CanadaCanada
|
Again, thx you very much for your reply, its really appreciated. Here are both of the errors I get trying what you suggested: 1-00:33:39 com.dukascopy.api.JFException: Label not unique(code 1). (Order already exists) [SELL11421282028110]:label=SELL11421282028110;getId()=null;groupId=null;openingOrderId=null;pendingOrderId=null;pendingOrderCommand=null;parentOrderId=null;tpOrderId=null;slOrderId=null;state=CREATED;instrument=GBP/JPY;openPrice=186.80407;requestedAmount=0.0075;amount=0.0075;lastServerRequest=SUBMIT;awaitingResubmit=false;localCreationTime=1421282028110; @ dukascopy.strategies.DoubleHedgeBeta1.onTick(DoubleHedgeBeta1.java:76) 2-00:33:39 Order REJECTED: CONDITIONAL BUY GBP/JPY, REASON: Invalid price format - please use increments of 0.1 pip. Maby another part of the code is wrong as I wonder why if I don't include this part : for (IOrder order: engine.getOrders()) {if (!orderMap.containsKey(order)) {orderMap.put(order, false);} it dosen't compile and say : ''order canno't be resolved.'' I try to do it step by step whit a simple logic: when a market order is filled, open 2 opposites orders of half size of market at x pips of opening price . If I just get this to work I would be Super happy! I'll push my luck a little further with nice ppl like you. If not, I'll evaluate if I'm ready to pay the price asked. Inz tcsabina wrote: Hi,
For the error that you have mentioned ("cannot create label for order that already exist"): You have to create a unique label for every order. This can be done several ways, a plain simple example is:
|
|
|
|
 |
API Support
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Thu 15 Jan, 2015, 08:35
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
Inzider
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Sun 25 Jan, 2015, 06:59
|
|
User rating: 0
Joined: Thu 01 Jan, 2015, 19:30 Posts: 5 Location: CanadaCanada
|
API Support wrote: Quote: 2-00:33:39 Order REJECTED: CONDITIONAL BUY GBP/JPY, REASON: Invalid price format - please use increments of 0.1 pip. Take a look at this example: https://www.dukascopy.com/wiki/#Rounding_pricesHi, How can I make the strategy make the difference in between a market order that been filled and a conditional one (pending/hedge). The opposite order code makes the strategy buy at start, so it easy just to send another order after it... I'm trying to create a second order when a market order is submitted (filled), not a pending one. Any way to make the difference in the code? Thx for your answer and help.
|
|
|
|
 |
API Support
|
Post subject: Re: Simple hedge - plz help |
Post rating: 0
|
Posted: Mon 26 Jan, 2015, 08:56
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Quote: How can I make the strategy make the difference in between a market order that been filled and a conditional one (pending/hedge). You can find the difference by order state, see this for details: https://www.dukascopy.com/wiki/#Order_stateQuote: The opposite order code makes the strategy buy at start, so it easy just to send another order after it... I'm trying to create a second order when a market order is submitted (filled), not a pending one. Any way to make the difference in the code? See code example: // submit first order IOrder order1 = engine.submitOrder("test1", Instrument.EURUSD, OrderCommand.BUY, 0.001); // wait until it's filled order1.waitForUpdate(IOrder.State.FILLED); // submit second order after first has been filled engine.submitOrder("test2", Instrument.EURUSD, OrderCommand.BUY, 0.001);
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|