|
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.
| modify pending ticket's openPrice |
|
jacques3901
|
| Post subject: modify pending ticket's openPrice |
Post rating: 0
|
Posted: Fri 11 Oct, 2013, 05:46
|
|
User rating: 0
Joined: Sat 28 Sep, 2013, 05:54 Posts: 13 Location: ChinaChina
|
|
Hi,
I use "order.setOpenPrice(OpenPrice)" to modify a pending ticket's opened price. It works in history strategy tester. But when I try to run in opened market, the pending ticket's opened price cannot be modified without any error information output.Below is my script:
if(order.getState() ==IOrder.State.OPENED){ if(order.getOpenPrice() !=BuyStop){ order.setOpenPrice(BuyStop); } }
Please help check what's wrong in my script.
Thanks!
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: modify pending ticket's openPrice |
Post rating: 0
|
Posted: Fri 11 Oct, 2013, 07:34
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
jacques3901 wrote: the pending ticket's opened price cannot be modified without any error information output Please elaborate what messages you get. Please provide an example strategy which replicates this.
|
|
|
|
|
 |
|
hyperscalper
|
 |
Post subject: Re: modify pending ticket's openPrice |
Post rating: 0
|
Posted: Fri 11 Oct, 2013, 14:38
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
jacques3901 wrote: Hi,
I use "order.setOpenPrice(OpenPrice)" to modify a pending ticket's opened price. It works in history strategy tester. But when I try to run in opened market, the pending ticket's opened price cannot be modified without any error information output.Below is my script:
if(order.getState() ==IOrder.State.OPENED){ if(order.getOpenPrice() !=BuyStop){ order.setOpenPrice(BuyStop); } }
Please help check what's wrong in my script.
Thanks! You should check for an exception on the order.setOpenPrice(...) This could possibly be relevant, but your code may be OK as well. I always use the "equals" method for enumerated values like IOrder.State.OPENED That re-write would be like this: if(order.getState().equals(IOrder.State.OPENED)) { // using .equals if(order.getOpenPrice() !=BuyStop){ try { order.setOpenPrice(BuyStop); } catch(Exception e) { e.printStackTrace(); } } }
Hope this helps !! HyperScalper
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: modify pending ticket's openPrice |
Post rating: 0
|
Posted: Fri 11 Oct, 2013, 16:09
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
hyperscalper wrote: This could possibly be relevant, but your code may be OK as well. I always use the "equals" method for enumerated values like IOrder.State.OPENED That re-write would be like this: Actually using == or Object.equals for enums is effectively the same, have a look at the java.lang.Enum.equals implementation.
|
|
|
|
|
 |
|
jacques3901
|
| Post subject: Re: modify pending ticket's openPrice |
Post rating: 0
|
Posted: Sun 13 Oct, 2013, 04:24
|
|
User rating: 0
Joined: Sat 28 Sep, 2013, 05:54 Posts: 13 Location: ChinaChina
|
hyperscalper wrote: jacques3901 wrote: Hi,
I use "order.setOpenPrice(OpenPrice)" to modify a pending ticket's opened price. It works in history strategy tester. But when I try to run in opened market, the pending ticket's opened price cannot be modified without any error information output.Below is my script:
if(order.getState() ==IOrder.State.OPENED){ if(order.getOpenPrice() !=BuyStop){ order.setOpenPrice(BuyStop); } }
Please help check what's wrong in my script.
Thanks! You should check for an exception on the order.setOpenPrice(...) This could possibly be relevant, but your code may be OK as well. I always use the "equals" method for enumerated values like IOrder.State.OPENED That re-write would be like this: if(order.getState().equals(IOrder.State.OPENED)) { // using .equals if(order.getOpenPrice() !=BuyStop){ try { order.setOpenPrice(BuyStop); } catch(Exception e) { e.printStackTrace(); } } }
Hope this helps !! HyperScalper Thanks for your perfect clues. After check through scrip body, I found there are another condition as below: if(order.getComment()=="STAT1") I changed the script as your suggestion to: if(order.getComment().equals("STAT1")) it works! Thank you very much. Strangely, why my orginally script can work in historical tester?
|
|
|
|
|
 |
|
API Support
|
| Post subject: Re: modify pending ticket's openPrice |
Post rating: 1
|
Posted: Mon 14 Oct, 2013, 08:47
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
jacques3901 wrote: order.getOpenPrice() !=BuyStop This is error-prone, use Double.compare, i.e., Double.compare(order.getOpenPrice(),BuyStop)!=0
|
|
|
|
|
 |
|
hyperscalper
|
| Post subject: Re: modify pending ticket's openPrice |
Post rating: 2
|
Posted: Wed 16 Oct, 2013, 04:31
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
|
Also don't forget that some changes to a given order's properties, and certainly successive order operations MUST be paced to allow a MINIMUM of 1 second between successive operations, on a particular order.
So you may be able to change 100 order's prices all within 1 second, but you can't change a SPECIFIC order's price more often than once PER second...
Otherwise, an exception will be thrown, so anticipate that possibility.
If a Strategy method throws an uncaught exception, your Strategy may be terminated, so always handle exceptions properly within each IStrategy method to prevent this from happening.
HyperScalper
|
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|