|
ORDER MAGIC NUMBER/COMMENT |
ArthurV
|
Post subject: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Thu 18 Apr, 2013, 18:51
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
Hello Support,
Could you tell me please, is there any way to group my orders by magic number, comment or anything similar to this?
Having several manual strategies, each of them requires different settings for trailing stop for instance. I need to separate my orders somehow as it is possible on MT4.
Any suggestion on that?
Thank you.
Arthur
|
|
|
|
 |
hyperscalper
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Thu 18 Apr, 2013, 21:54
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
IOrder has a label property. This internal label property is displayed by the JForex platform as "External ID". Normally your "magic number" is embedded within a string assigned to the label. (All active labels must be a unique string, so some sequence number is used as well.) Any order you create or manage must be checked to contain your "magic number". See my screenshot for an example of live orders using a magic number (in this case 78). Note that this label property is different from the numeric order id. In fact, for the most part, your code does not care much about the numeric order id, just your assigned label. Any label containing your magic number within the string is managed, and any other orders are specifically coded to be ignored by your Strategy instance. Of course, you supply a magic number unique to each strategy instance, usually at startup, etc. The rest is "coding"  HyperScalper 
Attachments: |
HyperScalperOrderLabelling.PNG [211.29 KiB]
Downloaded 941 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.
|
|
|
|
|
 |
hyperscalper
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Thu 18 Apr, 2013, 22:27
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
This is just a code snippet to show how you would filter your order labels. It won't compile because certain functions are undefined. This code shows how to filter individual orders by "magic" label, and then close each one, skipping any unrecognized order labels. (This is only an example, and there may be more efficient ways to do this.) // this code must be invoked using IContext.executeTask(callable) final public class CloseAllOrdersTask implements Callable<Void> { IEngine _engine = null; Instrument _instrument = null; public CloseAllOrdersTask(final IEngine engineArg, final Instrument instrumentArg) { _engine = engineArg; _instrument = instrumentArg; } public Void call() throws Exception { checkThread(this); try { ArrayList<IOrder> orderList = (ArrayList<IOrder>)_engine.getOrders(); Instrument inst = null; IOrder order = null; IOrder.State state; double bidPrice; double askPrice; synchronized(spreadMutex) { bidPrice = instantaneousLastBidPricePrivate; //lastBidPricePrivate; askPrice = instantaneousLastAskPricePrivate; //lastAskPricePrivate; } for (int i=0; i<orderList.size(); i++) { order = orderList.get(i); if (order!=null && isMyOrder(order)) { // recognize MY orders inst = order.getInstrument(); if (inst==null || !inst.equals(_instrument)) { continue; // skip } state = order.getState(); if ( !state.equals(IOrder.State.FILLED)){ continue; // skip } boolean isLong = order.isLong(); double closePrice = isLong?(bidPrice-(PIP*2.0d)):(askPrice+(PIP*2.0d)); // this is a FILLED order, so close it // specify slippage, etc for more reliable close order.close(0, closePrice, SLIPPAGE_PIPS); /* if (WAIT_AFTER_CLOSE) { order.waitForUpdate(1000, TimeUnit.MILLISECONDS); } */ { //else { myYield(100); } } } } catch(Exception e) { e.printStackTrace(); throw e; } return null; } }
Example of forming a prefix string containing instrument, magic number, etc....... The following code returns the unique PREFIX of an order LABEL, which includes our magic number, and which removes an illegal character from the Instrument.toString(). Any order with this PREFIX string is one which the code will manage, otherwise it will be ignored. final public String SOH() { // return our unique prefix, including Instrument if (magicNumber<1 || magicNumber>99) magicNumber=99; // 1..99 String sohInvalid = ("SOH"+magicNumber+selectedInstrument.toString()); // NOTE: toString contains invalid slash character which we remove String soh = sohInvalid.replaceAll("/", ""); // illegal character EUR/USD -> EURUSD // MUST remove the illegal slash character from the string !!! return soh; }
|
|
|
|
 |
ArthurV
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Fri 19 Apr, 2013, 04:09
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
Hyperscalper-
Thank you for your reply.
I believe there will be no problems to make the strategy able to define those orders since they are separated by groups.
But I still cannot get how the orders will be marked like I want to.
Look:
3 different strategies, single currency pair. All orders are pending and flow in a random sequence.
External ID has no constant number in itself. If I understood correctly, the code you provided add this constant number to all orders of a particular currency pair.
How I can label the orders of 3 different strategies then?
Thank you,
Arthur
|
|
|
|
 |
API Support
|
 |
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Fri 19 Apr, 2013, 07:20
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
ArthurV
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Fri 19 Apr, 2013, 17:10
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
API Support wrote: Thank you! So the only way is to type each unique order ID manually? If I got 3 different strategies - I have to run 3 TS instances with different settings then? Following this, each trailing stop instance I believe should have at least 5 fields where to type these order IDs.. How can I shorten my order IDs in order to type just last 3 digits of it in terms of code? Does it all sounds as a best solution or you can suggest how to do it somehow in the other way? Thanks, Arthur
|
|
|
|
 |
hyperscalper
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 1
|
Posted: Fri 19 Apr, 2013, 20:18
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
ArthurV wrote: Hyperscalper-
Thank you for your reply.
I believe there will be no problems to make the strategy able to define those orders since they are separated by groups.
But I still cannot get how the orders will be marked like I want to.
Look:
3 different strategies, single currency pair. All orders are pending and flow in a random sequence.
External ID has no constant number in itself. If I understood correctly, the code you provided add this constant number to all orders of a particular currency pair.
How I can label the orders of 3 different strategies then?
Thank you,
Arthur YES, YOU CAN ALSO MAINTAIN A LOCAL LIST IN EACH STRATEGY AND MAINTAIN THAT LIST OR SET OF ORDERS. ISSUES OF LIST MAINTENANCE APPLY TO THAT SOLUTION. But, using the "concatenated unique key" approach I suggest: It's simple, I think: 1) You have a FIXED magic number which a strategy instance uses, which is entered at Strategy startup. 2) Each instance can achieve uniqueness by incrementing an integer starting with 1 for each label String created. 3) You form a String by concatenation of these elements, such that the magic number is recognizable by parsing/matching within the label String. // just typed free form, may be syntax errors !! public int magicNumber = 33; // CONFIGURED differently at Strategy start !! int nextOrderId = 1; // increment each time it is used // make a unique label according to this scheme // THIS IS THE LABEL YOU WILL PROVIDE WHEN ORDER IS CREATED String newLabel(Instrument instrument) { String instrumentInvalid = instrument.toString(); String instrumentValid = instrumentInvalid.replaceAll("/",""); // strip out the slash String labelKey = "ORD_"+magicNumber+"_"+ // <-- all orders start with this (nextOrderId++) + "_" + instrumentValid; return labelKey; }
// recognize my magicNumber order if (order.getLabel().startsWith("ORD_"+magicNumber) { // then this is an order I want to process // if you are using multiple instruments, then // you'll also check that it ends with e.g. EURUSD // or the specific instrument string you want. // NOTE: EUR/USD would be illegal, but EURUSD is OK }
Sample order labels: Strategy 1 (magic number 33): ORD_33_1 (or the expanded form ORD_33_1_EURUSD) ORD_33_2 ORD_33_3 ... Strategy 2 (magic number 55): ORD_55_1 ORD_55_2 ORD_55_3 ... Strategy 1 (magic number 77): ORD_77_1 ORD_77_2 ORD_77_3 ... IF you also need uniqueness across Instruments, then you could append the Instrument "EURUSD" for example, but see my previous code example as you need to strip out the slash in "EUR/USD" to produce "EURUSD". Then just append something like "_EURUSD" to make the key longer and thus unique to a given currency pair (aka instrument). Other Strategies which are working with the same Instrument form their label strings in the same way, but using their specific Magic Number values. Thus, each Strategy is able to recognize Orders with a matching Magic Number and does not operate on any other orders, nor perform any Mass Closure statements which would affect orders "belonging" to the other Strategies'. HyperScalper
|
|
|
|
 |
ArthurV
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Sun 21 Apr, 2013, 20:58
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
Hyperscalper-
Thank you for another explanation.
So, let say I run 3 strategy instances (trailing stops) with predefined settings to recognise orders by ORD_33, ORD_55 and ORD_77.
Then, I drop pending orders manually. Do I have to change the magic number value at all times before I submitted an order at strategy start up below (if the new order applies to another strategy)?
Do I understand correctly?
// just typed free form, may be syntax errors !! public int magicNumber = 33; // CONFIGURED differently at Strategy start !! int nextOrderId = 1; // increment each time it is used // make a unique label according to this scheme // THIS IS THE LABEL YOU WILL PROVIDE WHEN ORDER IS CREATED String newLabel(Instrument instrument) { String instrumentInvalid = instrument.toString(); String instrumentValid = instrumentInvalid.replaceAll("/",""); // strip out the slash String labelKey = "ORD_"+magicNumber+"_"+ // <-- all orders start with this (nextOrderId++) + "_" + instrumentValid; return labelKey; }
Thank you,
Arthur
|
|
|
|
 |
hyperscalper
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Mon 22 Apr, 2013, 00:24
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
ArthurV wrote: Hyperscalper- So, let say I run 3 strategy instances (trailing stops) with predefined settings to recognise orders by ORD_33, ORD_55 and ORD_77.
Then, I drop pending orders manually. Do I have to change the magic number value at all times before I submitted an order at strategy start up below (if the new order applies to another strategy)?
What is the meaning of "I drop pending orders manually"? Do you mean "cancel" or what is your definition of "drop"? All orders must be created by the Strategy instance, in order to be managed by that instance. If you created an order with the JForex platform, its "label" field would not conform to the convention, and so it would not be recognized by any of the Strategies, since it would not contain the "magic number" label naming convention. HyperScalper
|
|
|
|
 |
ArthurV
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Mon 22 Apr, 2013, 12:59
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
Hyperscalper-
That is why I was confused from the very beginning! The only strategy I meant was trailing stop, which should manage my manually entered positions with different settings according to each strategy.
Sorry for my improper clarification of that.
It seems there is no way to do it the way I want to.
This is the only thing where MT4 platform with its mini-terminal steps ahead. There, I enter the market by clicking on my saved template (which includes this magic number already). Quick and convenient. It should be an important future request to make JForex truly superior platform.
Thank you anyway, Arthur
|
|
|
|
 |
hyperscalper
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Mon 22 Apr, 2013, 17:28
|
|
User rating: 98
Joined: Mon 23 Jul, 2012, 02:02 Posts: 656 Location: United States, Durham, NC
|
ArthurV wrote: Hyperscalper-
That is why I was confused from the very beginning! The only strategy I meant was trailing stop, which should manage my manually entered positions with different settings according to each strategy.
Sorry for my improper clarification of that.
It seems there is no way to do it the way I want to.
This is the only thing where MT4 platform with its mini-terminal steps ahead. There, I enter the market by clicking on my saved template (which includes this magic number already). Quick and convenient. It should be an important future request to make JForex truly superior platform.
Thank you anyway, Arthur This is software design and development. Generally there is a way to achieve what you want, provided you state clearly what you want. An interactive Strategy instance could easily be developed to "take control of" and manage orders which you have entered manually. You seem to be requesting some kind of "programmable or flexible" Trailing Stop feature in the JForex platform. Whether a generic mechanism would help you depends what you want, but the Strategy mechanism could give you exactly what you need. That's why it's available: to bridge the gap between "generic" platform features, and very specific needs of traders. I requested an enhancement, such that IOrder.setLabel(...) could change the label of an existing order. This was implemented in the API. Using this mechanism, your Strategy module could be shown the (manually entered) order you wish it to manage, (perhaps presented in a list) and then it could (optionally) change the label of that order and "take control" of that order according to some management Strategy. Like I said, this is software, and if you know what you're doing, you can accomplish just about anything. Short of that, you have to EXPLAIN exactly what you need so that we can help you  The best thing you could do is to establish a relationship with a software developer who could help you achieve your goals, and splash out a little money to compensate him/her  The only real purpose of a "magic number" in MetaTrader is to "tag" orders as unique and "owned" by an instance of an Expert Advisor (aka EA). Otherwise it has no particular purpose. HyperScalper
|
|
|
|
 |
ArthurV
|
Post subject: Re: ORDER MAGIC NUMBER/COMMENT |
Post rating: 0
|
Posted: Sun 28 Apr, 2013, 16:04
|
|
User rating: 0
Joined: Fri 12 Apr, 2013, 00:05 Posts: 13 Location: United KingdomUnited Kingdom
|
hyperscalper wrote: Hyperscalper- The best thing you could do is to establish a relationship with a software developer who could help you achieve your goals, and splash out a little money to compensate him/her  The only real purpose of a "magic number" in MetaTrader is to "tag" orders as unique and "owned" by an instance of an Expert Advisor (aka EA). Otherwise it has no particular purpose. HyperScalper Hyperscalper- Yes, I agree that it would be the easiest way to complete my query. I've contacted someone already  Sure, I need it to have exactly for the same purpose. Thank you. Regards, Arthur
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|