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.

14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second
 Post subject: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Tue 10 Apr, 2012, 15:45 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

After add trailing to strategy, I start get offen follow error:

14:33:29 Order REJECTED: STOP LOSS BUY EUR/USD @MKT IF ASK => 0.75027 - Position #12429395, REASON: can't change stop loss price more than once in a second

sample code here:

// Trailing stop
if(_trailing!=0) {
for (IOrder order : engine.getOrders(selectedInstrument)) {

if(order.getOrderCommand()==IEngine.OrderCommand.BUY) {
if(tick.getBid()-order.getOpenPrice()>=_trailing*selectedInstrument.getPipValue()) {
if((tick.getBid()-_trailing*selectedInstrument.getPipValue())>order.getStopLossPrice()) order.setStopLossPrice((tick.getBid()-_trailing*selectedInstrument.getPipValue()));
order.waitForUpdate(200);
}
}

if(order.getOrderCommand()==IEngine.OrderCommand.SELL) {

if(order.getOpenPrice()-tick.getAsk()>=_trailing*selectedInstrument.getPipValue()) {
if((tick.getAsk()+_trailing*selectedInstrument.getPipValue())<order.getStopLossPrice()) order.setStopLossPrice((tick.getAsk()+_trailing*selectedInstrument.getPipValue()));
order.waitForUpdate(200);
if(order.getStopLossPrice()==0) order.setStopLossPrice((tick.getAsk()+_trailing*selectedInstrument.getPipValue()));
order.waitForUpdate(200);
}
}

}

On tester mode no this error.

Please, assist may be need make longer interval for order.waitForUpdate(200); ??

Thank advanced.

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 11 Apr, 2012, 09:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
vs_trade wrote:
Please, assist may be need make longer interval for order.waitForUpdate(200);
IOrder.waitForUpdate is not the same as Thread.sleep, please read javadocs. Please consider either changing your strategy logic such that it does not update the SL that often or keep the last SL change time as a field in your strategy and before the subsequent SL change attempt check if you have not already changed the SL within the last second.


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 11 Apr, 2012, 15:09 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

After fill order it set a wrong StopLoss and immediately are order close:


12:12:18 Order FILLED at 1.31286 USD (#53186548 STOP LOSS SELL 0.014761 mil. EUR/USD @ MKT IF BID <= 5.7891) - Position #12473588
12:12:17 Position 12473588 STOP LOSS #53186548 price stop changed from 1.26343 USD to 5.7891 USD
12:12:17 Order FILLED at 1.31293 USD (#53186547 ENTRY BUY 0.014761 mil. EUR/USD @ LIMIT 1.31294 IF ASK <= 1.31294) - Position #12473588
12:10:00 Order ACCEPTED: #53186549 TAKE PROFIT SELL 0.014761 mil. EUR/USD @ LIMIT 1.32113 IF BID => 1.32113 - Position #12473588
12:10:00 Order ACCEPTED: #53186548 STOP LOSS SELL 0.014761 mil. EUR/USD @ MKT IF BID <= 1.26343 - Position #12473588
12:10:00 Order ACCEPTED: #53186547 ENTRY BUY 0.014761 mil. EUR/USD @ LIMIT 1.31294 IF ASK <= 1.31294 - Position #12473588


code here:

...
// Trailing stop
if(_trailing!=0) {
for (IOrder order : engine.getOrders(selectedInstrument)) {

if(order.getOrderCommand()==IEngine.OrderCommand.BUY) {
if(tick.getBid()-order.getOpenPrice()>= getPipPrice(this._trailing)) {
if(round(tick.getBid()-getPipPrice(this._trailing),5)>order.getStopLossPrice()) order.setStopLossPrice(round(tick.getBid()-getPipPrice(this._trailing),5));
console.getOut().println("StopLossPrice_trailing : " + order.getLabel() + " " + order.getOrderCommand() + "Set time" + sdf.format(tick.getTime()) + " Price: " + order.getStopLossPrice());
order.waitForUpdate(2000);

}
}

if(order.getOrderCommand()==IEngine.OrderCommand.SELL) {

if(order.getOpenPrice()-tick.getAsk()>= getPipPrice(this._trailing)) {
if(round(tick.getAsk()+getPipPrice(this._trailing),5)<order.getStopLossPrice()) order.setStopLossPrice(round(tick.getAsk()+getPipPrice(this._trailing),5));
order.waitForUpdate(2000);
if(order.getStopLossPrice()==0) order.setStopLossPrice(round(tick.getAsk()+getPipPrice(this._trailing),5));
console.getOut().println("StopLossPrice_trailing : " + order.getLabel() + " " + order.getOrderCommand() + "Set time" + sdf.format(tick.getTime()) + " Price: " + order.getStopLossPrice());
order.waitForUpdate(2000);

}
}

}
}
...

public double round(double d, int decimalPlace){
// see the Javadoc about why we use a String in the constructor
// https://java.sun.com/j2se/1.5.0/docs/api ... mal(double)
BigDecimal bd = new BigDecimal(Double.toString(d));
bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
int lastdigit=0;

char digits[]=bd.toString().toCharArray();
lastdigit=digits[digits.length-1]-48;
// _console.getOut().println("LD: "+lastdigit);

if(lastdigit!=0 || lastdigit!=5) {
if(lastdigit>5) {
digits[digits.length-1]=53;
}
if(lastdigit<5) {
digits[digits.length-1]=48;
}

}

BigDecimal bd1 = new BigDecimal(digits);
bd1 = bd1.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);

//_console.getOut().println("D: "+bd1.toString()+" L: "+digits.length);

return bd1.doubleValue();

}
...

private double getPipPrice(int pips) {
return pips * this.selectedInstrument.getPipValue();
}

...


From where happen it mistake with price??


Thanks a lot.

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 11 Apr, 2012, 15:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
vs_trade wrote:
After fill order it set a wrong StopLoss and immediately are order close:
Consider logging IOrder.getOpenPrice, order direction (i.e. IOrder.isLong) and the calculated SL price right before you call IOrder.setStopLossPrice(). The most likely you are setting the SL in the wrong direction, therefore the order is subject to immediate close on SL.

Also please use Code tag for your code snippets, to make the source code more readable.


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 11 Apr, 2012, 15:41 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,


API Support wrote:
vs_trade wrote:
After fill order it set a wrong StopLoss and immediately are order close:
Consider logging IOrder.getOpenPrice, order direction (i.e. IOrder.isLong) and the calculated SL price right before you call IOrder.setStopLossPrice(). The most likely you are setting the SL in the wrong direction, therefore the order is subject to immediate close on SL.


I agree if it wrong direction, it no difficult to change. But here I get wrong price for SL.

2012-04-11 12:12:18 Order FILLED at 1.31286 USD (#53186548 STOP LOSS SELL 0.014761 mil. EUR/USD @ MKT IF BID <= 5.7891) - Position #12473588
2012-04-11 12:12:17 Position 12473588 STOP LOSS #53186548 price stop changed from 1.26343 USD to 5.7891 USD
2012-04-11 12:12:17 Order FILLED at 1.31293 USD (#53186547 ENTRY BUY 0.014761 mil. EUR/USD @ LIMIT 1.31294 IF ASK <= 1.31294) - Position #12473588

...
// Trailing stop
if(_trailing!=0) {
for (IOrder order : engine.getOrders(selectedInstrument)) {

if(order.getOrderCommand()==IEngine.OrderCommand.BUY) {
if(tick.getBid()-order.getOpenPrice()>= getPipPrice(this._trailing)) {
if(round(tick.getBid()-getPipPrice(this._trailing),5)>order.getStopLossPrice()) order.setStopLossPrice(round(tick.getBid()-getPipPrice(this._trailing),5));
console.getOut().println("StopLossPrice_trailing : " + order.getLabel() + " " + order.getOrderCommand() + "Set time" + sdf.format(tick.getTime()) + " Price: " + order.getStopLossPrice());
order.waitForUpdate(2000);

}
}

if(order.getOrderCommand()==IEngine.OrderCommand.SELL) {

if(order.getOpenPrice()-tick.getAsk()>= getPipPrice(this._trailing)) {
if(round(tick.getAsk()+getPipPrice(this._trailing),5)<order.getStopLossPrice()) order.setStopLossPrice(round(tick.getAsk()+getPipPrice(this._trailing),5));
order.waitForUpdate(2000);
if(order.getStopLossPrice()==0) order.setStopLossPrice(round(tick.getAsk()+getPipPrice(this._trailing),5));
console.getOut().println("StopLossPrice_trailing : " + order.getLabel() + " " + order.getOrderCommand() + "Set time" + sdf.format(tick.getTime()) + " Price: " + order.getStopLossPrice());
order.waitForUpdate(2000);

}
}

}
}
...

public double round(double d, int decimalPlace){

BigDecimal bd = new BigDecimal(Double.toString(d));
bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
int lastdigit=0;

char digits[]=bd.toString().toCharArray();
lastdigit=digits[digits.length-1]-48;

if(lastdigit!=0 || lastdigit!=5) {
if(lastdigit>5) {
digits[digits.length-1]=53;
}
if(lastdigit<5) {
digits[digits.length-1]=48;
}

}

BigDecimal bd1 = new BigDecimal(digits);
bd1 = bd1.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);

return bd1.doubleValue();

}
...

private double getPipPrice(int pips) {
return pips * this.selectedInstrument.getPipValue();
}

...



Here are some mistake with price, but where :roll: ??
I checked few times, but can't find. In history tester it's work without those problems.

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 11 Apr, 2012, 15:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please replace your IOrder.setStopLossPrice with calls of the following method:
   private void setStopLoss(IOrder o, double newSlPrice) throws JFException{
      print("%s isLong=%s, openPrice=%.5f,  current SL price=%.5f, new SL price=%.5f",
            o.getLabel(),o.isLong(), o.getOpenPrice(), o.getStopLossPrice(), newSlPrice);
      o.setStopLossPrice(newSlPrice);
   }
   
   private void print(String message, Object... args){
      console.getOut().println(String.format(message,args));
   }
And then check the values that you get in the Strategy tab.


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Thu 12 Apr, 2012, 13:47 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

Thanks for the advice. But I find problem in another place. My orders opening by SELLLIMIT or BUYLIMIT, in trailing method the orders checking by SELL or BUY Order.Command:

...
// Trailing stop
if(_trailing!=0) {
for (IOrder order : engine.getOrders(selectedInstrument)) {
 
if(order.getOrderCommand()==IEngine.OrderCommand.BUY) {

// or

if(order.getOrderCommand()==IEngine.OrderCommand.SELL) {


but when I change IEngine.OrderCommand.BUY => IEngine.OrderCommand.BUYLIMIT (or IEngine.OrderCommand.SELL => IEngine.OrderCommand.SELLLIMIT), I get bad results in tester.

And I solved problem by follow way:

...
if(order.getOrderCommand()==IEngine.OrderCommand.BUY) {
// replace to
if (orderInMarket.isLong() && instrument.equals(selectedInstrument)) {
...
if(order.getOrderCommand()==IEngine.OrderCommand.SELL) {
// replace to
if (!orderInMarket.isLong() && instrument.equals(selectedInstrument)) {


After this replacement error away.

It still only some others errors:

1. Thread queue

10:15:15 Strategy thread queue overloaded with tasks. Ticks in queue - 37, bars - 1354, other tasks - 375

It's comes I think from trailing method, so as it's based on Tick method and it has here order.waitForUpdate();
order.waitForUpdate(2000);


2. Order REJECTED:

11:40:42 Order REJECTED: STOP LOSS SELL EUR/USD @MKT IF BID <= 1.316 - Position #12511296, REASON: can't change stop loss price more than once in a second

It's comes from logic of trailing here. After when reaches trailing level, if order going by trend then trailing distance fix and checking and change by tick.

Can you help with this? Or it no so critical for working strategy?

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Thu 12 Apr, 2012, 15:43 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We reiterate that you should not use IOrder.waitForUpdate as a way to make a timeout. You should use it only when order change is imminent, see:
https://www.dukascopy.com/wiki/#Manage_Order_State

Also we repeat that before changing the stop loss level, please check for the last time the stop loss was changed, hence consider having stop loss changing function to be something like this:
    long lastSlChangeTime = 0;
    private void setStopLoss(IOrder o, double newSlPrice) throws JFException{
       long lastTickTime = history.getLastTick(o.getInstrument()).getTime();
        if(lastTickTime - 1000 > lastSlChangeTime){
           print("Cannot change SL yet, only %s millis passed since the last change", lastTickTime - lastSlChangeTime);
        } else {
           print("%s isLong=%s, openPrice=%.5f,  current SL price=%.5f, new SL price=%.5f",
                 o.getLabel(),o.isLong(), o.getOpenPrice(), o.getStopLossPrice(), newSlPrice);
           o.setStopLossPrice(newSlPrice);
           lastSlChangeTime = lastTickTime;
        }
     }


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Wed 18 Apr, 2012, 14:27 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

Can be error "Thread queue", if jforex no get tick data from sever. And how I can check it if problem there?

10:15:15 Strategy thread queue overloaded with tasks. Ticks in queue - 37, bars - 1354, other tasks - 375

My "computer" locate on virtual server on cloud and for start jforex it takes more longer time then from local machine.
Firewalls switch off.

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Thu 19 Apr, 2012, 07:45 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

One question more.

In my strategy, if condition are valid, at first on start one bar close order inMarket and on start next bar open new order. Sometimes it can be big differences between those two bars.
How I can make that open new order be immediately after close previous order?

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Sun 22 Apr, 2012, 11:53 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
vs_trade wrote:
Can be error "Thread queue", if jforex no get tick data from sever. And how I can check it if problem there?

10:15:15 Strategy thread queue overloaded with tasks. Ticks in queue - 37, bars - 1354, other tasks - 375
Apparently this is because of improper use of waitForUpdate, which blocks the strategy execution making the feed not to get processed on time. We already pointed this out in our previous post.
vs_trade wrote:
In my strategy, if condition are valid, at first on start one bar close order inMarket and on start next bar open new order. Sometimes it can be big differences between those two bars.
How I can make that open new order be immediately after close previous order?
Presumably this could be a consequence of the first issue.


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Tue 24 Apr, 2012, 12:57 
User avatar

User rating: 0
Joined: Thu 25 Aug, 2011, 14:04
Posts: 45
Location: Russian Federation,
Hello Support Team,

My "computer" locate on virtual server on cloud and for start jforex it takes more longer time then from local machine.
Provider cloud server said that it problem from provider application and readdress to you.

Firewalls switch off.

Best regards,
vs_trade


 
 Post subject: Re: 14:33:29 Order REJECTED ... REASON: can't change stop stop loss price more than once in a second Post rating: 0   New post Posted: Tue 24 Apr, 2012, 19:59 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please fix your strategy logic by following the instructions given in our previous posts. If you don't succeed, then please:
  1. provide a full example strategy,
  2. provide a precise test case,
  3. describe the behavior that you find being wrong,
  4. describe the desired behavior.


 

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