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.

Trade at specific time by timer
 Post subject: Trade at specific time by timer Post rating: 0   New post Posted: Thu 30 Jan, 2014, 00:10 

User rating: 0
Joined: Thu 12 Dec, 2013, 09:24
Posts: 21
Location: Ukraine, Kyiv
Hello,
I want to make trades at specific time by timer. In order to achieve this I wrote the following code:

  public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.timer = new Timer();
        tt = new TimerTask(){
                 @Override
            public void run() {
                try {
                    InitiateTrading();
                } catch (Exception e) {
            };
        }
        };
        timer.scheduleAtFixedRate(tt, 0, 1000);
    }
   
    private void InitiateTrading() throws JFException
    {
        Date d = new Date();
        Calendar calCurrentTick = GregorianCalendar.getInstance();
        calCurrentTick.setTime(d);
        int year = calCurrentTick.get(Calendar.YEAR);
        int month = calCurrentTick.get(Calendar.MONTH);
        int day = calCurrentTick.get(Calendar.DAY_OF_MONTH);
        int hour = calCurrentTick.get(Calendar.HOUR_OF_DAY);
        int minute = calCurrentTick.get(Calendar.MINUTE);
        int second = calCurrentTick.get(Calendar.SECOND);
       
        if(year == 2014 && month == 1 && day == 29 && hour == 23 && minute == 01 && second > 55 )
        {
                print("hour: " + Integer.toString(hour) + " : minute tick " + Integer.toString( minute) + " second=" + second );
        }
    }

Full code is available in attachment.
But sadly print is not executed at all.
N.B. Please don't propose for me to use onTick because ticks doesn't happen EVERY second. If to look in tick history sometime it happens that last tick of the minute was at 22 second especially in expectation of some news, but I need some specific way to execute trade at some specific date time. Specific till second. For example as in code
2014-01-29 23:01:55


Attachments:
tradeAtSpecificTime.java [2.32 KiB]
Downloaded 82 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: Trade at specific time by timer Post rating: 0   New post Posted: Thu 30 Jan, 2014, 16:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
month ==1 is February, see:
https://docs.oracle.com/javase/7/docs/api/constant-values.html#java.util.Calendar.FEBRUARY
the January would be 0.
Plus, instead of hard-coding the time-stamp, consider setting in the strategy parameters, see examples here:
https://www.dukascopy.com/wiki/#Strategy_parameters/Usage_of_date_and_time
And if you use a scheduler, why don't you schedule it to execute at a concrete time? See example here:
https://www.dukascopy.com/wiki/#Threading/Schedule_at_concrete_time


 

Jump to:  

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