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.

Function - One order in Bar (example on Period.FIFTEEN_MINS)
 Post subject: Function - One order in Bar (example on Period.FIFTEEN_MINS) Post rating: 0   New post Posted: Thu 11 Aug, 2011, 20:38 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
Hi eweryone!

In mql4 i realized this function (Function OneOrderInBar don`t allowing open new order in the Bar, where already order was opening and close)

//+--------------------------------------------------------------------------------------------------------------+
//| OneOrderInBar. Open one order in bar.
//| The new order can't be opened in the same bar where there was a order closing.
//+--------------------------------------------------------------------------------------------------------------+
bool OneOrderInBar(int OpType = -1){
//+--------------------------------------------------------------------------------------------------------------+
   
   int Bar = Period();
   
   for(int i = OrdersHistoryTotal(); i>=0; i--){
      //---
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
         //---
         if(OrderSymbol() == EASymbol && OrderType() == OpType && OrderMagicNumber() == MagicNumber) {
           
            if(OrderCloseTime()>iTime(EASymbol,Bar,0)) return(False);
            }
         }
      }

   //---
   return(True);
}


If in a current bar the order already opened and closed - don`t allowing open new order in the Bar.

How to realize this function in JForex?

Thanks for help!


 
 Post subject: Re: Function - One order in Bar (example on Period.FIFTEEN_M Post rating: 0   New post Posted: Fri 12 Aug, 2011, 09:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please, see orderClosedInLastBar method in this strategy.

package jforex.strategies;

import java.util.*;

import com.dukascopy.api.*;

public class OneOrderInBarStrategy implements IStrategy {
    private IEngine        engine;
    private IConsole       console;
    private IHistory       history;
    private IContext       context;
    private IIndicators    indicators;
    private IUserInterface userInterface;

    @Configurable("Instrument")
    public Instrument      selectedInstrument = Instrument.EURUSD;
    @Configurable("Period")
    public Period          selectedPeriod     = Period.TEN_SECS;  // bar duration

    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != selectedInstrument)
            return;
        console.getOut().println(orderClosedInLastBar());
    }

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

    public boolean orderClosedInLastBar() throws JFException {

        Calendar cal = Calendar.getInstance();
        long end = cal.getTimeInMillis();
        cal.add(Calendar.DATE, -1);
        long start = cal.getTimeInMillis();

        // get orders for the last day
        // only orders from selected instrument are fetched
        List<IOrder> orders = history.getOrdersHistory(selectedInstrument, start, end);

        // fetches current bid bar from history
        IBar lastBidBar = history.getBar(selectedInstrument, selectedPeriod, OfferSide.BID, 0);
        for (IOrder order : orders) {
            // check whether there is an order that has been closed during the
            // current bid bar
            if (lastBidBar.getTime() <= order.getCloseTime()) {
                return true;
            }
        }

        return false;
    }
}


 
 Post subject: Re: Function - One order in Bar (example on Period.FIFTEEN_M Post rating: 0   New post Posted: Sat 13 Aug, 2011, 00:27 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
thank you very much Api Support. You are realy help me with studying JForex EA language.

Whether prompt there is at a forum or still where that a library of functions for JForex Api, on similarity of those that you resulted earlier.


 

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