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.

Strategy using external concurrent threads for background calculations
 Post subject: Strategy using external concurrent threads for background calculations Post rating: 2   New post Posted: Fri 14 Feb, 2014, 17:46 

User rating: 2
Joined: Tue 25 Dec, 2012, 17:56
Posts: 15
I wrote a JForex Strategy that needs to spawn a number of threads to execute concurrently. Concurrent multithreading is essential because without it this strategy is impossible to implement. The threads receive tick data through BlockingQueues and use other BlockingQueues to send results to each other and back to the Strategy. I implemented threads using Java 7 standard runnables and task.start() from the Strategy. The code is made as to not create any delays in executing the Strategy's onTick method. Everything works very fine except that from time to time Historical Tester stops sending ticks. This happens for both low and high test speed and also while running within JForex Client.

I thought that maybe it would be better to create and manage threads using finalContext.executeTask(task) according to https://www.dukascopy.com/wiki/#Threading. So, I wrote a test ConcurrentThreads.java. Here I face difficulty in trying to run two threads simultaneously. Please try to run it in the JForex client.
The ConcurrentThreads Console output is:
...

15:37:13 NamedTask: taskOne - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskOne - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskOne - ticker:69 <*><*><*><*><*><*><*><*><*><*>
...

With concurrent execution the expected output should contain mixed prints from taskOne and taskTwo, like this:
...

15:37:13 NamedTask: taskTwo - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskOne - ticker:71 <*><*><*><*><*><*><*><*><*><*>
15:37:12 NamedTask: taskTwo - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskOne - ticker:70 <*><*><*><*><*><*><*><*><*><*>
15:37:11 NamedTask: taskTwo - ticker:69 <*><*><*><*><*><*><*><*><*><*>
...

Question 1: is it possible to run a few tasks concurrently, if they are created and started from JForex strategy using finalContext.executeTask(task) & task.start()? What must I change in my ConcurrentThreads.java to get simulataneous output from fom both taskOne and askTwo?

Question 2: Have you got any clue why feeding of ticks stops when I run Strategy + multitasking / standard runnables?

The problem is quite important since the strategy is getting good results and I'd like to prepare the final version for live execution. But it can't stop, of course.


Attachments:
ConcurrentThreads.java [2.79 KiB]
Downloaded 66 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: Strategy using external concurrent threads for background calculations Post rating: 0   New post Posted: Tue 18 Feb, 2014, 10:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
leoterra wrote:
Question 1: is it possible to run a few tasks concurrently, if they are created and started from JForex strategy using finalContext.executeTask(task) & task.start()? What must I change in my ConcurrentThreads.java to get simulataneous output from fom both taskOne and askTwo?
Not execute them through IContext.executeTask, rather simply run them. IContext.executeTask executes all tasks in the same single-threaded executor and it is meant for order creation/modification requests.
leoterra wrote:
Question 2: Have you got any clue why feeding of ticks stops when I run Strategy + multitasking / standard runnables?
Without a case (a strategy and Historical Tester setting print-screen) we can only speculate on the causes.


 

Jump to:  

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