Posts in category AIOTrade

Progress of Migrating AIOTrade to Scala #2

My next step is to push AIOTrade to another level of UE, with hotkey for symbols, indicators etc, with better UI.

So far, my Scala adventure went almost smoothly, I'm thinking about the data exchange between client and data source, maybe the actors from  Scala,  LiftWeb or  AKKA will bring some fresh atmosphere.



Progress of Migrating AIOTrade to Scala

Well, I've done most parts of migrating AIOTrade to Scala, not all features return yet. I gain lots of experiences of inter-op between Scala and Java, since AIOTrade has to be integrated into an existed Java framework  NetBeans Platform. And also, whole project is now managed by Maven instead of Ant, which reduces lots of pain of dependencies upon crossing sub-projects.

This project is now hosted on, you can check out the code to get an overview of how to integrated Maven + Scala + NetBeans Modules. Of course, all were done with NetBeans Scala plugin.

LOC of this project so far:

$ ./ --read-lang-def=lang_defs.txt ~/myprjs/
     677 text files.
     617 unique files.                                          
     154 files ignored. v 1.08  T=3.0 s (167.7 files/s, 21373.7 lines/s)
Language          files     blank   comment      code    scale   3rd gen. equiv
Scala               353      7981     16301     27180 x   1.36 =       36964.80
Java                 43      1148       833      6946 x   1.36 =        9446.56
XML                 104       231       389      2414 x   1.90 =        4586.60
Bourne Shell          2        81        81       488 x   3.81 =        1859.28
HTML                  1         7        15        26 x   1.90 =          49.40
SUM:                503      9448     17619     37054 x   1.43 =       52906.64

A screen snapshot:


Notice for Host Migration of This Site

I'm going to migrate this web site to new host during this month, both and may not be available at any time during this period.

AIOTrade, Scala for NetBeans, NLP

For past years, I worked on AIOTrade project, which uses Machine Learning technology to find the structural data pattern.

Then, to find a better programming language for AIOTrade, I tried Erlang, Scala, and wrote IDEs for these candidate languages, I learnt a lot of Formal Language Processing.

Now, finally, I dove into Natural Language Processing, and have a good chance to composite the knowledge of Statistics Learning, Rule based Language Processing on massive structural/un-structural data under parallel computing environment.

The candidate programming language is Scala, I keep to improve the NetBeans support for Scala these days while reading the books/code of NLP. During the long weekend, I've got some improvements on it, here is a summary:

  • Migrated to NetBeans' CSL
  • Use fsc instead of scalac as the project building compiler
  • Fixed setting breakpoint in closure statement
  • A basic import-fixer
  • Code assistant for local vars and functions
  • Run/Debug single file

The plugins can be got for beta testing on NetBeans Developing Update Center (for NetBeans 6.7 beta+), and will be released around the date of official NetBeans 6.7.

AIOTrade: Progress of Migrating to Scala - DSL and Parallel Computing

Well, I've migrated the core math, indicator parts of AIOTrade to Scala. There are two noticeable advances for new AIOTrade.

The first is the look and feel of indicator writing. Since Scala is suitable for DSL, now the indicator looks like:

class ARBRIndicator extends ContIndicator {
    _sname = "AR/BR"
    _grids = Array(50f, 200f)
    val period = Factor("Period", 10)
    val up = Var[Float]("up")
    val dn = Var[Float]("dn")
    val bs = Var[Float]("bs")
    val ss = Var[Float]("ss")
    val ar = Var[Float]("AR", Plot.Line)
    val br = Var[Float]("BR", Plot.Line)
    def computeCont(begIdx:Int, size:Int) {
        for (i <- begIdx until size) {
            up(i) = H(i) - O(i)
            val up_sum_i = sum(i, up, period)
            dn(i) = O(i) - L(i)
            val dn_sum_i = sum(i, dn, period)
            ar(i) = up_sum_i / dn_sum_i * 100
            val bs_tmp = H(i) - C(i)
            bs(i) = Math.max(0, bs_tmp)
            val bs_sum_i = sum(i, bs, period)
            val ss_tmp = C(i) - L(i)
            ss(i) = Math.max(0, ss_tmp)
            val ss_sum_i = sum(i, ss, period)
            br(i) = bs_sum_i / ss_sum_i * 100

Vs Java one:

public class ARBRIndicator extends ContIndicator {
    _sname = "AR/BR";
    _grids = new Float[] {50f, 200f};
    Opt period = new DefaultOpt("Period", 10);
    Var<Float> up = new DefaultVar("up");
    Var<Float> dn = new DefaultVar("dn");
    Var<Float> bs = new DefaultVar("bs");
    Var<Float> ss = new DefaultVar("ss");
    Var<Float> ar = new DefaultVar("AR", Plot.Line);
    Var<Float> br = new DefaultVar("BR", Plot.Line);
    void computeCont(int begIdx) {
        for (int i = begIdx; i < _itemSize; i++) {
            up.set(i, H.get(i) - O.get(i));
            float up_sum_i = sum(i, up, period);
            dn.set(i, O.get(i) - L.get(i));
            float dn_sum_i = sum(i, dn, period);
            ar.set(i, up_sum_i / dn_sum_i * 100);
            float bs_tmp = H.get(i) - C.get(i);
            bs.set(i, Math.max(0, bs_tmp));
            float bs_sum_i = sum(i, bs, period);
            float ss_tmp = C.get(i) - L.get(i);
            ss.set(i, Math.max(0, ss_tmp));
            float ss_sum_i = sum(i, ss, period);
            br.set(i, bs_sum_i / ss_sum_i * 100);

The apply method from Scala simplifies setter/getter, which makes the formulator looks more natural.

The second is by implementing each indicator as Actor, the computing procedure of indicators can be easily distributed to multiple CPU cores, with so few code modification:

case object Compute
trait Computable extends Actor {

    // ----- actor's implementation
    def act = loop {
        react {
            case (Compute, fromTime:Long) => computeFrom(fromTime)
            case _ =>
    // ----- end of actor's implementation

    def computeFrom(time:Long) :Unit
    def computedTime :Long
    def factors :ArrayBuffer[Factor]
    def factors_=(factors:ArrayBuffer[Factor]) :Unit
    def factors_=(values:Array[Number]) :Unit
    def dispose :Unit

Computable is an Interface/Trait with sync method: computeFrom(Long), now by extending Computable with Actor, implementing a simple function act with react message processing block, all indicators (which extended Computable) can benefit from parallel computing now by calling:

indicator ! (Compute, fromTime)

instead of


I've done some testing on my 4-core machine, which occupied about 380% CPU usage during running. This is, of course, a most easily implementation for parallel computing under JVM so far.

Another bonus is, I do not need to worry about concurrent calling on computeFrom(Long) now, since all calls will be triggered by Compute messages that are sent to actor's message queue, then be processed sequentially, there is no lock needed any more. The key:

Parallel computing actors + Sequential message driven computing per actor

AIOTrade Is Migrating to Scala

Finally, after evaluated Erlang, Scala etc, wrote IDE tools for these languages, I began to migrate AIOTrade from Java to Scala, with the help of Scala for NetBeans of course.

The first step is re-writting basic modules to Scala smoothly, with little functional style code; Then, I'll re-design the APIs by Scala's advanced features, including function, trait, actors etc.

Since AIOTrade is a NetBeans suite project, with several NetBeans style modules integrated, I need a general purpose build.xml to get Scala based modules working. Here are build.xml and scala-build.xml, which can be used to write Scala based NetBeans platform modules.

First, you should create a regular NetBeans module project, then put/replace these ant files under your project's base director. You also need to create 2 NetBeans lib wrapper modules, one is for scala-library.jar, another is for scala-compile.jar as parts of your NetBeans suite project (or, check them out from AIOTrade's source repository)


<?xml version="1.0" encoding="UTF-8"?>
<project name="lib.math" default="netbeans" basedir=".">
    <import file="scala-build.xml"/>


<?xml version="1.0" encoding="UTF-8"?>
<project name="scala-module" default="netbeans" basedir=".">
    <import file="nbproject/build-impl.xml"/>

    <target name="scala-taskdef" depends="init">
        <property name="scala.library" value="${cluster}/modules/ext/scala-library.jar"/>
        <property name="scala.compiler" value="${cluster}/modules/ext/scala-compiler.jar"/>
        <property name="scala.libs" value="${scala.library}:${scala.compiler}"/>

        <echo message="cluster: ${cluster}"/>
        <echo message="Compiling scala sources via ${scala.library}, ${scala.compiler}"/>

        <taskdef resource="scala/tools/ant/antlib.xml">
                <pathelement location="${cluster}/modules/ext/scala-library.jar"/>
                <pathelement location="${cluster}/modules/ext/scala-compiler.jar"/>

    <property name="jar-excludes" value="**/*.java,**/*.form,**/package.html,**/doc-files/,**/*.scala"/>

    <target name="compile" depends="init,up-to-date,scala-taskdef" unless="is.jar.uptodate">
        <!-- javac's classpath should include scala.library and all these paths of "cp" -->
        <path id="javac.cp">
            <pathelement path="${scala.libs}"/>
            <pathelement path="${module.classpath}"/>
            <pathelement path="${cp.extra}"/>
        <!-- scalac will check class dependencies deeply, so we can not rely on public package only which is refed by ${module.classpath} -->
        <path id="scalac.cp">
            <pathelement path="${scala.libs}"/>
            <pathelement path="${}"/>
            <pathelement path="${cp.extra}"/>
        <mkdir dir="${build.classes.dir}"/>
        <depend srcdir="${src.dir}" destdir="${build.classes.dir}" cache="build/depcache">
            <classpath refid="scalac.cp"/>
        <!-- scalac -->
        <scalac srcdir="${src.dir}" destdir="${build.classes.dir}" encoding="UTF-8" target="jvm-${}">
            <classpath refid="scalac.cp"/>
        <!-- javac -->
        <nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"
                deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${}" includeantruntime="false">
            <classpath refid="javac.cp"/>
            <compilerarg line="${javac.compilerargs}"/>
            <processorpath refid="processor.cp"/>
        <!-- Sanity check: -->
        <pathconvert pathsep=":" property="">
                <fileset dir="${src.dir}">
                    <include name="**/*.class"/>
                    <equals arg1="${}" arg2=""/>
            You have stray *.class files in ${src.dir} which you must remove.
            Probably you failed to clean your sources before updating them.
        <!-- OK, continue: -->
        <copy todir="${build.classes.dir}">
            <fileset dir="${src.dir}" excludes="${jar-excludes}"/>

    <target name="do-test-build" depends="">
        <scalac srcdir="${test.unit.src.dir}" destdir="${build.test.unit.classes.dir}" excludes="${test.excludes}"
            <classpath refid="test.unit.cp"/>

BTW, the new source code of AIOTrade is controlled under Mercurial version control system on, you can clone or brows the code at: AIOTrade source repository

Note: The whole project can not be successfully built yet.

AIOTrade Applet Demo Fixed Timezone Issue

I fixed AIOTrade timezone issue. And, the applet demo on does not need to be a signed applet any more.

For recent experience, I'm re-considering the RIA platform choice. May applet be saved in the near future? or Flash, Javascript win? First, Java applet needs a whole new look and feel theme, which make it fitting into the web page, second, how can a Java applet access DOM tree easily?


When Flash/Flex tries to take the place of Java applet, it will become another Java itself.

New Face of with AIOTrade Applet Demo

I've done some preliminary re-design on, put the AIOTrade applet on home page, it requires browser with Java plugin above JRE 1.5, the size is about 288k. You can input the symbol to get real-time quote charting. Symbol is same as Yahoo! finance. The quote data is also from Yahoo! finance.

There are still some bugs on it. I'll continue to improve it.

Here's the snapshot of whole home page after you input a symbol. You can remove the chart by press "Remove Quotes" button.


AIOTrade - It's not Flash or A Picture It's A Java Applet on Web Page

For RIA framework, there are choices of Flex/Flash, Applet/JavaFX etc. I saw a lot of real-time financial charts were written in Flex/Flash, all over the world wide web. Then, how about a Java applet financial charting after Java 6u10? I'd like a try, and here is the result:

  • The whole size of a most featured AIOTrade is less than 300k
  • On my Macbook, with Java 6u12 installed, the init time is about 1 sec.
  • By properly arranging Swing layout, the applet can auto-scale to proper size fit in html page just like any element.

Below is a snapshot:


The Year That Will Be

It's 2009 now, in Beijing.


I met Erlang 2 years ago, which finally brings me to Scala. I learnt a lot from Erlang, and I entered the Scala world with Erlang atmosphere surrounding me. The FP, the Pattern Match, the Actor/Process, I found these familiar friends in Scala everywhere.

Scala has extra bonus, to me, static types and OO/FP. The domains I face are usually with a lot of business logic, or, the worlds I try to describe are not only messages, they are, models I don't think are suitable to describe in Function only.

The world itself is OO/FP mixed, like Martin's quote: Two sides of coin. It's something like the Particle/Wave in Quantum. The world is an infinite whole, but the reason of Human Being is always finite, we are using out finite reason to measure the infinite world, it's an unsolvable contradiction: Infinity vs Finite. We have to read our world in OO and, in FP, in snapshot and in continuation.

There won't be "Super Hero" in computer languages, the world is getting self-organization and harmony, so do the languages. Each language is living in an eco-system, born, growing via interacting with environment, disappear ...

The Economy

It was bad in 2008. I tried to do some computing on stock market based on my neural network. What I can say is it will be swing in the next half-year, no big drop, no big rise. The Shanghai Stock Index will swing between 1200 and 3000. At least, no big worse any more.

My Self

I need to make some big decisions in this a year.

Vacation for Snowboarding

I'll take my vacation for snowboarding, 3-4 days. Happy Chinese New Year!

AIOTrade Is Open for Submissions

Here's the announcement from Moshe at the AIOTrade project page on

Lately I was added by as a developer in the project and I created a branch called "opencommunity". This branch should contain a development version that is built by contribution of the community in order to answer better the needs of a trader.

Any contribution, any code, designs, ideas, bug fixes, etc., should be send to me and I'll integrate it (the contributers will be credited, of course)

I can be contacted through the forum of the AIOTrade project or directly through aiotrade -d0t- submit -at- gmail -d0t- com or by using the secure client at


Good works! Moshe

AIOTrade Goes to BSD License Again

Updated June 21: I've updated the source code in trunk to BSD License.

I decide to re-open AIOTrade, an open-source, free stock technical analysis and charting platform based on NetBeans to BSD license. And welcome the new developer Moshe who will maintain a community branch.

As I'm working hard for my friends project, I have no much time to go with this project in the near future, so, more community members will be helpful for this project.

I'll update the source tree in trunk to BSD license in one week.

I have now a brand new Macbook in white, with 2G memory and Parallels+Windows XP installed, so I can make sure AIOTrade and ErlyBird being Mac OS friendly.

AIOTrade: Yahoo! data module updated

Due to the recent date format change in the Yahoo! historical data, I've updated the relative module: org-aiotrade-platform-modules-dataserver-basic.nbm

And also updated module: org-aiotrade-math.nbm to fix the bug mentioned at: Solution for bug: wrong date shown

To update your installed Aiotrade 1.0.3:

1.From menu: Tools -> Update Center
2.In the "Select Location of Modules" pane, click "Install Manually Downloaded Modules(.nbm Files)", then "Next"
3.Click [Add...] button, go to the path to select these two .nbm files that you downloaded. (Press Ctrl key down and click on file name to select multiple files)
4.Following the instructions to install updated modules.
5.Restart Aiotrade.

!Notice, you may need to delete all aiotrade log files, which are located at:
For Windows user:
C:\Documents and Settings\yourusername\Application Data\.aiotrade\1.0.3\var\log\
For Mac user:
${HOME}/Library/Application Support/aiotrade/1.0.3/var/log/

This is a quick fix, the final solution will be included in next release.

Split the Server Part and Client Part? - Next Generation AIOTrade

I'm thinking to re-design the AIOTrade by splitting it to Server part and Client part. The server part may also run as a standalone web application.

But, I'm also busy on another project, so, the prototype and coding work will be postponed.

The Design of AIOTrade (Part I)

There are no design documents of AIOTrade released so far, it's because I'm still not satisfied the code and architecture, anyway, I'll try to post some draft overall views of the design in my blog.

Below is a digram of main classes [updated: Dec 10, 2006]:

Click on the picture to enlarge it

main classes

Solution for Bug: wrong date shown

There is a bug affects those who's time zone is not UTC:

For each stock, AIOTrade shows the data of the day after. For example, the data of Friday November the 24th is shown in the application at Friday November the 23th.

This bug will be fixed in next release, by far, you can try to add a a property in aiotrade's config file, which is located at:

change the line:

default_options="-J-Xms24m -J-Xmx128m --fontsize 11"


default_options="-J-Xms24m -J-Xmx128m --fontsize 11 -J-Duser.timezone=UTC"

Sorry about the inconvenience.

AIOTrade 1.0.3 Released

I'm pleased to announce the 1.0.3 release of AIOTrade. You may download it via

The new features had been listed in my previous blog

Thanks for all the suggestions, bugs reports and feature requests. Thanks for msayag's bugs hunt.

Bug reports, especially for the experimental IB-TWS data feed are welcome.

What's new in coming AIOTrade release

After one and half month developing, the next release of AIOTrade is on the road. Here is the new features and improvements in the coming release:

  • Charting performance was improved a lot.
  • Added an integrated scrolling, zooming controller. Zoom out/in by dragging the thumb side to any scope you want.
  • Added an icon beside the symbol, indicating the data source, such as from Yahoo!/CSV etc.
  • When you switch to different frequency charting , only the indicators and drawings with the same frequency displayed under the symbol node.
  • The symbols under watching will have its real-time charts displayed on a scrolling window. Double click on its title will pop up a standalone window.
  • Some times, too many indicators are displayed in chart view, you can double-click on indicator's title to pop up a standalone indicator window for detailed analysis. There will be a scrolling controller attached in this window, and shares the same cursor with the main chart view.
  • An experimental IB-TWS data feed interface. As I can only test it on demo environment, this feature is just to be released for wide range testing, I'm even not sure if it really works:-), so please feed me back all the issues, I'll fix them and release an official version as soon as possible.
  • Save chart to custom time frame image, even bigger than your screen.

And another important question: Where are the AI features? Sorry, as I have no much time, although I'll keep my own research, the open-source AI features will be pended. Until ... I don't know.

The scheduled release date is around Nov 19.

Click on the picture to enlarge it

A big chart of DJI from Jan 2000 till now: big dji

new features

Way To Going

Recently I got some messages that worried about the way to go for AIOTrade project, as eneratom posted in forum. Good question, as I am also thinking about it.

Although the initial motivation for this project is building a platform for myself research on AI on trading, I finally find I've gone a bit far from it, it's now a platform with potential to be All In On trading platform.

I were busy on my own affairs in the passed months, such as moving, looking for job (maintaining an open-source project is a bit hard) etc. When I come back to this project these days, I find I'm still with passion on it. So the svn trunk is being filled with a lot of new committed works which will bring the architecture to a much more beauty and clean: such as a more powerful custom scrollbar to control scrolling/zooming all in one with auto-hide ability, a XOR mouse cursor with better performance etc.

The answer for me now is clear: it will be an All In One Trading platform with AI features.

Let me try to give a road map for the near future:

  • The next release will be with a lot of fine tuning on performance and a neural network module.
  • The next next release will support mins data loading and more data feeds
  • The next, will implement back-testing features.
  • Then, an interface for placing orders to brokers
  • ...

For the contributions, I'm very appreciate for the suggestions, but as I mentioned before, there will not be more developers until the APIs are stable enough, and all the license issues have been considered carefully.

The patches and bug reports are always welcome though.

AIOTrade - New Name for BlogTrader Platform

BlogTrader Platform (i.e HumaiTrader) has got an official name as AIOTrade now, which means Artificial Intelligence On Trade, or, All In One Trade. And it will be a fairly large project to be developed.

Did I mentioned this project is one-year old now? and more than 10,000 copies (binary and source) was downloaded.

I've re-packed the source tree, and will release the code in name of AIOTrade soon, with a primary Neural Network module.

It's brought to you by AIOTrade Computing Co.

And the new web site:
is coming soon.

Support Vector Machine for BlogTrader Platform

I've got the Support Vector Machine (SVM) running on BlogTrader Platform. The results are more stable than MLP and I'm still being familar with the C and sigma parameters of SVR.

SVM is a good tool that based on Kernel and Statistical Learning theory, and it can reach the globle minima, with only few parameters needed to be adjusted which may be easily applied GA.

For those who are interesting in machine learning, there are several good books are recommented:

Statistical Learning Theory [Vladimir N. Vapnik]

An intruduction to Support Vector Machines and Other Kernel-based Learning Methods [Nello Cristianini, John Shawe-Taylor]

Kernel Methods for Pattern Analysis [John Shawe-Taley, Nello Cristianini]

Prediction on Another Stock Index by Neural Network

This time, let's try to apply the neural network on Shanghai Stock Exchange Index(000001.SS on Yahoo! Finance). The network has 2 hidden layers, the 1st one has 5 nodes, the 2nd one has 2 nodes. Output layer has 1 node.

After 5000 epoches training with 2400 sample data, the result is showing below.

It seems the pattern of chart is better than the turning time. Particularly, the backward generalization gets a very interesting result.

When I do the prediction, I do not use the price in the prediction period to adjust the network or as input any more. That is, I only use the price data in the training period to recognize the pattern, then apply the pattern backward or forward directly. So the prediction is fairly a long term prediction.

Click on the picture to enlarge it


A More Interesting Prediction of Stock Price by Neural Network

After more tuning work on my very primary neural network to predict the Price of stock market, I got some interesting result on ^HSI. 3600 sample data were used to train the network this time, from Mar 9, 2005, backward 3600 days. Generalization was applied forward from Mar 10, 2005 to Aug 23, 2006.

It's a simple MLP network with 3-layers, the hidden layer has 10 nodes, and 1 node for output layer.

Here's the result:

Click on the picture to enlarge it


And the zoom-in view, the result is also applied to the future (From Mar 10, 2005 to Aug 23, 2006 on this picture)


Another Attempt to Predict Stock's Price by Neural Network

This is the 2nd version of my very primary neural network to predict the Price of stock market on BlogTrader Platform. 800 sample data were used to train the network, and generalization was applied forward and backward.

Here's the result:

Click on the picture to enlarge it


A Very Primary Prediction of Stock's Trends by Neural Network

I've designed the 1st version of my very primary neural network to predict the Trends and Turns (not the Price) of Stock market on BlogTrader Platform. 400 sample data were used to train the network, and generalization was applied forward and backward.

Here's predicted result(very primary):

Click on the picture to enlarge it


Trying of Neural Network for BlogTrader Platform

I'm writing the Neural Network module for BlogTrader Platform. The first implementation is a Multi-Layer Perceptron. I'm glad that the MLP is going to compute something out for me today.

Training a neural network is a really tricky work, it seems we need a lot of interaction with the results and parameters.

A typical training with 200 training data, 3-10-1 topological MLP network runs about 4 minutes for 5000 epochs at this time. I do not apply any performance optimizing on it till now.

Primary support for Buy/Sell Signals in BlogTrader Platform

The primary support for Buy/Sell signals has been implemented in BlogTrader Platform, inculding SignalChart, SignalIndictor etc.The signal indicators will be put in a separate module: "BlogTrader Platform Modules Basic Signal"

Below is a screenshot of signals generated by MACD's slow line cross fast line. The blue arrows indicate the signals:

custom ndicator

The sample code:

public class MACDSignal extends AbstractSignalIndicator {
    Opt periodFast   = new DefaultOpt("Period EMA Fast", 12.0);
    Opt periodSlow   = new DefaultOpt("Period EMA Slow", 26.0);
    Opt periodSignal = new DefaultOpt("Period Signal",    9.0);
    Var fast = new DefaultVar();
    Var slow = new DefaultVar();

        _sname = "MACD Signal";
        _lname = "Moving Average Convergence/Divergence Signal";
    void computeCont(int begIdx) {
        for (int idx = begIdx; idx < _dataSize; idx++) {

            fast.set(idx, macd(idx, C, periodSlow, periodFast));
            slow.set(idx, ema(idx, fast, periodSignal));
            if (crossOver(idx, fast, slow)) {
                signal(idx, Sign.EnterLong);
            if (crossUnder(idx, fast, slow)) {
                signal(idx, Sign.ExitLong);


Design of Function of Technical Analysis (Part I)

As the basic atom for indicator computation, the function design for TA should consider:

  • It can be computed at any idx or time point, whenever -- computeSpot(int idx) or computeSpot(long time)
  • It can correspond to the Options change (Options are transfered in by the caller as reference)
  • It can remember the intermedial status of function instance to avoid redundant computation. The status includes
    • backward values (as it's a TimeSeries's variable)
    • the based Variables
    • the Options
    • the caller

Then an indicator instance can call it to:

  • compute from 'begIdx' to 'endIdx'
  • compute at point 'idx'
We can define an indicator's computing procedure as a computing session by provide a sessionId to it. The sessionId will also be the representer of function instance's caller mentioned above.

Supported TA Functions Currently

Below are the TA functions that have been implemented. The corresponding indicators were re-written based on these functions too.

More functions will be listed here as they are implemented.

float max(int idx, Var var, Opt period)
float min(int idx, Var var, Opt period)
float sum(int idx, Var var, Opt period)
float ma(int idx, Var var, Opt period)
float ema(int idx, Var var, Opt period)
float stdDev(int idx, Var var, Opt period)
float tr(int idx)
float dmPlus(int idx)
float dmMinus(int idx)
float diPlus(int idx, Opt period)
float diMinus(int idx, Opt period)
float dx(int idx, Opt period)
float adx(int idx, Opt periodDi, Opt periodAdx)
float adxr(int idx, Opt periodDi, Opt periodAdx)
float bollUpper(int idx, Var var, Opt period, Opt alpha)
float bollLower(int idx, Var var, Opt period, Opt alpha) 
float bollMiddle(int idx, Var var, Opt period, Opt alpha) 
float cci(int idx, Opt period, Opt alpha)
float macd(int idx, Var var, Opt periodSlow, Opt periodFast)
float mfi(int idx, Opt period)
float mtm(int idx, Var var, Opt period)
float obv(int idx)
float roc(int idx, Var var, Opt period)
float rsi(int idx, Opt period)
float sar(int idx, Opt initial, Opt step, Opt maximum)
Direction sarDirection(int idx, Opt initial, Opt step, Opt maximum)
float stochK(int idx, Opt period, Opt periodK)
float stochD(int idx, Opt period, Opt periodK, Opt periodD)
float stochJ(int idx, Opt period, Opt periodK, Opt periodD)
float wms(int idx, Opt period)
float[][] probMass(int idx, Var var, Opt period, Opt nInterval)
float[][] probMass(int idx, Var var, Var weight, Opt period, Opt nInterval)
boolean crossOver(int idx, Var var1, Var var2)
boolean crossOver(int idx, Var var, float value)
boolean crossUnder(int idx, Var var1, Var var2)
boolean crossUnder(int idx, Var var, float value)
boolean turnUp(int idx, Var var)
boolean turnDown(int idx, Var var)
signal(int idx, Sign sign, String name)
signal(int idx, Sign sign)
enum Sign {

Switch to GPL

BlogTrader Platform has switched to GPL license.

The source code that have been released under BSD will be moved to a special tag on SVN, the trunk will be the newer GPLed source tree.

This project won't accept new developers until all the license policy is clearly defined.
(See discuss in Switch to GPL license?)

Patchs and bugs report are welcome.

Do we need two forms for each TA function?

There are 2 forms could be defined for each TA function, such as:</p>

1. Var emaVar(Var var, Opt period)
2. float ema(int idx, Var var, Opt period)

The first one will return a series of variable which have been calculated;<br /> The second one just return one value in the series that is exactly at point idx.

Now, let's apply the two forms to the MACD indicator:

public class MACDIndicator extends AbstractContIndicator {

    Opt periodS = new DefaultOpt("Period Short", 12.0);
    Opt periodL = new DefaultOpt("Period Long",  26.0);
    Opt periodD = new DefaultOpt("Period Diff",  9.0 );
    Var<Float> dif, dea, macd, ema1, ema2;
    protected void go() {
        dif = new DefaultVar("DIF",  Chart.LINE);

        // here, the emaVar may be wrongly used, because the dif 
        // should be pre-calculated. 
        dea = emaVar(dif, periodD);
        macd = new DefaultVar("MACD", Chart.STICK);

        ema1 = emaVar(C, periodS);
        ema2 = emaVar(C, periodL);
    protected void computeCont(int begIdx) {
        for (int i = begIdx; i < _dataSize; i++) {
            dif.set(i, ema1.get(i) - ema2.get(i));

            macd.set(i, dif.get(i) - dea.get(i));

In the MACD example, there came out calculating dependency order issue if we apply 1st form function no properly. That is, the 'dea' actually should be calculated after the 'dif'. And it's difficult to insert the emaVar() into the proper place (should be in the 'for' clause, exactly after the point 'i' of 'dif' is calculated), because emaVar() is not aware of 'i'

To avoid these confusion, we should only provide the second function:

float ema(int idx, Var var, Opt period)

and force the developer to write the code as:

public class MACDIndicator extends AbstractContIndicator {
    Opt periodS = new DefaultOpt("Period Short", 12.0);
    Opt periodL = new DefaultOpt("Period Long",  26.0);
    Opt periodD = new DefaultOpt("Period Diff",  9.0 );
    Var<Float> dif, dea, macd, ema1, ema2;
        _sname = "MACD";
        _lname = "Moving Average Convergence/Divergence";

        ema1 = new DefaultVar();
        ema2 = new DefaultVar();
        dif  = new DefaultVar("DIF", Chart.LINE);
        dea  = new DefaultVar("DEA", Chart.LINE);
        macd = new DefaultVar("MACD", Chart.STICK);
    protected void computeCont(int begIdx) {
        for (int i = begIdx; i < _dataSize; i++) {
            ema1.set(i, ema(i, C, periodS));
            ema2.set(i, ema(i, C, periodL));
            dif.set(i, ema1.get(i) - ema2.get(i));
            dea.set(i, ema(i, dif, periodD));
            macd.set(i, dif.get(i) - dea.get(i));


This version makes the calculating dependency order clearly, no more confusion.</p>

Switch to GPL license?

I'm thinking to switch the license of BlogTrader Platform from BSD to GPL.

Making the license under GPL will encourage the contributors (include me) to release more source code to public, and means compatible to GPLed softwares that may be integrated into this project, such as: Sleepycat's Berkeley DB.

Of course, the source code that had been released will remain under BSD license, but I will not update it any more.

An interesting face of BlogTrader Platform

I applied the napkin look and feel on BlogTrader Platform, here's what it looks like:</p>


The first custom indicator lives in BlogTrader Platform

Here's the screenshot shows the first custom indicator lives in the coming BlogTrader? Platform which is scheduled at mid of May.


Programming language for custom indicator?

I tried to write the MA indicator in javascript, here's what it looks:

this._sname = "MA";
this._lname = "Moving Average";
this._overlapping = true;
var period1 = new P("Period 1", 5.0 );
var period2 = new P("Period 2", 10.0);
var period3 = new P("Period 3", 20.0);
var ma1 = new Var("ma1", Chart.LINE);
var ma2 = new Var("ma2", Chart.LINE);
var ma3 = new Var("ma3", Chart.LINE);
function computeCont(int fromIdx) {
    for (int i = fromIdx; i < this._dataSize; i++) {
        ma1.set(i, ma(i, C, period1.value()));
        ma2.set(i, ma(i, C, period2.value()));
        ma3.set(i, ma(i, C, period3.value()));

And the Java version:

public class MAIndicator extends AbstractContIndicator {
        _sname = "MA";
        _lname = "Moving Average";
        _overlapping = true;
    P period1 = new P("Period 1", 5.0 );
    P period2 = new P("Period 2", 10.0);
    P period3 = new P("Period 3", 20.0);
    Var<Float> ma1 = new Var("ma1", Chart.LINE);
    Var<Float> ma2 = new Var("ma2", Chart.LINE);
    Var<Float> ma3 = new Var("ma3", Chart.LINE);
    void computeCont(int fromIdx) {
        for (int i = fromIdx; i < _dataSize; i++) {
            ma1.set(i, ma(i, C, period1.value()));
            ma2.set(i, ma(i, C, period2.value()));
            ma3.set(i, ma(i, C, period3.value()));

There is rare difference between those two versions. So, why should we extend this platform via script language if we've built a helpful framework?

Java also has better support via IDE. It's easier to implement code completing, debug etc in java than script language.

For the learning curve, the basic syntax of Java is almost same as javascript. If you don't want to write UI, Network features from the scratch, Java is same easier as javascript.

This comes out my decision: I'll implement the feature of custom indicator directly in Java via wizard and templet. It will be integrated with most of the features in NetBeans IDE for developing module.

And the packed size of binary package will grow to 15M size. But you get a BlogTrader? Platform Developer Edition.

New home of

I'm glad that has a new home today. I'll migrate those posts at to here. I even can not visit for 3 months, because it is blocked at the place where I arrived 3 months ago.

Humai Trader as a Pluggable Trading Platform

I’ve activated the plug-in feature of Humai Trader, that means Humai Trader can be a pluggable platform now, you may easy extend its features via plug-in modules.

For example, you write an indicator or one kind of chart as a plug-in module, then distribute it to John or someone else, then John just plugs it in Humai Trader platform following a very simple step, and can use it at once.

Thanks for the pluggable architecture of NetBeans Platform.

Script Language for Humai Trader?

I’m considering the script language for Humai Trader, which will be used to define custom indicators, buy-sell signals etc. I took a look at the script world in Java now. There are some choices newer than several years ago, such as, groovy, beanshell etc.

There is an interesting article:  Choosing a Java scripting language: Round two in javaworld comparing these script languages, which is almost the same point as my view:

Here’s what he says:

Jython is one of the fastest scripting interpreters. From looking at the Website, it seems that Jython development is about to renew, which is good news. There are several good books on Jython. If you like the Python language, Jython is a solid choice.

BeanShell is not as fast as the quickest of the interpreters, but the 2.0 release supports loading of ordinary Java source, which is a strong selling point. I tried loading and running several Java source programs as scripts and found BeanShell to work fine, which is impressive. The libraries are well-organized and make integration simple. If performance is not the single most important criteria for your scripting interpreter and you want to write Java scripts, look at BeanShell.

Rhino is the winner of the performance benchmarking test and also supports Java-like syntax in its scripting. There are plenty of books on JavaScript available. Rhino appears to be well supported, and the distribution includes a useful debugger.

JRuby brings the feature set of Ruby to the table. It isn’t the fastest of the interpreters, but if Ruby syntax and functionality is important to you, take a look at this interpreter. I ran version 0.8, which seemed to work just fine for my simple tests.

Groovy has attracted quite a bit of attention and development effort in the Java community. It is one of the fastest interpreters on the benchmarking tests, even without compiling the scripts down to classfiles. The syntax is Java-like and supports some powerful features that Java doesn’t. This is an interesting addition to the programmer’s toolkit that has a lot of potential.

So, the choice may be JavaScipt, the major reasons are:

  • JavaScipt (JSR 223) will be integrated in Mustang (the next version of JDK)
  • JavaScipt is the winner of the performance benchmarking test
  • JavaScipt is one of the mostly used language in web world, it’s a familiar for many users
  • There are plenty of books on JavaScript available
  • The footprint

The only issue is: Is there a lightweight javascipts editor module available for NetBeans Platform?

Screenshot on Linux

Today I got a screenshot of Humai Trader on Linux. But, as you seeing, there is a warning window popping up to say the Exception, which I mentioned in previous post. It was a bug related to some countries Locale Setting, I have fixed it in my source tree.


But, if you can not wait, try this:

  • open and edit the config file /humaitrader/etc/humaitrader.conf
  • go to the line
    default_options=-J-Xms24m -J-Xmx64m -J-Dnetbeans.logger.console=true -J-ea
  • change to:
    default_options="-J-Xms24m -J-Xmx64m -J-Dnetbeans.logger.console=true -J-ea -J-Duser.language=en"

It should work now

Astrology Module for Humai Trader

The astrology module for Humai Trader works perfectly now.

The upper circle is Heliocentric view, the lower circle is Geocentric view: