fprophet wrote:
I understand that order Labels have to be unique - and I have been using
my Strategy name + instrument + a counter for all my Labels.
Yes that is one option, however, it won't help if you will call the same strategy on the same instrument (or instrument set). For such case consider adding an
java.util.UUID which will guarantee the label uniqueness (i.e. Strategy name + instrument + a counter + UUID.randomUUID().toString().replaceAll("-", "")). In fact using the UUID alone will also guarantee the uniqueness, but will make the order difficult to distinguish in logs and on chart.
Another option is maintaining all strategy-created orders in a
java.util.List or
java.util.Set, see:
https://www.dukascopy.com/wiki/#Order_Management/Maintain_order_listActually there are two things to be aware of:
- Label uniqueness among all orders. Order opening attempt with the same label on the same account will result in a JFException.
- Making sure the strategy works only with its own orders (if that is required by the strategy logic).
fprophet wrote:
Do I also need to put a 'thread id', or something that uniquely
identifies the preset that I'm using, or the Strategy run start-time
perhaps (?) - so that I can check each order is actually 'mine' before I
update it?
It is up to you, however, we find the previously mentioned approach the least tedious.
fprophet wrote:
I notice that none of the example Strategies provided on the Support
Forum (JForex Support Board > Automated Trading > Code Base >
Strategies) include any code that performs this sort of ownership
checking - so I have been assuming that the JForex platform
automatically synchronizes threads & associated data.
Each strategy works in its own thread, but the platform does not prevent strategy from modifying a not-its-own order, thus, depending on the strategy, they might need to get updated such that they don't modify/close orders of other strategies.
fprophet wrote:
If indeed I need to specifically code in order to parallel run multiple
instances, then some guidance and/or an example of best practice Java
code would be extremely useful please.
See our previously given example.