Hi chaps,
I'm very new to Java, and I'm struggling to get together a pretty basic routine to place a single order once per day.
Basically, I want the following:
EUR/USD only
ontick
check current time
is time 8am (london open)
if time is 8am, then place buy and sell orders with good till time of 8 hours
if an order is filled, delete the opposite order
however im unable to narrow down the time check to 8:00am, I am having to check is the time between 8:00am and 8:01am which is resulting a load of orders being placed between that 1 minute.
I got around that buy putting a boolean "has_order_been_placed" to true after the order has been placed, but I'm struggling to find a way to find a trigger to reset this to false when the order is closed?
So far I have something like this:
public void onTick(Instrument instrument, ITick tick) throws JFException {
// boolean all_orders_closed = false;
int total_closed_orders = closed_orders_total(instrument);
console.getOut().println("closed ORDERS = " + last_closed_orders);
if (total_closed_orders > last_closed_orders){
active_orders = false;
// reset to new val
last_closed_orders = total_closed_orders;
}
// long current_bar_time = askBar.getTime();
// List<IOrder> current_orders = engine.getOrders();
// foreach loop to check if last order was closed
// If there are no active orders then proceed.
if (positionsTotal(instrument) == 0){
// Is it the correct time to trade (8 in the morning)
boolean is_time_to_trade = is_valid_time(8,0,8,1);
// console.getOut().println("is it time to trade??? = " + is_time_to_trade);
if (is_time_to_trade && active_orders == false){
double current_tick_value = tick.getAsk();
long current_tick_time = tick.getTime();
// Place a London order
console.getOut().println("PLACING A TRADE OK!!!");
// set active orders flag to true
active_orders = true;
place_order(current_tick_value, current_tick_time, ln_order_time_period);
}
}
protected int closed_orders_total(Instrument instrument) throws JFException {
int counter = 0;
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.CLOSED) {
counter++;
}
}
return counter;
}
Cheers for any help!
Regards,
Jon.