Semi-Automated S&R Trading

Discussion in 'Journals' started by PetaDollar, Jun 18, 2012.

  1. The most important and best decision I made was to use Java for the trading platform.
    • Trading is a real-time, asynchronous task. Java has the built-in machinery to handle this kind of thing. I make heavy use of Executor services and concurrent memory objects such as ConcurrentLinkedQueue and ConcurrentHashMap.
    • My build is automatic with the Netbeans IDE. I can tweak it when I need to.
    • The same build runs an any computer, any OS.
    • I can easily tweak the heap size from the command line.
    • JConsole allows me to easily watch RAM and CPU usage in real-time.

    Another important decision was to drop the GUI. Command-line software only, unless there is a clear need for a GUI. A GUI is a time consuming, unnecessary complication in most cases when it comes to trading software. In my first year of trading system programming, I wasted a lot of time maintaining GUIs before I came to this realization.

    Benefits realized from all of the above: I successfully have deployed trading applications to a Linode virtual server, without any problems, the very first day I tried. Furthermore, I was able to use the least-expensive package (512MB RAM) and I still have plenty of RAM available. The system has been up for 38 days straight.

    I am also a certified C++ programmer. But I tell you what, I'm glad I didn't use C++ for the trading application. C++ gives you greater flexibility and speed, but it comes at a cost. Java is just right. If you are playing some sort of millisecond trading game, then I guess you are forced into C++.

    As I look at the 3rd party Java libraries I'm using, there's not much. The most important is Mockito, for testing. There's also JodaTime for dates/times, Apache CLI to parse the command line, and JDOM, Jaxen to handle XML I/O.

    Also, I think using XML for I/O was another fruitful decision. If you mention XML, some software developers (especially web developers) will jump and say "use JSON instead". I even talked to one who thought XML was only good for storing meta-data. The reason, I believe, is that most of them have only seen/used XML to send/receive messages. Well, of course JSON is better for THAT purpose.

    If you want to know the real deal, read Rusty Herrold's books. XML is outstanding for data I/O to the trading program, especially when mated with Java. I also have a PostgreSQL database for storage, but I didn't want to require a trading program to have a database connection. It takes an XML input file, and it gives an XML output file. I can use a variety of readily available GUI editors to change the input, or just a text editor. Using DTDs, schema, schematron, et. al. the trading program is guaranteed to get a valid input file. Using XPath, I have other programs which get data from the XML output just like a database query.

    On the research and analysis side, I tend to favor Python and Matplotlib. It's quick and easy to grab data from an XML file or database and plot up some multi-panel analysis. On the downside, packages and modules tend to be a little disorganized and troublesome compared to Java/Netbeans. I jump a lot between computers. When I clone a Python package onto another computer I tend to run into problems getting it to work at first. Namespace clashes, paths, and the like.
     
    #21     Jul 21, 2012
  2. keep it up!I myself have found the easiest way to trade to be using support and resistance techniques compared to other TA methods. I am looking forward to more of this thread.
     
    #22     Jul 23, 2012
  3. Finally... got the bugs worked out of the new version. All of the bugs were from a small portion of code that wasn't under tests.. :eek: That's fixed now too. So I'll have two days on the live simulator and then back to real $ on Monday.

    Right now it's looking for three different trades on the NQ:

    • Buying support at 2540
    • Buying a breakout of 2560
    • Buying a retrace after a breakout of 2560

    It will make up to five such trades. I'll check in the morning to see if the price has dropped below 2540 overnight. If so, I'll give it a new set of trades to work on.

    As a by-product of the past couple weeks' coding adventure, I can now run the same trading program but feed it simulated ticks. Thus I can use the same exact code for both trading and backtesting, both acting on the same data.
     
    #23     Jul 25, 2012
  4. The TWS Gateway crashed a little before midnight when it tried to save my settings file. Other than that, everything worked perfectly.
    :D

    I restarted the program with the following trades: breakout of the premarket high, buy support at 2560, buy support at 2540.
     
    #24     Jul 26, 2012
  5. Everything worked perfectly yesterday. Last day of simulated-live trading today. Back to real $ on Monday. Today's program:
    • NQ
    • Buy breakout 2591-3
    • Buy pullback to 2591-3 after breakout
    • Buy support in the 2570-2572 area
     
    #25     Jul 27, 2012
  6. Rats, it did the first trade correctly, but no trades afterwards. After a little investigation, I found that the module execution code was swallowing InterruptedExceptions. My goodness. That Newcastle keg does lead to problems sometimes. So no threads got interrupted, and after that first failed breakout everything got turned off and couldn't be interrupted to start over. That's the theory anyway. I'll have to add some more automated tests this weekend and run the live-sim again on Monday. :mad:
     
    #26     Jul 27, 2012
  7. gmst

    gmst

    Hey I admire your effort. But if you are not doing much sophisticated stuff like market making, order book analysis, pairs/basket trading, then instead of writing your custom order management tool, why can't you use some off the shelf software like NT or multicharts?
     
    #27     Jul 28, 2012
  8. Why a custom job? Great question, easy answer: minimize limitations that have to go in commercial software by its nature. Almost all of my stuff is run from the Linux command line, and therefore harnesses the power of everything Linux. Could a company sell something without a GUI? I seriously doubt it.

    I have complete flexibility in how incoming ticks are turned into trading decisions such as the identification of support. I wouldn't say I did a thorough investigation to figure out what I really *needed* to make money, to see if there was commercial software that fit the bill. But, I'm sure in a good position now if you can excuse the hiccups. And I have the flexibility to add functionality.

    There is also the question of convenience. Once everything is operating properly, I can optimize I/O to what works best for me. For example, I'm thinking about web page and/or smartphone dashboard. Yes, that's a GUI. My point is, I can decide what needs to go in it.
     
    #28     Jul 28, 2012
  9. gmst

    gmst

    I am afraid I didn't quite understand your simple answer :(
    I have never used Linux - so I definitely don't understand what you mean when you write "harnesses the power of everything Linux". It will be great if you can expand a bit on this part. For example, what your software will be able to do 'in future' that for example Multicharts doesn't do 'right now'? I am very curious. Also, had you written you are using Matlab or R for development of trading models and those software allow you a lot of flexibility over multicharts, I will understand. But I think you are saying since you are developing your software in Linux, that platform provides much more flexibility than anything Windows based?!

    All the retail softwares out there handle tick data and have time bars, volume bars, renko, heiken aishi etc. etc. I am sure those bar types can be used - or maybe some mathematical transform on those bar types or raw price series can be used to identify support. So, how does your custom software is better? I am sure you have put huge amounts of work into developing it - so there must be value in it. I am just trying to understand where exactly is the value.

    Thats a good illustration of what your custom software will allow. For example, I don't think multicharts has a web/phone version.
     
    #29     Jul 28, 2012
  10. Working in a Linux environment is a huge advantage for anyone processing and analyzing data. I don't think it's something I can readily explain in a post, but there's plenty of info you can read out there on the Internet. Ubuntu offers dual installs over Windows (you can run both on the same computer, choosing at boot-up) for those interested.

    The advantage with custom software is complete control of everything that happens between the ticks coming in and the orders going out. There is also complete control of feature implementation. The advantage of Java over another Turing complete language such as R or MatLab is its multi-threaded nature and supporting concurrent utilities. This is important for trading applications which are asynchronous by nature.

    All that being said, if I wanted to have a multi-security strategy up this week it would be easy enough. From what I understand, that is a planned feature upgrade for Multicharts. I was impressed that the company keeps its bug reports and planned upgrades on a public website.
     
    #30     Jul 29, 2012