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.

Order and modification processing
 Post subject: Order and modification processing Post rating: 0   New post Posted: Sun 26 Oct, 2008, 23:04 

User rating: 0
Joined: Thu 27 Mar, 2008, 13:06
Posts: 18
Hello,

I would like know how the pending orders are processed. For example, when I send SELLSTOP with slippage and there will be only partial fill of this order.
Then I have 2 orders? First one is still pending order (SELLSTOP which wasn't executed yet) and second is executed part of this sellstop?
If yes, the labels of these orders are same (same as I set into submit method)?
OrderCommand of executed part is a SELL? I need know, how I can recognize executed part of order when I pass list of orders.


I trail my SL each tick in my way and I noticed that there can occur this thing:
I move SL by this way
if(order.getStopLossPrice()>normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue()))){
          order.setStopLossPrice(normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue())));
          print("SHORT SL modification  "+normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue())));
}

But when I get new tick which have higher Ask than previous tick and previous modification wasn't done yet, then I send next modification but I shouldn't send this request because my previous modification was below.

Here is a log of second modification when it set higher SL and there was error:
10:30:03:299 => -onTick(GBP/USD,1.5652/1.5644, spread: 8)
10:30:03:299 => SHORT SL modification 1.5657
10:30:03:533 => -onTick(GBP/USD,1.56555/1.564, spread: 15)
10:30:03:533 => SHORT SL modification 1.5661
10:30:03:580 => -onMessage(MessageType ORDER_CHANGED_OK Text null Related order [GDP2]-FILLED/GBP/USD/0.175)
10:30:03:596 => -onMessage(MessageType ORDER_CHANGED_OK Text null Related order [GDP2]-FILLED/GBP/USD/0.175)

Is there any way how I can send modification and wait for result?

Thanks DarkMan


 
 Post subject: Re: Order and modification processing Post rating: 0   New post Posted: Mon 27 Oct, 2008, 16:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

JForex API shows both of them in one order, order changes it's state to FILLED and returns only filled amount if you call getAmount method, while getRequestedAmount returns the amount you requested. When remaining part will be filled you will get one more ORDER_FILLED_OK message. Javadoc for IOrder.State.FILLED says about that.

All requests to the server are sent asynchronously, that means you don't get your changes accepted just after you sent the request. That's why we added IOrder.waitForUpdate method, it blocks current thread and no ticks are sent until something is changed in order, which happens when your change gets accepted by server and successful response received by the client. Try changing your code as following:
if(order.getStopLossPrice()>normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue()))){
          order.setStopLossPrice(normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue())));
          //wait until changes are accepted or until 10 seconds passed
          order.waitForUpdate(10 * 1000);
          print("SHORT SL modification  "+normalize(tick.getAsk()+(iSL*selectedInstrument.getPipValue())));
}


 
 Post subject: Re: Order and modification processing Post rating: 0   New post Posted: Mon 27 Oct, 2008, 22:03 

User rating: 0
Joined: Thu 27 Mar, 2008, 13:06
Posts: 18
Dmitry Shohov wrote:
JForex API shows both of them in one order, order changes it's state to FILLED and returns only filled amount if you call getAmount method, while getRequestedAmount returns the amount you requested. When remaining part will be filled you will get one more ORDER_FILLED_OK message. Javadoc for IOrder.State.FILLED says about that.


OK, so it means that I can't modify SL only for executed part of order?
I want to send order with initial SL and each new tick in my way I want to modify SL only for executed part of order.
I can't modify SL for pending order, because when market make retracement and execute remaining part of order
and SL will be lower than SELLSTOP (because was modified previously for first executed part) then I will immediately closed.


 
 Post subject: Re: Order and modification processing Post rating: 0   New post Posted: Tue 28 Oct, 2008, 12:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Do not use SL at all. If you need to close a part of executed order, just hedge this part.

In other words
1) You have BUY 10 mill. order. BUY 7 mill. is executed partially and BUY 3 mill. is still in pending state.
2) To set a STOP LOSS condition for the executed part, just set a SELL ENTRY ORDER for the executed amount. As well, for moitoring the SL condition, you can modify a price of this order.
3) So, in case of executing the ENTRY ORDER, you will have

Open positions:
+ 7 mill. (the executed part of initial order)
- 7 mill. (the executed etry order for SL condition)

Pending:
+ 3 mill. (still pending)

The global position in this case will be 0. Due to +7 and -7 are hedged. But do not forget to close (to merge) these positions before settlement (21:00 GMT) to avoid additional expenses because of swaps points.


 

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