fprophet's Blog

Avatar

Skipping Trading Breaks during Backtesting

Backtesting a Strategy for long periods of time (e.g. years) can be very time consuming.
You can speed things up during long backtesting runs by adding code to your Java Strategy that will skip over times when your selected Instrument's Market is Closed, like this:

public ITimeDomain curWeekend = null;
long time = bidBar.getTime();
if (engine.getType() == IEngine.Type.TEST) {
if (curWeekend == null) curWeekend = context.getDataService().getOfflineTimeDomain(instrument);
if (time >= curWeek
Lisez l'histoire complète
Traduire en Anglais Montrez l'original
oupour laisser des commentaires
Avatar

New York SESSION_HOURS and DAYLIGHT SAVING

If you want to know if the New York Session is currently open you have to take in account the time of year
as New York could be on Eastern Standard Time (EST) or Eastern Daylight Time (EDT).
We can easily do this in our Java code using the following constants
private static int USopen = 8, USclose = 17;
private static String UStimezone = "EST5EDT"; // New York SESSION_HOURS

and then in our onBar logic set up a Calendar to obtain the current time in the required timezone, as follows:
Cale
Lisez l'histoire complète
Traduire en Anglais Montrez l'original
oupour laisser des commentaires
Avatar

JFcontestFeb23 : Contest Strategy

This Strategy trades using the 5 Minute chart for instrument EUR/USD.
It is a scalper that looks for high probability short-term trades, with a small Takeprofit (5 pips) and a large Stoploss (40 pips).
Version 1 of this Strategy is very simple: it gets the RSI(14) and checks if it is over-bought (i.e. exceeds 70) or is over-sold (i.e. below 30).
If over-bought we expect the price to retrace, so we SELL, and if over-sold we BUY.
Trading is restricted to GMT 1000 start, 1600 finish.
%Equity t…
Lisez l'histoire complète
Traduire en Anglais Montrez l'original
oupour laisser des commentaires
Avatar

Identifying your Strategy Orders

When coding your Strategy in Java it is important to be able to identify the orders that your Strategy 'owns' (i.e. created & is managing) - and not get those mixed up with Orders on the same Account that were created manually or by any other Strategy that is running at the same time.
So when you want to Count your Filled (and/or Pending) orders, or Close your open positions, you may need to ensure they were created by the ‘owning’ Strategy.
I do this by always creating Orders with a Label tha…
Lisez l'histoire complète
Traduire en Anglais Montrez l'original
oupour laisser des commentaires
Avatar

Calculating Amount to Trade based on Risk

For currency pair 'instrument' I calculate OrderAmount to Trade with the following code, assuming I want to Risk 80% of my Equity (which is ok for the Strategy Contest):
@Configurable("%Equity to Risk") public double EQpcAmount = 80;
JFUtils utils = context.getUtils();
double EquityInUSD = history.getEquity()*utils.getRate(JFCurrency.getInstance(String.valueOf(context.getAccount().getCurrency())),JFCurrency.getInstance("USD"));
double OrderAmount = roundDecimals(EquityInUSD/1000000)*(EQpcAmo…
Lisez l'histoire complète
Traduire en Anglais Montrez l'original
oupour laisser des commentaires