Dukascopy
 
 
Wiki JStore Search Login

Article series "Creating your first strategy" - Support and files thread
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 08 Oct, 2012, 11:10 
User avatar

User rating: 2
Joined: Sat 05 May, 2012, 13:08
Posts: 33
Location: ItalyItaly
jlongo wrote:
Hi scramble:

Thank you for your comments. I'm very glad that my articles can be useful for someone.

Let's see if i have the time to release my planed new articles about strategies this weekend.

Trade well and prospers in your way.

Best regards

JL


yes i find your articles very helpful since i'm a beginner programmer :lol:
anyway already writing by first automated strategy and finding huge walls every new 5minutes, but i like java and i like its structure. i only need to learn well to manage with some functions. it's also very helpful that we can download from jforex contest other people''s strategy so i can understand few more about some steps.

have a bit question:
do you know or do you remember if someone posted or if somewhere is posted an idea about buying/selling an MA price? i have found my own idea and seems working well, but would like to see if there are other ideas different from mine and after a research into dukascopy forums i didn't find anything about.....

and another question:
i see almost all people in contest using the same script about position open. do we need to use the string, or can we use other ways? for example i simply have a "private int maxpositionallowed = 1;" which is then called later in a "private void" about positions engine. hope you understand what i mean. lol.


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 08 Oct, 2012, 14:02 
User avatar

User rating: 3
Joined: Tue 14 Feb, 2012, 19:31
Posts: 143
Location: Romania, Bucharest
Greetings Jose,

Congratulations for one of the best series in the article contest.
It helps the Dukascopy community traders to devellop their own strategies in J-forex Platform.
It is one of the things that were missing in our community and you deserver all the gratitude and thanks for it.

I want to use your series of articles to create my own strategy in the Strategy Contest.
It's nice because it can be used as a manual.

Waiting for more quality info from your behalf.

trade well,
To your success,

Doctortyby


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 08 Oct, 2012, 15:11 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi scramble:

There are some strategies based on MA's (SMA, EMA, etc) out there... have you explored this section ? -> viewforum.php?f=7


About your question about open orders (i think) the easiest way is using "engine.getOrders()" and this is why most people (myself included) use it but you can use any way where you can achieve the same result. You can use events of "onMessage()" function for example... Your imagination and the work needed for achieve what you want is the only limitation.

Best regards

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 08 Oct, 2012, 20:09 

User rating: 0
Joined: Mon 21 May, 2012, 16:14
Posts: 4
Location: PolandPoland
Hi JL,

It's excellent!

I tried the strategy out today, and it's exactly what I need. I've been using the other one, but that didn't have the ability to place limit orders, so your new strategy is just what I need, thank you.

I was able to place buy limits, but the sell limits execute at market for some reason. Please could you have a look at it when you have some time?

Thanks once again,

N


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 08 Oct, 2012, 20:43 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi nowytarg:

As far i tested it i have no problems with it unless the ones i talk on article series... take in consideration that the orders placed with buy and ask options are only relative to feed price (ask or bid value) not to the order itself and not are limit orders... For example, if you place a conditional Sell by bid or ask price the order is triggered when feed price for ask or bid price gets <= order submited price. The inverse for Buy. Maybe i will try to develop limit orders in a near future, but don't consider it a promess.

Anyway i will check again if something is wrong with i say before and if so i will update the strategy file.

Best regards

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Tue 09 Oct, 2012, 13:08 

User rating: 0
Joined: Mon 21 May, 2012, 16:14
Posts: 4
Location: PolandPoland
Hi JL,

Now I get it, the pending orders are Buy/Sell stops, as opposed to limit orders, which is why I couldn't get it to work for me and why the orders were triggering immediately.

Yes, the strategy works 100%, and is exactly what I need, so thank you again for your efforts with this. It's a very good tool for practicing.

I would really appreciate it if you could please include limit orders in the strategy, since that is how I trade, and it would greatly benefit my practicing.

Once again, thanks for your efforts and thanks for sharing.

Regards,

N


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Tue 09 Oct, 2012, 20:47 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Dukascopy Community:

This post is just to announce and release a new version of "myOfflineTrades" with a new feature:

- Support for simple limit orders (BUYLIMIT and SELLLIMIT)

Image

Please see the first post for download.

@nowytarg: You are a luky guy :)... now you have what you asked for :)

I hope you like it!

JL


Attachments:
2012-10-09_21_00.png [39.06 KiB]
Downloaded 1638 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.
 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Tue 09 Oct, 2012, 21:48 

User rating: 0
Joined: Mon 21 May, 2012, 16:14
Posts: 4
Location: PolandPoland
Thank you VERY MUCH Sir, you are too kind. This is exactly what I need. Anyone who is serious about trading needs to be using this tool.

All the best,

N


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 15 Oct, 2012, 14:28 
User avatar

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

I would like to ask something regarding a previous article of the series. It is about backtesting.
By any chance, have you ever tried to backtest using a CSV file instead of the Historical Tester of the platform? I would like to do some stress testing strategies, and the platform`s backtest speed is limiting this process. I know that prices can be downloaded to CSV file using the Historical Data Manager, but I haven`t found anything about how to make the strategy use the CSV as input, instead of the price feed of the platform.

Based on my limited experience I could see to ways to do this:
a) process the CSV file in the strategy itself. There is a little help for this here: http://www.dukascopy.com/wiki/#Get_data_from_CSV, but this is far from complete for what I want to use it.
b) make a feed from the CSV file, and use this feed (IFeedDescriptor(), etc...) in the strategy. I haven`t found anything on this.


thanks and regards


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 1   New post Posted: Mon 15 Oct, 2012, 15:20 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi tcsabina:


You are right, "historical tester" uses their own feed. If it don't have the data needed for the period it downloads it and stores it on the cache. Anytime you try to do backtests on this intrument and period and if it is on cache, it uses it. The cache is located on your OS user folder under "Local Settings" folder or similar depending on your operating system. All data is stored on *.bi5 files on a folder structure taking in consideration the intrument and date/time. I don't know any way to use the csv or hst file generated by the Historical manager in the historical tester. But as you have the data on cache, i don't see any trouble about stressing the system to use it directly by historical tester (it will be the same or more stress if you "process" csv files). If you need the cache files on different computers you can save this "cache" between them to avoid download times. Also you can define the location of this cache folder under "tools -> preferences -> advanced" menu.

As you say in your post, the other ways available are as you say. I don't know of any example of this, maybe support can help on this.

I hope this helps in what you want

Best regards

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Tue 16 Oct, 2012, 06:21 

User rating: 0
Joined: Tue 16 Oct, 2012, 06:03
Posts: 3
Hi JL,

On beginning I would like to thank you for very good series of articles.
I've found them very helpful, especially that I am fresh to programming.

I have got stuck in one place and I would like ask you for help.

I've try to filter data feed and try to use presented way:

public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != Instrument.EURGBP || instrument != Instrument.EURUSD || instrument != Instrument.GBPUSD) return;{
console.getOut().println(instrument.toString());
        }


For me it works this way, but i am not sure if it gives the same effect (My goal is to have very fast information/filtering).

if (instrument == Instrument.EURGBP){
        console.getOut().println(instrument.toString());
        }
        if (instrument == Instrument.EURUSD){
        console.getOut().println(instrument.toString());
        }
        if (instrument == Instrument.GBPUSD){
        console.getOut().println(instrument.toString());
        }


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Fri 19 Oct, 2012, 14:18 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi wizytacja:

In that way you get the same results in both snipets, saying one is faster than another, well we just can say that doing some stress tests with profiling.

If you want to do different things with each pair, the second way seems to me the best choice...
If you want to do the same code for all pairs, the first have more chances to be faster as with "||" at first "true" found it does the return ignoring the other comparisons. In second snipet all comparisons are done.

Sorry to take so much time to answer you, but your post went unnoticed.

Best regards

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Mon 05 Nov, 2012, 22:02 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Dukascopy Community:

Other article of this series is waiting approval and i also released the source code of "myOfflineTrades".
You can get it at the first post.

Trade well and prospers in your way.

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Sat 24 Nov, 2012, 16:27 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Dukascopy Community:

Just to announce the release of other version of "MyOfflineTrades" with a small improvement:

- Now we have at the top of the window the date/time of the date/time on Historical Tester.

Image

Later i'm thinking about the possibility of showing a simple report on the fly when we want to see it.

I hope you like this small improvement.

You can get the last version at the first post.

Best regards

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Wed 26 Dec, 2012, 21:38 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Dukascopy Community:

First of all, i wish you all had a Happy Christmas with all familly and friends and i hope you will have a great 2013!

Just to announce and publish another small improvement in MyOffineTrades strategy:

Image

Now we can see the initial equitity value (I.E), actual equitity value (A.E.) and the profit/loss value along the trade testing period without the need to wait for final report or making the calculations with the values on progress bar.

You can get the updated strategy at first post. I hope you like this change.


Happy New Year for all!

JL


 
 Post subject: Order Operations should not be done in actionPerformed ? Post rating: 2   New post Posted: Fri 28 Dec, 2012, 21:50 
User avatar

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

I had a look at your source code and I noticed that you execute orders from within Swing actionPerformed which is on the single-threaded Swing event handler thread. Although this might seem like it works fine, I was just wondering, I thought *all* such order commands must/should be marshalled via IContext.executeTask(task), where task needed to implement the java.util.concurrent.Callable interface, and return values would be fetched by the invoking thread via java.util.concurrent.Future.get(), etc...

Of course if order commands are done in IStrategy callbacks, then we are already in the correct execution context to handle order operations. Like in IStrategy.onTick or onMessage or onBar, etc.

This is not a criticism at all, but just wondering whether, strictly speaking, that's the right way to do it. In my case, I probably overly complicate things, since from within actionListeners, I usually kick off a Runnable in a separate thread, and that thread, in turn, invokes IContext.executeTask(task) where each task implements the Callable<return-type> interface. That separate thread then fetches any return from the task using java.util.concurrent.Future get(). All of that definitely complicates coding, but I thought that it was probably necessary to be sure that all order operations are done on the correct dispatch thread through IContext.executeTask.

I do a lot of fast Live order processing driven by a Swing graphical user interface (gui), so I need to be absolutely sure that all my order manipulation commands are in the "executeTask" context thread, but sometimes that seems to the programmer to be an unnecessary complication. But, actually, if you read further you might find it's absolutely necessary to use these mechanisms or the API for Order Processing, etc., will not work properly. In "mission critical" applications, it's essential, and it may apply to your code as well.

I noticed in your comments that sometimes a piece of code did not seem to work properly. That is exactly what would happen (intermittently) if the code was not being dispatched on the correct thread for API order processing. For example, when you use
List<IOrder> openOrders;
            openOrders = myEngine.getOrders();


from within an actionListener, the command could fail to work properly because it should run not on the Swing "gui" thread but, instead, on the IContext.executeTask underlying thread for correct synchronization with the API. A task executing on the Swing thread could execute concurrently with another task executing on the underlying IContext.executeTask(task) execution thread. This could result in errors, and they would appear intermittently, as you sometimes may observe.

In a heavily multi-threaded program doing active order processing, these Thread Synchronization issues will multiply and the system will not behave properly. I could give you some examples of how you might handle these things, but I'm sure you already could work it out yourself. Anyone who puts a user interface on an IStrategy module must be aware of these threading issues, but they are far less important, the simpler the code is, or the less frequently the order operations are performed, but they are still probably technically incorrect, and that would lead to puzzling and unreliable results (i.e. errors or BUGs which are untraceable) when thread synchronization is not maintained through the correct mechanisms for IContext.executeTask(task) in the API.

So, for example, if you want to populate a JTable from order data derived from the JForex API you would probably want to do all of the API work within a java.util.concurrent.Callable<returntype> object invoked through IContext.executeTask(task), and have that task synchronize on a data structure and populate it, all within that task, and then have that task invoke another task using SwingUtilities.invokeLater(task) which would synchronize on the data structure, and populate the JTable from the data. This would ensure that both operations were performed from within the correct thread and synchronization contexts. Sounds difficult, and it is somewhat, but unless it's done in this way, errors in execution will almost inevitably appear, and thread synchronization errors are the worst to try and debug. Also, few Java programmers really know enough about threads, to realize that they may not be using the correct techniques in their code until things just get too complex and more bugs show up. (no criticism of you, just in general)

I hope you won't be offended by this, but it really does apply to a lot of coding on the API where programmers do things in IStrategy modules which involve either a GUI or additional thread activities which need to call API order processing functions.

HyperScalper


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Fri 28 Dec, 2012, 22:31 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi hyperscalper:

Yes, you are right about to create a separate thread to maintain the order flow, but that certainly complicates too much the coding part. I'm doing this strategy to show that don't is necessarily complicated, i'm trying to do the code the simplest way i can to someone learn with it as i'm doing the same. Also i'm not a programmer and i have also too much to learn about Java, and this approach can not be the best way because of that "intermitently" events. But for now it works and the present "bugs" are somewhat mitigated with the synchronyse "button". Also this strategy is not to run on LIVE mode, and don't have a "critical" aspect. May be in some future i decide to do this strategy in a different way. One way can be what you suggested.

Thank you for your comments.

Have a good New Year

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Fri 28 Dec, 2012, 23:06 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
If you'd like some tips, I'll be very glad to pitch in and help. It's not usually very complicated to learn or to implement in Java code.

Your code doesn't have that many areas where order operations are performed, outside of IStrategy callbacks.

Happy New Year !!

hyperscalper


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Sat 29 Dec, 2012, 00:07 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi hiperscalper:

Thank you for your help. When i have some doubt's i remember you about your offer :) !
I have sent you one email with my contact if i can help in something too and we can keep in touch :)

Yes, i have a call in function synchronize and order placement... i forget that ones as i try to do all API calls on main class and pass arguments... i will change the code to call a function on main class and pass the needed arguments. Also i need to clean up some code i created to try to resolve some problems.

Best regards and a Happy New Year :)

JL


 
 Post subject: Re: Article series "Creating your first strategy" - Support and files thread Post rating: 0   New post Posted: Sun 27 Jan, 2013, 16:01 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Dukascopy Community:


I have created one indicator to show us the line of High, Low, Close and Open of the previous period (daily, weekly and monthly) and also 1/3, 1/2 and 2/3 of the High/Low and Open/Close range of the correspondent period. Also you can activate the visualization of previous periods. I hope you find it useful.

Image
Daily period
Image
Weekly period
Image
Monthly period

You can get this indicator at the first post of this thread.

Trade well

JL


Attachments:
JL_Range_Monthly.png [27.07 KiB]
Downloaded 1343 times
JL_Range_Weekly.png [29.55 KiB]
Downloaded 1172 times
JL_Range_Daily.png [19.31 KiB]
Downloaded 1481 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.
 

Jump to:  

  © 1998-2011 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