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.

How to fetch the opening price of the last trade
 Post subject: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sat 20 Oct, 2012, 14:02 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
To Dukascopy Support,

Kindly tell me how to fetch the opening price of the last trade taken when there is no trade open (when order == null). Thanks.

Jimmy. :)


 
 Post subject: Re: How to fetch the opening price of the past trade Post rating: 0   New post Posted: Sat 20 Oct, 2012, 19:03 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
You may refer to this post in the forum which uses the
IHistory object which is fetched using IContext.getHistory()
Using that object you could possibly iterate/search for the latest dated closed order.
If you're able to find the historical IOrder you want, then use getOpenPrice()
I have not actually done this myself, so not absolutely sure of the details.

How can I get my historical closed positions?
viewtopic.php?f=65&t=45371&p=59575&hilit=closed#p59575


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sun 21 Oct, 2012, 18:05 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
I am sorry but I did not completely follow the method that you suggested. Also, I believe that the topic you suggested has the code snippet to fetch the historical order between a certain specified time frame. In my case, there is no specified time frame. I just want to fetch the opening price of only the last trade taken. Thanks anyway.


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sun 21 Oct, 2012, 21:05 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Surely you know whether it was within the past 24 hours (or whatever, not sure how far back it goes), and the final date could certainly be NOW. So please explain why doesn't that answer your question?

JimmyHowl8 wrote:
I am sorry but I did not completely follow the method that you suggested. Also, I believe that the topic you suggested has the code snippet to fetch the historical order between a certain specified time frame. In my case, there is no specified time frame. I just want to fetch the opening price of only the last trade taken. Thanks anyway.


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sun 21 Oct, 2012, 22:42 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi JimmyHowl8:

The way hiperscalper says is one way if you know the instrument where the last order was ended or get the last order on all intruments and compare the time of close to get the last one closed (this is independent from the timeframe where the order was submited).

If you want to have a class order object with the last closed order (and get any value you want from it) i may advise you to use onMessage() method storing the last closed order in this variable object with the event "ORDER_CLOSE_OK". Of course this approach only works if the last order was closed with the strategy running and if the instrument of the closed order was subscribed.

I hope that helps

Best regards

JL


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Mon 22 Oct, 2012, 03:27 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
Could you also plz provide a code snippet or a wiki example? Thanks.


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Mon 22 Oct, 2012, 07:33 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Read the first paragraph of this wiki article:
https://www.dukascopy.com/wiki/#Order_state
There you will also find the link for order history retrieval, for active order retrieval see:
https://www.dukascopy.com/wiki/#Order_Management


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Mon 22 Oct, 2012, 09:25 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
I understood the logic behind it all but could you also provide a code snippet?


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Mon 22 Oct, 2012, 09:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The links that we provided and/or referred to are already supplied with the examples, if you need to find a historical order, see:
https://www.dukascopy.com/wiki/#Order_history


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Mon 22 Oct, 2012, 09:38 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi JimmyHowl8:

In the example i suggest in the onMessage() method please see this snipet code :

public void onMessage(IMessage message) throws JFException {
        // get the order at order close
        if(message.getType() == IMessage.Type.ORDER_CLOSE_OK){
            //you need to have declared this variable as class variable usually at start of the strategy class
            lastOrderClose = message.getOrder();
            //later you can use this variable to get order data for example lastOrderClosed.getOpenPrice()
        }
}


Hope that helps

Best regards

JL


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Thu 15 Nov, 2012, 09:07 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
To Jlongo / Jforex Support,

I have tried to modify the strategy as suggested by you but there is still an error. Kindly help me get rid of it. The conditions are as follows:

- When conditions for a buy trade meet, the strategy should check whether the preceding trade was a buy trade. If it was, the current buy trade should be taken only if it crosses the preceding buy trade's opening price. And if the preceding trade was a sell trade, the current buy trade should be taken normally as soon as the conditions are met.

- Similarly, for the sell trade, when conditions for a sell trade meet, the strategy should check whether the preceding trade was a sell trade. If it was, the current sell trade should be taken only if it crosses the preceding sell trade's opening price. And if the preceding trade was a buy trade, the current sell trade should be taken normally as soon as the conditions are met.

Regards,

Jimmy.


Attachments:
SMASimpleStrategymodify3.java [5.55 KiB]
Downloaded 315 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: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Thu 15 Nov, 2012, 12:10 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi JimmyHowl8:

I have done a fast read at your strategy... you don't check the direction of lastorderclosed. You can do that with lastorderclosed.getOrderCommand() and use it on your conditions.

Hope that helps.

Best regards

JL


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Fri 16 Nov, 2012, 12:09 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
To Jlongo,

Here is the modified strategy which checks the direction of the last order closed. But the afore-mentioned error still persists. Please help.

Regards,

Jimmy.


Attachments:
SMASimpleStrategymodify3.java [5.71 KiB]
Downloaded 302 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: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Fri 16 Nov, 2012, 13:28 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi JimmyHowl8:

You need to say what error happens...

Best regards

JL


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sat 17 Nov, 2012, 11:03 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
To Jlongo,

M sorry. Here is the error :

0022-05-05 22:00:01 lastorderclosed cannot be resolved
0022-05-05 22:00:01 if (lastorderclosed.getOrderCommand() == OrderCommand.SELL && tick1.getBid() < lastorderclosed.getOpenPrice() && prevBar.getOpen() > sma && prevBar.getClose() < sma && order == null){

0022-05-05 22:00:01 4. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\SMASimpleStrategymodify3.java (at line 97)

0022-05-05 22:00:01 lastorderclosed cannot be resolved
0022-05-05 22:00:01 if (lastorderclosed.getOrderCommand() == OrderCommand.SELL && tick1.getBid() < lastorderclosed.getOpenPrice() && prevBar.getOpen() > sma && prevBar.getClose() < sma && order == null){

0022-05-05 22:00:01 3. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\SMASimpleStrategymodify3.java (at line 97)

0022-05-05 22:00:01 lastorderclosed cannot be resolved
0022-05-05 22:00:01 if (lastorderclosed.getOrderCommand() == OrderCommand.BUY && tick1.getBid() > lastorderclosed.getOpenPrice() && prevBar.getOpen() < sma && prevBar.getClose() > sma && order == null){

0022-05-05 22:00:01 2. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\SMASimpleStrategymodify3.java (at line 93)

0022-05-05 22:00:01 lastorderclosed cannot be resolved
0022-05-05 22:00:01 if (lastorderclosed.getOrderCommand() == OrderCommand.BUY && tick1.getBid() > lastorderclosed.getOpenPrice() && prevBar.getOpen() < sma && prevBar.getClose() > sma && order == null){

0022-05-05 22:00:01 1. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\SMASimpleStrategymodify3.java (at line 93)

Regards,

Jimmy.


 
 Post subject: Re: How to fetch the opening price of the last trade Post rating: 0   New post Posted: Sat 17 Nov, 2012, 12:10 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi JimmyHowl8:

I not have see your code, but by the error, seems that the variable lastorderclosed don't is initiated or is null.

In first place you need to make the variable lastorderclosed available to all class, for that you declare it after the configurable parameters "Iorder lastorderclosed = null"

Also you must remember, at strategy start you don't have any closed order, you need to implement a check if the lastorderclosed is null and make the conditions without the check to this variable. If we have a lastorderclosed the conditions can use the variable.

I hope that helps

Best regards

JL


 

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