Posted in Uncategorized on October 26, 2009 by Eric Somdahl
Why? Why not!
Source of hanoi.scala
object Hanoi {
def main (args: Array[String]) : Unit = {
var plates: Int = 4
for { j <- args } plates = try { Integer.parseInt(j) } catch { case _ => 1 }
val soln = hanoi(plates, "A", "C", "B")
for { i <- soln } Console.println(i)
}
def hanoi(n: Int, peg1: String, peg3: String, peg2: String) : List[String] = {
n match {
case 1 => List( "Move the plate from " + peg1 + " to " + peg3)
case _ => hanoi(n - 1, peg1, peg2, peg3) :::
List( "Move the plate from "+ peg1 + " to "+ peg3) :::
hanoi(n - 1, peg2, peg3, peg1)
}
}
}
Compile and invoke as "scala Hanoi" or "scala Hanoi x" where x is the number of plates to solve.
Posted in Uncategorized on October 21, 2009 by Eric Somdahl
More Googling has uncovered 2 new ways to invoke Java/Scala code with MetaTrader. Both are commercial products but licenses are reasonably priced.
The first takes an approach similiar to the one demonstrated in this blog posting. The name of the product is JavaDllBuilder. It compiles Java code into DLLs but uses a JNI translating layer to make the code available.
The second is more interesting. It is called DDE for Java, a DDE client for java (naturally!) Using the approach of a Java program accessing MetaTrader through DDE I think I can take advantage all of the heavy lifting done by MetaTrader (indicator calculation, actual communication with the broker) and do all of the fun work in Scala!
Edit: crap -- DDE is being dropped from MetaTrader 5. Scratch that option!
Posted in Blog Entries on October 14, 2009 by Eric Somdahl
My Google-fu is strong... 
I believe I have found a way to invoke Java and Scala code from MetaTrader 4. It is not pretty but it should work. I have not actually tested this -- this is just my thinking out loud after some searching.
-
The starting point is a compiled JAR file... either Scala or java code will do.
-
IKVM (http://www.ikvm.net). I think this project is a product of the Mono people. It is an implementation of the JVM designed to run under Mono/.NET. The bytecode from the JAR file is compiled to some format that runs on the IKVM JVM runtime. This glob of bits (a dll) is then made available as a .NET assembly.
-
This little article on CodeGuru.com explains how to make a .NET assembly available as a plain old importable DLL. It is written from the context of importing .NET code into MetaTrader.
The third step of that process would be unnecessary using NinjaTrader since it natively supports .NET stuff.
I guess the big thing is what level of JDK is supported by the IKVM JVM. The webpage claims JSE 6 compatibility with the exception of AWT/Swing and Security classes. Neither of those will be an issue for this project.
Edit 17 Oct 09 : Here is my followup implementing this mechanism. Success!
Posted in Blog Entries on October 13, 2009 by Eric Somdahl
Here are some of the platforms available for automated Forex trading.
MetaTrader 4: (http://www.metaquotes.net/metatrader/)
MetaTrader has a scripting language for automation, MQL4. It allows loading foreign code via Windows dlls. There is a lot of tool-chain distance between Scala/Java bytecode and a Windows DLL but my Google-fu seems to have found a path. Look here for a subsequent post describing it.
MT4 has a big advantage in that many Forex brokers use it for their trading platform.
NinjaTrader: (http://www.ninjatrader.com/)
NinjaTrader automates via a .NET-derived language (C#). Its automation language seems capable of importing outside .NET assemblies. The tool chain for MetaTrader involves making the JVM bytecode available as a .NET assembly. That means that this route would work with the tool chain I found for MT4 but with one less step.
NinjaTrader works with less than a dozen brokers but the ones it works with tend to be very reputable.
Tradestation: (http://www.tradestation.com/)
This gets good reviews but is limited to the TradeStation brokerage...
QuickFix protocol (http://www.quickfixj.org/)
FIX protocol is a standard for all kinds of financial maneuvering. There is a Java implementation. Basically, my dream setup for this project is
-
QuickFix/J with a Scala Wrapper
-
Compose a Domain Specific Language (DSL) in Scala
-
???
-
Profit
FIX protocol is supported by a few brokers but they are the majors: Oanda, Dukascopy, Interactive Brokers, etc. The problem is that because you are dealing with the major players, it requires a not-insignificant outlay of money (in account minimums and monthly fees) during the development process.
The cost probably makes this route a no-go, for now. But just for now...
Posted in Blog Entries on October 12, 2009 by Eric Somdahl
In (re)evaluating this project I should lay out some basic requirements for the Forex. Here are hard and fast requirements:
- Back-testing of strategies
- Use of 1-minute bars the bare minimum
- Tick data back-testing preferable
- Unattended, automatic execution of trades
- Large number of technical indicators can be easily plugged in
- Should be able to communicate to me (via email or SMS) in real time as things happen, good or bad
Here are some desires, either bells and whistles or what will make this fun rather than work:
- Implementation (at least in part) using Scala and Java
- Graphs with technical indicators, for live data and back-testing
- Use of GA (Genetic Algorithms) to decide when to trade
- Should be able to receive communications from me (via email or SMS), in emergency situations. For example, in the case of a catasrophic news event, I would like to be able to send an SMS to it indicating it should close all positions immediately and cease trading.
- Be portable across Forex brokers
- Use tools that are Open Source as much as possible