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.

Configurable Time value
 Post subject: Configurable Time value Post rating: 1   Post Posted: Sun 06 May, 2012, 22:13 

User rating: 1
Joined: Fri 04 May, 2012, 21:03
Posts: 5
Hi, I'm new in this forum.
I want create a configurable time parameter to use in my test strategy like this:

@Configurable("Time to insert")
    public Time  _time= new Time( date.getTime());


and use to

if(tick.getTime()>=_time.getTime()){
  engine.submitOrder("Now!!");
}


If I run Historical test without change default value for the parameter, test run, but if I change the default value don't run!

What is wrong?

Thank's


 
 Post subject: Re: Configurable Time value Post rating: 0   Post Posted: Wed 09 May, 2012, 07:20 

User rating: 1
Joined: Fri 04 May, 2012, 21:03
Posts: 5
Hi, support!

Please can you help me with this trouble? It's really important for my study resolve it

Thank's so much


 
 Post subject: Re: Configurable Time value Post rating: 0   Post Posted: Thu 10 May, 2012, 15:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following code
package jforex.strategies;

import java.text.SimpleDateFormat;

import com.dukascopy.api.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Strategy1 implements IStrategy {

    private IConsole console;
    private IHistory history;

    @Configurable("time")
    public Calendar time = new GregorianCalendar();
   
   
    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        this.history = context.getHistory();
       
//        // this code sets time variable to 12:30 GMT, tomorrow
//        time = new GregorianCalendar();
//        time.setTimeZone(TimeZone.getTimeZone("GMT")); // time zone GMT
//       
//        time.setTimeInMillis(history.getLastTick(Instrument.EURUSD).getTime()); // set time to last tick
//       
//        time.add(Calendar.DATE, 1); // add one day to the time
//       
//        time.set(Calendar.HOUR_OF_DAY, 12); // set hours
//        time.set(Calendar.MINUTE, 30);      // set minutes
//       
//        console.getOut().println(toStr(time.getTimeInMillis()));
       
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != Instrument.EURUSD) {
            return;
        }
       
        if(time != null && time.getTimeInMillis() <= tick.getTime()) {
            console.getOut().println("Time is now " + toStr(time.getTimeInMillis()) + " " + toStr(tick.getTime()) );
        }       
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }
   
    public String toStr(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {
            {
                setTimeZone(TimeZone.getTimeZone("GMT"));
            }
        };
        return sdf.format(time);
    }
}


Attachments:
Strategy1.java [2.04 KiB]
Downloaded 281 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-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