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.

use orderInMarket command for specific instrument
 Post subject: use orderInMarket command for specific instrument Post rating: 0   New post Posted: Fri 16 Dec, 2011, 09:48 

User rating: 0
Joined: Mon 14 Nov, 2011, 05:16
Posts: 33
Location: PhilippinesPhilippines
Dear Support,

I am developing a strategy, which act on two currency pairs, using the construct

public void onBar(Instrument instrument, Period period, IBar askbar, IBar bidbar) throws JFException {
if( (instrument == Instrument.USDCHF)) {
...logic...
if( (instrument == Instrument.EURUSD)) {
...logic...

I want to be able to change the initial stop loss and take profit levels for EURUSD after a certain time period, however when I use the below code, the SL and TP is amended for both EURUSD and USDCHF. Can you help me make this specific to EURUSD only?


for (instrument == Instrument.EURUSD && IOrder orderInMarket : engine.getOrders()) {
Calendar tradeDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
tradeDate.setTimeInMillis ( orderInMarket.getFillTime() );
MaxDurationMills = (MaxDuration*60*60*1000);
MaxDurationMillsFri = (MaxDurationFri*60*60*1000);
int tradeDay = tradeDate.get ( Calendar.DAY_OF_WEEK );

if ( tradeDay == Calendar.FRIDAY ) {

if (((instrument == Instrument.EURUSD && orderInMarket.getState() == IOrder.State.FILLED)
&& (bidbar.getTime() >= (orderInMarket.getFillTime() + MaxDurationMillsFri) ) ) {
if (orderInMarket.isLongEURUSD()) {
orderInMarket.setStopLossPrice(askPrice - instrument2.getPipValue() * SL2);
orderInMarket.setTakeProfitPrice(askPrice + instrument2.getPipValue() * TP2);}
else if (!orderInMarket.isLongEURUSD()) {
orderInMarket.setStopLossPrice (bidPrice + instrument2.getPipValue() * SL2);
orderInMarket.setTakeProfitPrice(bidPrice - instrument2.getPipValue() * TP2);
}

}
}
else if ( tradeDay != Calendar.FRIDAY ) {
if ((orderInMarket.getState() == IOrder.State.FILLED)
&& (bidbar.getTime() >= (orderInMarket.getFillTime() + MaxDurationMills) ) ) {
if (orderInMarket.isLong()) {
orderInMarket.setStopLossPrice(askPrice - instrument2.getPipValue() * SL2);
orderInMarket.setTakeProfitPrice(askPrice + instrument2.getPipValue() * TP2);}
else if (!orderInMarket.isLong()) {
orderInMarket.setStopLossPrice (bidPrice + instrument2.getPipValue() * SL2);
orderInMarket.setTakeProfitPrice(bidPrice - instrument2.getPipValue() * TP2);
}

}


}


 
 Post subject: Re: use orderInMarket command for specific instrument Post rating: 0   New post Posted: Fri 16 Dec, 2011, 13:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You could add the following condition to the IF statements:
orderInMarket.getInstrument().equals(Instrument.EURUSD)


 

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