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.

Time out code has stopped working
 Post subject: Time out code has stopped working Post rating: 0   New post Posted: Thu 26 Jan, 2012, 15:42 

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

I have been using the below code snippet in both historical testing and on live account trading to close out trades (set a tighter stop loss and take profit) after a pre-determined duration. In the last one or two weeks, this mechanism has stopped working (again both in testing and live). What can have caused this? Has a version updated changed any of the functions called? I have not amended the snippet and there should therefore be no problems on my side.

// CLOSING POSITION AFTER PRE-DETERMINED DURATION
if(period == period.THIRTY_SECS ){
for (IOrder orderInMarket : engine.getOrders()) {
Calendar tradeDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
tradeDate.setTimeInMillis ( orderInMarket.getFillTime() );
MaxDurationMills = (MaxDuration*60*60*1000);

if ((orderInMarket.getState() == IOrder.State.FILLED)
&& (bidbar.getTime() >= (orderInMarket.getFillTime() + MaxDurationMills) ) ) {
if (orderInMarket.isLong()) {
orderInMarket.setStopLossPrice(askPrice - instrument.getPipValue() * 20);
orderInMarket.setTakeProfitPrice(askPrice + instrument.getPipValue() * 20);}
else if (!orderInMarket.isLong()) {
orderInMarket.setStopLossPrice (bidPrice + instrument.getPipValue() * 20);
orderInMarket.setTakeProfitPrice(bidPrice - instrument.getPipValue() * 20);
}

}

}
}


 
 Post subject: Re: Time out code has stopped working Post rating: 0   New post Posted: Fri 27 Jan, 2012, 13:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide an example strategy in which this snippet works (it uses a lot of variables that are not in the snippet). Please also provide the launch scenario (strategy configuration parameters, Historical tester settings, etc.).


 
 Post subject: Re: Time out code has stopped working Post rating: 0   New post Posted: Mon 30 Jan, 2012, 14:55 

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

I have identified the error, which was in my code (a parameter was coded as 'private' where it should be 'public'). For information to other traders, here is attached my code to time-out trades after a predetermined period + to calculate position size based on value-at-risk as a percentage of equity.


Attachments:
Example.java [6.8 KiB]
Downloaded 264 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.
 

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