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 access the first trade taken
 Post subject: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 07:23 

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

I want to access the very first trade opened when the strategy is started. This is because I want to open the following trades with respect to its opening price. Plz tell me how to access the first trade opened.

Regards,

Jimmy.


 
 Post subject: Re: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 08:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You simply need to fetch the trade reference IOrder object when you call IEngine.submitOrder, see:
https://www.dukascopy.com/wiki/#Set_Market_Order


 
 Post subject: Re: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 09:02 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
Ok, suppose the strategy creates the first order in the following way :

IOrder order = engine.submitOrder("MyMaketBuyOrder", Instrument.EURUSD, OrderCommand.BUY, 0.1);

How will I be able to fetch the opening price of this trade in a way that I can use it to open the next few trades if they cross this value.
Could you plz explain?


 
 Post subject: Re: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 09:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
JimmyHowl8 wrote:
How will I be able to fetch the opening price of this trade in a way that I can use it to open the next few trades if they cross this value.
Could you plz explain?
You have to make the IOrder object a field (i.e. global variable), i.e., define it before onStart, the same way as it is done in the wiki example MarketOrder.java which can be found in the previously referenced article.


 
 Post subject: Re: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 09:47 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
I already saw that example MarketOrder.java. In that the order is accessed using the IMessage method in the following manner :

public void onMessage(IMessage message) throws JFException {
if(message.getOrder() == order)
{//print only our-order messages
console.getOut().println(message);
}
}

But in my strategy, I am already accessing the last order closed using this method in the following manner :

public void onMessage(IMessage message) throws JFException {
if (message.getType() == IMessage.Type.ORDER_CLOSE_OK)
{
lastorderclosed = message.getOrder();
}
}

So could you plz tell me how to access the first trade opening price without mixing it up with the last order closed?


 
 Post subject: Re: How to access the first trade taken Post rating: 0   New post Posted: Fri 07 Dec, 2012, 10:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
JimmyHowl8 wrote:
So could you plz tell me how to access the first trade opening price without mixing it up with the last order closed?
Assign your first order to a different IOrder object than the other orders.
Also please use Code tags when posting code snippets, to make it more readable.


 

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