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.

Positions merger question
 Post subject: Positions merger question Post rating: 0   New post Posted: Wed 01 Apr, 2015, 11:34 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
Hello,

I'm testing automated strategy for positions merging. After I tried to merge positions I got the following error (full log at the end of the message):
Quote:
09:05:22 java.lang.NullPointerException @ com.dukascopy.api.impl.connect.ct.onMessage(Unknown Source)


The merger code where exeception probably happened looks like that (nothing unusual):
IOrder mergedO = engine.mergeOrders(tmpLabel, o1, o2);
IMessage message = mergedO.waitForUpdate(5, TimeUnit.SECONDS);


I suspect that cause of the error was very long merger execution (14 seconds!!!).

The merger technique is very convenient but I thought that it works immediately. To merge two positions I have to disable all stop-losses, so after I've noticed aforementioned situation it seems the technique is very risky. Is the phenomenon common or rather rare on production site? Should I manage individual positions instead of merging all positions to one? Alternative technique that is changing many stop-losses for each position is inconvenient but works immediately and in this context seems safer...

BTW Could you add mergeOrders method with stop-loss/take-profit as parameters and no need to disable stop-losses/take-profit in advance?

Best regards,
FXer

Full log:
Quote:
09:05:31 Positions: 80582864; 80582835 MERGED to position: 80583397
09:05:22 Strategy "STradeManagePos" is stopped at 2015-04-01 09:05:22.483 GMT on the local computer with parameters "instrument"=[EUR/USD], "reference1"=[ONEWAY], "hoursBack"=[0], "transactionCostInPips"=[1.0], "slippageSafeguardInPips"=[0.6]. Reason: Stopped by Engine
09:05:22 Stopping "STradeManagePos" strategy at 2015-04-01 09:05:22.471 GMT on the local computer
09:05:22 java.lang.NullPointerException @ com.dukascopy.api.impl.connect.ct.onMessage(Unknown Source)
09:05:17 Merge in progress...
09:05:17 Merge request with label jf1i668r11 sent for positions: 80582864, 80582835 at 2015-04-01 09:05:17.427 GMT by the strategy "STradeManagePos": from the local computer
09:05:17 Order CANCELLED: #305926385 Parent Order #305926378 STOP LOSS BUY 0.001 mil. EUR/USD @ MKT IF BID => 1.074 - Position #80582835
09:05:17 Canceling order #305926385 STOP LOSS BUY 1000 EUR/USD @ MKT IF BID => 1.074 at 2015-04-01 09:05:17.075 GMT by the strategy "STradeManagePos": from the local computer
09:05:17 Order FILLED at 1.07255 (#305927111 STOP SELL 0.001 mil. EUR/USD @ MKT IF BID <= 1.07255 EXPIRES: GTC) - Position #80582864
09:03:23 Position 80582864 ENTRY #305927111 price changed from 1.07180 to 1.07255
09:03:23 Order #305927111 ENTRY SELL 1000 EUR/USD @ MKT IF BID <= 1.07255 EXPIRES: GTC had been sent at 2015-04-01 09:03:23 manually
08:58:05 Order ACCEPTED: #305927111 STOP SELL 0.001 mil. EUR/USD @ MKT IF BID <= 1.0718 - Position #80582864
08:58:05 Order ENTRY SELL 1000 EUR/USD @ MKT IF BID <= 1.07180 had been sent at 2015-04-01 08:58:05 manually
08:58:05 Sending order: ENTRY SELL 0.001 mil. EUR/USD @ MKT IF BID <= 1.0718
08:57:01 Order CANCELLED: #305926379 STOP LOSS BUY 0.001 mil. EUR/USD @ MKT IF ASK => 1.074 - Position #80582835
08:57:01 Order ACCEPTED: #305926385 Parent Order #305926379 STOP LOSS BUY 0.001 mil. EUR/USD @ MKT IF BID => 1.074 - Position #80582835
08:57:01 Order FILLED at 1.07347 (#305926378 SELL 0.001 mil. EUR/USD @ MKT) - Position #80582835
08:57:01 Order ACCEPTED: #305926379 STOP LOSS BUY 0.001 mil. EUR/USD @ MKT IF ASK => 1.074 - Position #80582835
08:57:01 Order ACCEPTED: #305926378 SELL 0.001 mil. EUR/USD @ MKT - Position #80582835
08:57:01 Order SELL 1000 EUR/USD @ MKT had been sent at 2015-04-01 08:57:01 manually
08:57:01 Sending order: STOP LOSS BUY 0.001 mil. EUR/USD @ MKT IF ASK => 1.074
08:57:01 Sending order: SELL 0.001 mil. EUR/USD @ MKT MAX SLIPPAGE 0.001


 
 Post subject: Re: Positions merger question Post rating: 0   New post Posted: Wed 01 Apr, 2015, 20:04 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

Solving NPE is quite difficult without the actual code. So I suggest to attach the strategy, or send it to support, if it is confidential.

Where do you see this 14 second merge process? In the attached log there is only 5 second visible:
Quote:
09:05:22 java.lang.NullPointerException @ com.dukascopy.api.impl.connect.ct.onMessage(Unknown Source)
09:05:17 Merge in progress...
...
09:05:17 Order FILLED...


But still, 5 seconds are quite long. Again, seeing the strategy itself would be useful to be able to help.

The Merge Positions wiki page contains lots of examples about merging. I suggest to take a quick look, if you haven't done before. Maybe you will discover some issues in the merging logic of your strategy.

Quote:
BTW Could you add mergeOrders method with stop-loss/take-profit as parameters and no need to disable stop-losses/take-profit in advance?

I am pretty sure this is not going to happen ;).


 
 Post subject: Re: Positions merger question Post rating: 0   New post Posted: Wed 01 Apr, 2015, 20:14 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Also, there are lots of examples in the forum as well. For example:
https://www.dukascopy.com/swiss/english ... 78&p=60337
https://www.dukascopy.com/swiss/english ... 81&p=74907
https://www.dukascopy.com/swiss/english ... 26&p=82690


 
 Post subject: Re: Positions merger question Post rating: 0   New post Posted: Mon 06 Apr, 2015, 22:53 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
Hi,

Thank you for all the links to the forum - a lot of useful pieces of information :-) I've read wiki before and I believe that my strategy follows the rules... In the hindsight I think the problem was that for testing I was using Linux with OpenJDK-7. I have migrated to the Oracle 8 JVM and I believe there will be no such problem anymore.

Best regards,
FXer

PS BTW the 14 seconds is the time between merger start and merger end:
Quote:
09:05:31 Positions: 80582864; 80582835 MERGED to position: 80583397
...
09:05:17 Merge in progress...


 

Jump to:  

cron
  © 1998-2025 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