JFUtil: An open-source JForex utilities library
JFUtil is a Quantisan.com open-source project focused on reusable JForex trading strategy components. Latest version is 2.1.3 released on April 8, 2011. Please keep your local JFUtil library up to date for the latest patches and features.
Main Features
1. Access to IContext and IAccount from anywhere in your project files.
The one and only JForexContext object in JFUtil is a thread-safe, singleton object which can be called from anywhere within your projects, across any class file. No need to declare global IContext variables. No need to pass it around in parameters.
2. Simplify order submission with ticket builder.
Set your trade order parameters with an order ticket object using a builder constructor. You can build ticket with as few or as many parameters as you like. All with intuitive method names in the same ticket class.
OrderTicket buySpTicket = new OrderTicket .Builder(label, instrument, IEngine.OrderCommand.BUY, 0.1) .setStopLossPrice(stopPrice) // set stop price to ticket .setTakeProfitPrice(targetPrice) // set target .build();
3. No more confusion about indicator methods.
Indicators are encapsulated into their own bean object with their full function name and parameters are set using intuitive, clearly described methods.
// get an EMA indicator value by building an indicator bean
MovingAverage maBean = IndicatorBeanFactory.getMovingAverage();
// then sets its parameters with obvious method names
maBean.setAppliedPrice(IIndicators.AppliedPrice.MEDIAN_PRICE)
.setMAType(IIndicators.MaType.EMA)
.setWidth(14); // all of these are optional parameters
// feed the bean into a generic calculation method to get the result
double ema = Indicating.calculate(instrument, Period.ONE_MIN, maBean);
4. Implicit multi-threading for ordering.
Ease your main thread’s workload for processing incoming data and avoid your order manager holding up the traffic. All automatically performed in the background without extra coding for you.
5. Built-in popular numerical functions for forex trading.
Calculate expected profit or loss in your account currency. Saves you from writing boilerplate codes and reinventing the wheel.
6. Continuous improvements!
JFUtil is continuously being improved based on feedback from traders like you. See the changelog below for major changes since the initial release in November 2010.
Example
To best illustrate how JFUtil can make your JForex programming life easier, see this JForex strategy source code example.
Download
Download the latest JFUtil library jar file including the javadoc for your own use (use the @Library annotation in your strategy) or fork the project at Github to participate in this open-source project to make programming trading strategies in JForex easier for everyone.
Feedback
Please report any issue or discuss your question or recommendation in the comments section below. Alternatively, you can contact me directly.
Major Releases:
v2.1.0 – March 22, 2011 – indicator bean, label maker
v2.0.0 – March 8, 2011 – singleton access to JForex objects, order ticket building, global currency conversion, global printer utility.
v1.0 – November 24, 2010 – JFUtil 1.0
Related posts:
10 Comments
Trackbacks/Pingbacks
- JForex Example: Not letting profit turn to losses with a breakeven stop | Quantisan.com - [...] This is now integrated into the JFUtil open source project. // [...]
- Making the best use of my time | Quantisan.com - [...] participating in two trading contests, developing an automated trading system with a team, managing an open-source project, actively trading, ...
- JFUtil 2.0 alpha demonstration | Quantisan.com - [...] the latest JFUtil from the project page. As this is an alpha release, I need your help in finding ...

Paul,
Have you done much with design patterns (I hope you have)? You want to write an open source set of utilities. It could be taken much further than that in creating a trading framework with concepts like pluggable entry,exit and filter strategies and pluggable trade management. Optimization lets you mix and match different entries and exits, filters and trade management. You’re also about to join (and/or/xor/not) entries/exits/filters/trademanagement if they are encapsulated in different objects. Are you interested in something like this?
Bill
Bill,
Unfortunately, no, I haven’t done much with design patterns. Indeed, I have much to learn in programming. I opened this project up so that better programmers, maybe such as yourself, can help make it better.
I am all ears. What do you propose?
It may be better if I send you some code so you’d understand.
Right now I use a Template Method (Design Pattern) to create the basic flow of how the IStrategy operates. It is an abstract class that contains an algorithm. Opening positions, reversing positions, closing positions … are all handled by the abstract class. The concrete class is written in JForex and it extends the abstract class. The concrete class is very minimal and effectively only handles things like @Configurable and general initialization.
The Abstract class delegates algorithmic calculations to objects rather than methods. For example, the concept of an Entry Condition can be encapsulated in an object. Your abstract class asks the entry condition (initialized in the concrete class or from a factory) if it should enter. Depending on which entry condition object you have initialized, you get the signal to buy, sell or do nothing and abstract class handles it.
So when you run a historical test in your optimizer, each “Pass” can handle a different entrance type. It also lets you run different time frames on your entry conditions vs your filter conditions vs your exit conditions. And test them all.
I’d appreciate if you can send some code to clarify please. My email is ‘paul’ at “this domain”.
I’m getting the concept but still have no clue on how it’s actually done. Like how do you delegate algo to objects rather than methods? And how does abstracting translate to pluggable components?
What you’re saying sounds very useful indeed. Thanks a lot for your help, Bill!
My focus at university was software design, specifically object oriented design. One of the most useful books out there is one called “Design Patterns: Elements of REusable Object-Oriented Software” by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.
It might be interesting if you really want to work on a framework. Ultimately, the design concepts mentioned before can lead to a “Strategy” that selects the entry conditions/exit conditions/trade management and filters based on market conditions and the instrument behavior. You use a “dispatcher” that will dispatch the proper object that handles what is needed.
I thought that this is just a matter of refactoring the project code. I doubt I can afford the time to figure out this framework if it requires a university course to teach.
Do you suppose you’ll have the time to fork this project and start to do what you’re suggesting? Or would this be somewhere entirely new that you’re proposing to start?
Don’t need a university course for sure. It is actually really simple concepts. I’m sure you’ll have no problem. I may have time, I’m not sure about forking… but I’ll just start writing my code so that it is a bit easier to understand.
“Design Patterns: Elements of REusable Object-Oriented Software†by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.
This book is really important for OOP (object oriented programming). You will find that most OOP programmers use these design patterns. If they are trained in a university, they will likely have read this book as it’s usually part of the required reading. If not taught (like me) you can’t help coming across code examples using these patterns.
I would encourage you to seriously consider getting familiar with this. It might seem a lot of work in the short term but will be save plenty of time in the long term.
cheers
Rob (pipware.com)
I have done something similar: creating a completely pluggable framework on top of JForex using OO, slotting and composite design patterns. To create new strategies you just instantiate a class, set variables, and off you go. I have even built up reporting and mixed in R. I am not sure how I feel about making my code public, but I am interested I’m collaborating in private on the framework or strategies. My day job is software engineering.
Thanks for all the feedbacks! I learned more about software design and design patterns in the last month through the Design Patterns and Effective Java books.
I can see what can be improved for this library now. Such as using the Builder pattern instead of telescoping constructors and making use of Singleton for IContext et al.
I’ll update the library the next time that I work on it. Don’t hold your breath for my update though, as this is at the bottom of my to-do list.
Update March 2011: JFUtil 2.0 is released with a new object oriented design.