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.

Why "incorrect thread"?
 Post subject: Why "incorrect thread"? Post rating: 0   New post Posted: Tue 04 Aug, 2009, 09:40 

User rating: -
Hi ,i use a new thread to process with some extra dynamic datas, but when i submit a new order in this thread ,there's an "incorrect thread" exception, why?


 
 Post subject: Re: why "incorrect thread"? Post rating: 0   New post Posted: Tue 18 Aug, 2009, 13:02 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,
JForex API was designed so that most of the methods (mostly orders manipulation) can be run only from strategy thread. Pretty much like Swing in java. To submit order from another thread you need to run task through the IContext.executeTask(Callable<T> callable) method


 
 Post subject: Re: why "incorrect thread"? Post rating: 0   New post Posted: Fri 13 Jan, 2012, 18:27 

User rating: 1
Joined: Tue 12 Jul, 2011, 20:43
Posts: 51
Location: Germany,
Hello support,

I also have this problem.

My scalping strategy creates a bottom tab with an "open" and a "close" button with ActionListeners onStart. I want to open and close an order manually (only one order at the same time).
Also the strategy creates an unlocked HorizontalLineChartObject on a TickBar chart onStart. With this line I can determine the StopLoss level manually per mouse in the chart.
The advantage of using custom "open" and "close" buttons in conjunction with horizontal StopLoss line should be a fast trading with precise money management which is important for scalping. That is, the strategy calculates an exact trade amount (based on the distance between current price and horizontal line StopLoss level) before opening the trade. Also the trade direction (long or short) can be determined automatically - if I drag the StopLoss line below current bid price then the trade direction is long automatically, and if I move the StopLoss line above current ask price then the trade direction is short automatically.

Therefore I want to use custom buttons instead of standard JForex order functionality.
But when I'm clicking on "open" button, only "Incorrect thread" is printed out on console.

I assume that I have not only two but three different threads: a main strategy thread, a thread when I'm clicking on "open" button and a thread when I'm clicking on "close" button.
If there is a possibility to realise this strategy anyway - especially to open and close an order instantly by button click before next tick arrives - please describe a solution.

Thanks in advance and regards
AbsoluteReturner


 
 Post subject: Re: why "incorrect thread"? Post rating: 0   New post Posted: Mon 16 Jan, 2012, 09:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
AbsoluteReturner wrote:
If there is a possibility to realise this strategy anyway - especially to open and close an order instantly by button click before next tick arrives - please describe a solution.
If you ask about creating an order from a different thread than that of strategy, then in the current implementation it is forbidden, the closest that you can get is using a queue of order requests and process them in onTick. If your inquiry was about something else, please specify its details.


 
 Post subject: Re: why "incorrect thread"? Post rating: 0   New post Posted: Tue 17 Jan, 2012, 13:27 

User rating: 1
Joined: Tue 12 Jul, 2011, 20:43
Posts: 51
Location: Germany,
Yes, my intention was to create an order from a different thread than strategy thread (inside a button click ActionListener).
I also known about the workaround you suggested (register button click[s] in global / class variable[s] and execute appropriated task[s] inside next onTick event).
But for a strategy which is created to support manual scalping this means at least one more tick slippage.

Therefore I want to ask again if and when it will possible in the future to avoid this workaround and manage orders inside different threads (open an order in one thread, and close the same order in another thread).


 
 Post subject: Re: JFOREX-3449 why "incorrect thread"? Post rating: 0   New post Posted: Tue 17 Jan, 2012, 13:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The issue is under investigation.


 
 Post subject: Why "incorrect thread"? Post rating: 0   New post Posted: Tue 17 Jan, 2012, 17:13 

User rating: 1
Joined: Tue 12 Jul, 2011, 20:43
Posts: 51
Location: Germany,
Quote:
The issue is under investigation.

Please consider also the possibility to manage one order over more than two threads.
For example, having a strategy with a bottom tab containing several graphical objects:
- one button to open a trade, or respectively one button for long and short trades (means creating a long / short order)
- one button to cancel the trade (means closing the order before filled)
- one button to close the order
- one checkbox to add / delete a take profit to the order
and so on ...


 
 Post subject: Re: Why "incorrect thread"? Post rating: 0   New post Posted: Mon 27 Feb, 2012, 10:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
As already mentioned in our first reply, you can do this with IContext.executeTask, see:
https://www.dukascopy.com/wiki/#Threading


 

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