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.

problem with order.getLabel
 Post subject: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 01:41 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
hello support,

i have a problem with the order label. i mean i do a mistake but where....

for (IOrder order : engine.getOrders(instrument)) {
         if (order.getLabel().equals("take1")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult;
         }
         if (order.getLabel().equals("take2")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult * 2;
         }
         if (order.getLabel().equals("take3")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult * 3;
         }
         }
print("label:" + order.getLabel());


first it doesn't place any takeprofit when the order is created and when i print the label it doesn't return "take1" but EURUSD0. i think something is missing in this part of code :

  private String getLabel(Instrument instr) {
        String label = instr.name();
        label = label + (counter++);
        label = label.toUpperCase();
        return label;
    }


but i don't known what.

could you help me please?

eric


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 04:05 

User rating: 3
Joined: Thu 17 Nov, 2011, 04:06
Posts: 39
Location: Canada, Ottawa
The issue with the code is that you are setting your labels to equal the instrument name plus a number and then you are checking to see if they are equal to string (eg "take 1"). Because no order will have that label (as you did not set it in the first place) your logic will always return false.


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 09:25 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
thank for your reply,

well i understand what you say, it's logic.
but if i refer to this wiki : https://www.dukascopy.com/wiki/#Order_Management and if i understand correctly (the english isn't my native language), it's possible to create an order with my proper label.
if i replace the label "take1" by "EURUSD0"(this is the label of the first order created when i run the strategy), the strategy doesn't place any takeprofit. when the strategy created an another order, the label is incremented of +1(EURUSD0,EURSUSD1,EURUSD2,....), that it's logic.
so, how create an order with a static label?

eric


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 11:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ericbiz wrote:
so, how create an order with a static label?
The label is always the one that you set it and it does not change. Whether you include instrument name, some counter, strategy name, a java.util.UUID, etc. it's up to you.
For more efficient assistance please describe:
  • what do you expect the strategy to do,
  • what it does the instead.
Also please provide the example strategy and describe the launch scenario.


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 11:50 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
for example :

//signal definition
if (currBar.getClose() > prevBar.getHigh())
  {           
    buySign = true;
    buyPrice = currBar.getClose();
   }
// PLACE ORDER
        if (buySign) {
            orderMgr.closeAllShortOdrers();
            if(orderMgr.canAddOrder(OrderCommand.BUY)){
               
   double stopLossPrice = 0.0;
   stopLossPrice = currBar.getLow();
         
            orderMgr.submitOrder("take1",OrderCommand.BUY, buyPrice, stopLossPrice);
            orderMgr.submitOrder("take2",OrderCommand.BUY, buyPrice, stopLossPrice);
            orderMgr.submitOrder("take3",OrderCommand.BUY, buyPrice, stopLossPrice);
            }

private IOrder submitOrder(String string, OrderCommand orderCmd, double price, double stopLossPrice) throws JFException {
            if(!canAddOrder(orderCmd)) {
                return null;
            }
         
            double takeProfitPrice = 0.0;
            double stopLossDiff = price - stopLossPrice;
       double stopLossPips = Math.abs(stopLossDiff) / instrument.getPipValue();
      
   for (IOrder order : engine.getOrders(instrument)) {
              if (order.getLabel().equals("take1")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult;
         }
         if (order.getLabel().equals("take2")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult * 2;
         }
         if (order.getLabel().equals("take3")){
         takeProfitPrice = price + stopLossDiff * takeProfitMult * 3;
         }
      }
           

            double amount = XRate.getAmount(context, account, instrument, risk, stopLossPips);
            IOrder order = engine.submitOrder(getLabel(instrument), instrument, orderCmd, amount, 0, slippage, stopLossPrice, takeProfitPrice);
         
            addOrder(order);
            return order;
        }

i will create 3 orders in a same time when the signal occur. the 3 signal have the same SL but not the same TP(breakeven,trailing stop too). if i want to manage the order i need to name it in order to manage it correctly.


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Mon 03 Dec, 2012, 12:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You are trying to retrieve the order from active order list (see IEngine.getOrders), before even submitting the order. Thus it's rather straightforward, that it won't work that way. If you want to use String operations for order logic, then you would need to do something like this:
  • rename the string input parameter of the submitOrder method to something more meaningful like label.
  • remove the for cycle, since the orders are not there yet.
  • modify the comparison expression to
    label.getLabel().equals("take2")
Also if you want to retrieve an order by its label, simply use IEngine.getOrder, instead of iteratating over order list.


 
 Post subject: Re: problem with order.getLabel Post rating: 0   New post Posted: Wed 05 Dec, 2012, 09:52 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
hello support,

thank for your reply, code base completely successfull.

eric


 

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