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.

general java programming question
 Post subject: general java programming question Post rating: 0   New post Posted: Sat 16 Aug, 2014, 06:47 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi

I have a strategy which has about 1,350 lines of code and currently deals with one currency pair only.

I wish to implement several currency pairs

What is the best programming approach ?

creating arrays? using 'switch'

Any comments , welcome

Bob M
Dunedin
New Zealand


 
 Post subject: Re: general java programming question Post rating: 2   New post Posted: Mon 18 Aug, 2014, 15:13 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

In general, implementing multiple currency pairs is not a big deal. But of course, it depends on how does your existing code look like.

Let me give a few examples which probably will get you further:

First, you have to define/declare the currency pair. You can do it hard-coded in the source, or you can make a strategy parameter out from it, so you can select every time during strategy start:
    @Configurable("")
    public Set<Instrument> selectedInstruments = new HashSet<Instrument>(
        Arrays.asList(new Instrument[] {Instrument.EURUSD, Instrument.USDCHF, Instrument.GBPUSD, Instrument.USDJPY})
    );


If you happen to run on a Remote environment, you have to explicitly subscribe to the instruments:
    context.setSubscribedInstruments(selectedInstruments, true);


And finally, you have to filter the onTick(), onBar() (maybe onMessage() as well) function calls to deal only with the instruments that you have selected:
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (selectedInstruments.contains(instrument)) {
            // here comes the code that deals with ticks of the selected instruments
        }
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (selectedInstruments.contains(instrument)) {
            // here comes the code that deals with bars/candles of the selected instruments
        }
    }

    public void onMessage(IMessage message) throws JFException {
        IOrder anOrder;

        anOrder = message.getOrder();
        if (selectedInstruments.contains(anOrder.getInstrument())) {
            // here comes the code that deals with messages for the selected instruments
        }
    }


I hope this helps.


Edit:
And of course, the topic should move to Automated Trading Knowledge Base, as it has nothing to do with the Strategy Contest ;).


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Tue 19 Aug, 2014, 07:45 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi tcsabina

Thanks for your input.............

I was initially going to expand my one program to handle multiple currency-pairs but have now decided to simple duplicate the current strategy and modify the contents according to each currency-pair.

I have some data mining involved and so the modifications are somewhat extensive but OK to do

My intention is to have x strategies running simultaneously, each providing a suggested possible trade at regular intervals, and another java program which will receive a message from each strategy stating the possible trade and amount, this additional program will consider all x suggested trades, maybe reducing x trades to the equivalent y trades (where y < x) and sending the identical message back to each of the x strategies with the final result - then, each of the x strategies will place a trade if it is included in the final analysis

I haven't explored messaging yet but it should be reasonably easy to implement

Kind regards

Bob M


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Tue 19 Aug, 2014, 09:27 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Take a look on this to get started.

there are some topics also in the forums about broadcast messages...


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Tue 19 Aug, 2014, 10:43 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Many thanks, tcsabina

I look forward to implementing these messages - back and forth

Kind regards

Bob M
Dunedin
New Zealand


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Wed 20 Aug, 2014, 13:27 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
us_copiosus wrote:
Hi tcsabina

Thanks for your input.............

I was initially going to expand my one program to handle multiple currency-pairs but have now decided to simple duplicate the current strategy and modify the contents according to each currency-pair.

Bob M


For your level of experience, and an easy way to achieve
your goals, as you may already have discovered....

Just "cloning" the runtime Strategy.jfx by simply
file copying and creating
Strategy2.jfx, Strategy3.jfx you will have independently
runnable instances. You will not have to create multiple sources
with different class names.....

HyperScalper


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Wed 20 Aug, 2014, 17:16 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi HyperScalper

I am not sure about "my level of experience" :)
I have been interested in trading for about 5 years now - it certainly takes time and a lot of effort to understand the complexities of the forex market

As regards messaging, which I see you are well versed in, given my outline above concerning messaging do you think I could implement this using IMessage or should I bring in a third party messaging service such as Apache ActiveMQ message broker

My uncertainty is I require x messages to be sent to a controlling strategy at staggered intervals (i.e. as each of the x independent agents reaches a decision).
I then need the controlling strategy to realize at some point that it has received all x messages
It will then do some calculations and finally sent an identical message back to each of the x independent agents who will open a trade if required

Many thanks for your time, and happy trading

Bob M
Dunedin
New Zealand


 
 Post subject: Re: general java programming question Post rating: 1   New post Posted: Wed 20 Aug, 2014, 20:05 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
us_copiosus wrote:
Hi HyperScalper

I am not sure about "my level of experience" :)
I have been interested in trading for about 5 years now - it certainly takes time and a lot of effort to understand the complexities of the forex market

As regards messaging, which I see you are well versed in, given my outline above concerning messaging do you think I could implement this using IMessage or should I bring in a third party messaging service such as Apache ActiveMQ message broker

My uncertainty is I require x messages to be sent to a controlling strategy at staggered intervals (i.e. as each of the x independent agents reaches a decision).
I then need the controlling strategy to realize at some point that it has received all x messages
It will then do some calculations and finally sent an identical message back to each of the x independent agents who will open a trade if required

Many thanks for your time, and happy trading

Bob M
Dunedin
New Zealand


IMessage in the Dukascopy API? in a word.... "NO" but consider that you
have any option you want if you'll just invest some time in learning how
to use the Standalone API in "creative" ways.

OK, well "level of experience" in JForex programming. For the type of problem
you are trying to solve, I'd suggest you get into standalone API and run "N"
dynamically loadable concurrent strategies within the same process.

Then, coordination between the "dynamic but fiercely independent 'experts'"
which you've so carefully crafted :) can communicate in the same memory
space. Use whatever communication mechanism you need "in process" and
just use the IStrategy stuff to hook into Dukascopy's data feeds, etc.

There's no reason why you can't write your own Moving Averagers, is what
I'm sayin'... or anything else you want to do...

Don't be locked to the "IStrategy" structure. You may use some strategy
instances in order to "sink" data, but these IStrategy objects can have any
number of additional external interfaces, run any number of threads, and
resolve your problem in a more "scalable" fashion.

One thing about Dukascopy is that they do not restrict us in any way, how
we "embed" the IStrategy interface-based objects into an overall system which
can use literally any Java-based code imaginable, including, of course, on
local systems, Swing user interface components or even embedded web
servers, etc... But I digress, just showing off I guess....

The Sky's the Limit on what you can do. Don't restrict yourself to the concept
of having to use Strategy instances "loosely coupled" over unreliable communications
media, but decide at a high level what you want, and then use the Strategy idea
within a standalone API Client to "hook" your logic into Dukascopy, while using
literally any other programming techniques to give yourself a more elegant solution.

Capiche?
HyperScalper


 
 Post subject: Re: general java programming question Post rating: 1   New post Posted: Wed 20 Aug, 2014, 20:16 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
tcsabina wrote:
Take a look on this to get started.

there are some topics also in the forums about broadcast messages...


The problem with using IEngine.broadcast is that you have to write a "messaging
infrastructure" and (at least at the moment) Remote Server does not broadcast
to all clients, only the JForex client.

I write a messaging system, using the broadcast mechanism and, in the end, it
really isn't worth the trouble... Sure clients can "subscribe" to the messaging "bus"
and all of that stuff, but really there are too many issues with that mechanism.

Write your own communication mechanism. Unless you are running on Remote Server,
you can use sockets or any other mechanism to communicate. If you don't know
the limitations of Remote Server, you should read about it...

In the end, getting your own VPS or dedicated server is the very best way to write
"serious" complex code. Consider that you can get a VPS which is entirely adequate
from an outfit like HostEurope.ch for maybe 20 CHF per month, and you can do
literally anything with that server instance...

HyperScalper


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Wed 20 Aug, 2014, 21:06 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi hyperscalper

Many thanks for your informative suggestions.......

I am afraid I don't understand some of it :)

What is the difference between "Dukascopy API" and "standalone API" ?

"no reason why you cannot write you own Moving Averagers" ?
do you mean code MAs etc. yourself ?
I code all required mathematical variables, MAs, ROCs, WILRs etc.

I will take your advice and set up my own messaging system

"running on Remote Server" ?
I local run on a laptop :)

"getting your own VPS" ?
I think at this stage, you are getting way out of my zone :)

Bob M


 
 Post subject: Re: general java programming question Post rating: 1   New post Posted: Thu 21 Aug, 2014, 12:05 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
us_copiosus wrote:
Hi hyperscalper

Many thanks for your informative suggestions.......

I am afraid I don't understand some of it :)

What is the difference between "Dukascopy API" and "standalone API" ?

"no reason why you cannot write you own Moving Averagers" ?
do you mean code MAs etc. yourself ?
I code all required mathematical variables, MAs, ROCs, WILRs etc.

I will take your advice and set up my own messaging system

"running on Remote Server" ?
I local run on a laptop :)

"getting your own VPS" ?
I think at this stage, you are getting way out of my zone :)

Bob M


OK, basically when an IStrategy instance runs in JForex, the
Dukascopy API is present within the runtime. When you run
an IStrategy outside of JForex environment, then you provide
the runtime environment through the API supporting JAR files
and your own "main" entry point which then creates an
IClient (since JForex is the "client") which permits you to
run Strategy instances, connect to data feeds, etc.

You manage the "reconnect logic" if there is a network problem,
and also you must collect username/password information plus
manage the "captcha" PIN for login. Otherwise, then you can
run multiple IStrategy instances, and provide them with
startup parameters. However, you do not have the JForex
startup parameter facilities, and your code needs to
collect and provide the startup values for the Strategy
modules.

So it is the "Standalone API" usage, and this gives you
complete control over what happens in your custom
IClient process, while still having access to Dukascopy
feeds, and Order management via the "embedded"
IStrategy instances you launch inside the same
Operating System process either on Windows or
Linux, etc...

Hope that helps !
Brent


 
 Post subject: Re: general java programming question Post rating: 0   New post Posted: Thu 21 Aug, 2014, 23:19 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Thanks for that explanation............

Clearly there are some great opportunities out there is you are a coding guru :)

I understand the concept of a standalone API and endorse your reasoning behind using one.
I have always believed that in-house programs surpass any 'off the shelf' stuff !

My last regular job (a long time ago) was with an insurance company here in Dunedin and it was interesting to see the 'old boy' network working away amongst Insurance managers and computer reps - end result - the company bought a very expensive piece of software, rather than design in-house.....silly decision really

However, my desire is not really to get involved with what I see as a whole lot of housekeeping. I think I would rather remain with Dukascopy's API and work within its restraints (if any).

I have downloaded the Apache messaging broker and look forward to getting it up and running

Thank you for taking the time :)

Bob M


 

Jump to:  

cron
  © 1998-2024 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