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.

Timer in strategy
 Post subject: Timer in strategy Post rating: 0   New post Posted: Sat 18 Aug, 2012, 08:43 

User rating: 0
Joined: Thu 09 Aug, 2012, 01:17
Posts: 9
Is there a way in JForex to have a timer inside an IStrategy object. For instance, I want some code to be run every 5 seconds while the strategy is running.


 
 Post subject: Re: Timer in strategy Post rating: 1   New post Posted: Sat 18 Aug, 2012, 14:50 
User avatar

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

One example of this i made in one of my strategies: used to update a table every 10 secs.

private void myTableUpdate() {
        myTimer = new java.util.Timer();
        myTimerTask = new TimerTask() {

            @Override
            public void run() {
                try {
                    updateTableContent();

                    // just to test activity - myConsole.getOut().println("testing");
                } catch (Exception e) {
                }
            }
        };
        myTimer.scheduleAtFixedRate(myTimerTask, 0, 10000);
    }


Hope that helps.

Trade well and prospers in your way

JL


 
 Post subject: Re: Timer in strategy Post rating: 0   New post Posted: Sun 19 Aug, 2012, 05:35 

User rating: 0
Joined: Thu 09 Aug, 2012, 01:17
Posts: 9
Thanks for the response jlongo. Timer objects execute their code in their own thread. Is the JForex code thread safe?


 
 Post subject: Re: Timer in strategy Post rating: 1   New post Posted: Sun 19 Aug, 2012, 12:32 
User avatar

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


JForex have implementations that are thread safe and others maybe not...
The "thread safe" depends on how you implement your code/objects...

To see more on "threading" in JForex see here.

Best regards

JL


 

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