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.

HistoricalTester: orders with take profit fill and close on same price
 Post subject: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Tue 16 Jul, 2013, 12:07 

User rating: 0
Joined: Tue 09 Apr, 2013, 14:14
Posts: 8
Location: SloveniaSlovenia
Expected: order will close on defined TP
Actually happening: order closes on same price as filled
Code used:
engine.submitOrder(getLabel(instrument), instrument, IEngine.OrderCommand.SELL, this.orderAmount, 0, 10, 0, tick.getBid() - this.parTakeProfit);
-getLabel - function included in the demo code


@1.3074 TP: 1.3073onMessage: ORDER_SUBMIT_OK - Order submitted order: OPENED SELL 0.001 @ 0.0 OID: 41

onMessage: ORDER_FILL_OK - Order filled order: FILLED SELL 0.001 @ 1.3074 OID: 41

onMessage: ORDER_CLOSE_OK - Order closed order: CLOSED SELL 0.001 @ 1.3074 OID: 41

@1.30717 TP: 1.30707onMessage: ORDER_SUBMIT_OK - Order submitted order: OPENED SELL 0.001 @ 0.0 OID: 42

onMessage: ORDER_FILL_OK - Order filled order: FILLED SELL 0.001 @ 1.30717 OID: 42

onMessage: ORDER_CLOSE_OK - Order closed order: CLOSED SELL 0.001 @ 1.30717 OID: 42

@1.30703 TP: 1.30693onMessage: ORDER_SUBMIT_OK - Order submitted order: OPENED SELL 0.001 @ 0.0 OID: 43

onMessage: ORDER_FILL_OK - Order filled order: FILLED SELL 0.001 @ 1.30703 OID: 43

onMessage: ORDER_CLOSE_OK - Order closed order: CLOSED SELL 0.001 @ 1.30703 OID: 43


 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Tue 16 Jul, 2013, 12:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide a full example strategy which replicates the case. Please provide a screenshot of the used Historical Tester settings.


 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Tue 16 Jul, 2013, 12:32 

User rating: 0
Joined: Tue 09 Apr, 2013, 14:14
Posts: 8
Location: SloveniaSlovenia
I just saw HistoricalTester is a jforex platform component not a jforex-sdk component. Evaluations are from jforex-sdk.

public void onTick(Instrument instrument, ITick tick) throws JFException {
        List<IOrder> openOrders = engine.getOrders(instrument);
        Double ask = tick.getAsk();
        Double bid = tick.getBid();

        if(openOrders.isEmpty()){
            sendBothMarketTP(instrument, engine, tick);
        }
        else{
            //get chan population
            Map<Boolean, Double> chanPopulation = new HashMap<Boolean, Double>();
            for(IOrder order: openOrders){
                Double price = order.getOpenPrice();
                Boolean position = order.isLong();

                if(position){
                    if(Math.abs(price - ask) < this.parChanWidth){
                        chanPopulation.put(position, price);
                    }
                }
                else{
                    if(Math.abs(price - bid) < this.parChanWidth){
                        //two with same position shouldn't be in a chan
                        chanPopulation.put(position, price);
                    }
                }

            }
            //check if anything at all in chan
            if(chanPopulation.isEmpty()){
                sendBothMarketTP(instrument, engine, tick);
            }
            //saturate chan if needed
            else if(chanPopulation.size() == 1){
                Boolean position = chanPopulation.keySet().iterator().next();
                if(position){
                    console.getOut().print(" @" + tick.getBid() + " TP: " + Double.toString(tick.getBid() - this.parTakeProfit));
                    engine.submitOrder(myUtils.getLabel(instrument), instrument, IEngine.OrderCommand.SELL, this.orderAmount, 0, 10, 0, _tick.getBid() - this.parTakeProfit);
                }
                else{
                    console.getOut().print(" @" + tick.getAsk() + " TP: " + Double.toString(tick.getAsk() + this.parTakeProfit));
                    engine.submitOrder(myUtils.getLabel(instrument), instrument, IEngine.OrderCommand.BUY, this.orderAmount, 0, 10, 0, _tick.getAsk() + this.parTakeProfit);
                }

            }
        }

    }


public void sendBothMarketTP(Instrument _instrument, IEngine _engine, ITick _tick) throws JFException{
        _engine.submitOrder(myUtils.getLabel(_instrument), _instrument, IEngine.OrderCommand.BUY, this.orderAmount, 0, 10, 0, _tick.getAsk() + this.parTakeProfit);
        _engine.submitOrder(myUtils.getLabel(_instrument), _instrument, IEngine.OrderCommand.SELL, this.orderAmount, 0, 10, 0, _tick.getBid() - this.parTakeProfit);
    }


 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Tue 16 Jul, 2013, 12:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide a complete example strategy which replicates the case. If you launch the strategy from the JForex-SDK, please provide the program which launches the strategy.


 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Tue 16 Jul, 2013, 15:41 

User rating: 0
Joined: Tue 09 Apr, 2013, 14:14
Posts: 8
Location: SloveniaSlovenia
I modified the my_play that comes with the demo code and attached it.

@1.30647 TP: 1.30657onMessage: ORDER_SUBMIT_OK - Order submitted order: OPENED BUY 0.001 @ 0.0 OID: 4
onMessage: ORDER_FILL_OK - Order filled order: FILLED BUY 0.001 @ 1.30647 OID: 4
onMessage: ORDER_CLOSE_OK - Order closed order: CLOSED BUY 0.001 @ 1.30647 OID: 4


Attachments:
File comment: modified ma_play
MA_Play.java [3.88 KiB]
Downloaded 378 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.
 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Wed 17 Jul, 2013, 08:56 

User rating: 0
Joined: Tue 09 Apr, 2013, 14:14
Posts: 8
Location: SloveniaSlovenia
From the wiki and docs this is the preferred way of setting take profit for orders or am I missing something?


 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Wed 17 Jul, 2013, 16:05 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We could not replicate those results:
Image
As you see the TP works as expected. So we repeat for the third time - please provide historical tester settings that you achieve such results with.


Attachments:
orders_1pip_tp.png [37.7 KiB]
Downloaded 572 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.
 
 Post subject: Re: HistoricalTester: orders with take profit fill and close on same price Post rating: 0   New post Posted: Thu 18 Jul, 2013, 14:13 

User rating: 0
Joined: Tue 09 Apr, 2013, 14:14
Posts: 8
Location: SloveniaSlovenia
You're right. In the report the orders are as expected. The message was confusing - it says the order is closed@open_price. Using .getClosedPrice gives the right answer. Tnx.
onMessage: ORDER_FILL_OK - Order filled order: FILLED BUY 0.001 @ 1.31145 closed price:0.0 OID: 2081
onMessage: ORDER_CLOSE_OK - Order closed order: CLOSED BUY 0.001 @ 1.31145 closed price:1.31157 OID: 2081


 

Jump to:  

  © 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