Sunday, August 27, 2006

%b Systems

One of the many cats we have here on the farm knocked over my external hard-drive. While it was on. And now it sounds kind of like how it would if you ran over a roller-skate with a lawn mower.

I took it to the computer doctor, who plugged it in, heard the sound, and told me there was no chance to recover anything from it. And charged me $22.

Fortunately I had been using it generally only for backup purposes, so I didn't lose anything. Well, I didn't lose much. I also used it to store my Thinking Stuff databases, with all the Gain Capital data plugged in, and some pretty useful trading systems. I can re-load the data. But the systems??

Here's where not keeping good trading systems to yourself pays off. If ever your cat knocks over your external hard-drive.

I'd sent the details of a couple of seemingly good systems to one of my customers. So I had them in a separate Excel file sitting on my desktop and not on the external drive.

So here they are. I'd appreciate comments. Or any profit-improving alterations. Of course you'll be using these at your own risk.

These 2 are both based on %b. %b is a single line whose value is determined by where the closing price is in relation to the upper and lower Bollinger lines.

When the close is exactly at the lower line, %b equals 0. Below the lower line, %b is negative. When the close is exactly at the upper line, %b equals 1. When it's exactly in the middle, %b equals 0.5. And so on.

It's very rare for %b to be lower than -0.3, or higher than 1.3.

The way Bollinger Bands are constructed, the price moves from the lower band, to the upper band, and back to the lower band. The problem is that the Bands aren't static. Just because the price moved from the lower band to the upper band, it doesn't necessarily mean that the price is rising - the upper band might have come down to meet the falling (or stagnating) price.


%b System #1

Here's a system which attempts to use this knowledge. It was tested on 5 Minute bars and seemed to do quite well. However it was only a couple of months of prices, so please backtest thoroughly before use. In particular, using a %b value of 0.1 for Longs and 0.8 for Shorts might need to be changed. As might the percent to be added to or subtracted from the Close price for the Stop Loss settings.

All Bollinger settings used a period of 720, with 2 standard deviations above and below.

Rule TypeDescription
Long - Entry RulesValue of %b Is Below X (0.1)
Long - Entry ValuesPrice Where %b Would Equal X (0.1)
Long - Init. S/L ValuesClose Minus X (0.3) Percent
Long S/L Mgmt RulesEvery Bar
Long S/L Mgmt ValuesClose Minus X (0.3) Percent

And for shorts:

Rule TypeDescription
Short - Entry RulesValue of %b Is Above X (0.8)
Short - Entry ValuesPrice Where %b Would Equal X (0.8)
Short - Init. S/L ValuesClose Plus X (0.5) Percent
Short S/L Mgmt RulesEvery Bar
Short S/L Mgmt ValuesClose Plus X (0.5) Percent


%b System #2

Instead of only using a trailing stop, this sytem also attempts to lock in a bunch of profit if the price has moved a fair distance in our favour.

For longs, initially the stop loss is set to the lower Bollinger line (where %b equals zero). The stop loss is then kept at the same level as the lower Bollinger line every bar after entry (remembering that the stop loss will never go down, however). But, if %b ever gets above 0.8, then the stop loss is moved up to where %b would equal 0.8. And from then on, the stop loss is kept where %b would equal 0.8.

All Bollinger settings used a period of 288, with 2 standard deviations above and below. Directional Movement System period was 14.

Rule TypeDescription
Long - Entry RulesADX Is Below Both +D and -D
Long - Entry RulesValue of %b Is Below X (0.2)
Long - Entry ValuesPrice Where %b Would Equal X (0.2)
Long - Init. S/L ValuesPrice Where %b Would Equal X (0.0)
Long S/L Mgmt RulesEvery Bar
Long S/L Mgmt ValuesPrice Where %b Would Equal X (0.0)
Long S/L Mgmt Rules #2Value of %b Is Above X (0.8)
Long S/L Mgmt Values #2Price Where %b Would Equal X (0.8)

And for shorts:

Rule TypeDescription
Short - Entry RulesADX Is Between +D and -D
Short - Entry RulesValue of %b Is Above X (0.8)
Short - Entry ValuesPrice Where %b Would Equal X (0.8)
Short - Init. S/L ValuesPrice Where %b Would Equal X (1.0)
Short S/L Mgmt RulesEvery Bar
Short S/L Mgmt ValuesPrice Where %b Would Equal X (1.0)
Short S/L Mgmt Rules #2Value of %b Is Below X (0.2)
Short S/L Mgmt Values #2Price Where %b Would Equal X (0.2)


These and a couple of other objective trading systems can be found on my Trading Systems For Free page.

Friday, August 25, 2006

Looking For Good Broker With Cheap API

Right now my software connects with 2 brokers - Gain Capital and Oanda.

Gain Capital has a free API, but its behaviour is different in its Live accounts compared to its Demo accounts. It means to finish coding it, I would have to experiment in my Live account, while risking real money. And their minimum purchase size is 100,000 units (1 contract). No dice. Until that changes, my software is only going to work in their Demo accounts.

But that's fine. Because it's free. And it allows for people to develop and test their trading systems for no initial outlay (other than my subscription fee :-)

At the other end of the scale is Oanda, which by most accounts has one of the best setups around. But it's not cheap. US$600 to obtain it, and after the first 2 months it becomes US$600 per month. You should never pay $600 per month, because its discounted for volume - $50 for every million dollars of currency traded. So if you purchase $12 million of currency within the month, then the API fee for that month is waived.

Because their spread on EURUSD is very low - normally 1.5 pips - you should be able to bring down your API fee to a maximum of about $200. At the end of the month, just buy and sell and buy and sell EURUSD until you reach $12 million worth. Whatever the cost of the spread works out to is what your actual monthly payment will be.

There you have it - one free API that you can't use for Live trading, and one expensive API that you can. One cheap and ordinary. One expensive and good.

What's missing is the cheap and good API. I realised this is missing from my v1.0 plans.

I'd like to get Interactive Brokers done, and no doubt I will at some point in the future. But it's not as straightforward as it probably could be.

Then I remembered the DynaOrder product, which allows connection to FXCM and IB. It's having a closing-down sale at the moment, with Sept 1st the shut-down date. The reason I decided against using this a while ago, is because firstly there is no historical price retrieval functionality. Your computer shuts down for 5 minutes, and there is no way to get that 5 minutes of data. Secondly it didn't look like stop losses were placed at the same time as the order - you had to send it separately. I don't like that.

And now it's going out of business, there'll be no support, and no fixing of bugs, and no changes if FXCM or IB change their setup.

On the forum talking about the closing down of DynaOrder, I read a post about CMS Brokers having a free API. It looked alright.

Then I went to the GoForex site, which ranks Forex brokers. Oanda on top. Gain Capital nearing the bottom. CMS Forex 2nd-last. FXCM last.

That survey doesn't have so many contributors, and shouldn't be used as a definitive guide. But reading the comments didn't make me want to spend time writing the code to connecting to the bottom-ranked brokers.

So I went to the websites of the top-ranked brokers to look for APIs. It looks like the EFX Group has a free one.

It's not just the free API though. Minimum purchase size has to be small. Minimum account size also. And customer service is important.

If anyone has any reasons why the cheap and good option should not be EFX Group, or even why it should, please leave a comment.

Unknown when it would be done though. I suspect I'll finish what I have planned for v1.0 and then code the EFX interface.

Buy & Hold

Scenario #1: The Aussie Dollar falls below 0.6000. My high-school friend tells me, months after the event and after it had risen back to 0.7500+, that he knew he should have bought it then, because obviously it was going to go higher. He was kicking himself.

Scenario #2: Australia's biggest telco - Telstra - is hitting record lows at the moment. The thing is that it's ~51% owned by the Australian government, who want to sell. Selling it now would be too cheap, so they should really hang back. But doing so keeps the price low, because they could drop billions of shares on the market at any time and flood the market. My Dad tells me that now would be a good time to buy Telstra shares.

The question I have to ask is, okay, but when would you sell it?

AUDUSD hit a low of ~0.4800 before rising back up to 0.7500. If my high-school friend had bought at 0.6000, he would have had to suffer through a loss of some 1200 pips before it finally swung back. If he had bought 1 contract, that's $12K. He used to work as an English teach in Japan, so $12K is a pretty big deal for him.

And there is where Buy & Hold falls down. The risk. You don't know it. By definition, Buy & Hold means you have to risk 100% of your money. You don't care about the losses (right?) because eventually that's going to turn around and go into a huge profit (right?).

Dollar-cost-averaging has the same problem. It works great, as long as the price eventually rises above where you originally bought. But if that price keeps going down and down and down, then really all you're doing is giving other people a chance to sell their stake. At your expense.

I don't mind long-term investing. I'm just saying use a stop loss. A point where you are prepared to say "yep, got that one wrong", you sell for a loss, and move on.

My other piece of advice is to not try and pick bottoms. Don't buy on the way down because you think it's cheap. It could well get a lot cheaper. Wait for the turn around. It might cost you a little in terms of profit, but you'll have more confidence going into the trade, and probably more chance of coming out ahead.

So, no Telstra shares for me just yet :-)

Thursday, August 24, 2006

Alerts Testing

I haven't started :-)

What happened was, I finished the code on Saturday night. And then had to wait until Monday for the markets to open so I could test the alerts.

On the Sunday, I chose to start coding what I planned for the release after the Alerts release - more charts functionality.

I got so much done on that Sunday, that I thought I might as well finish the charts functionality and include it in the Alerts release as well.

Then it was my Mother's birthday, and as a present I thought I might clean up the house. Only thing is that my Mother is one of those hoarder-type-people. And my Father, after retiring from the work-force a few years ago, is now the house-wife. Those 2 things combined means cleaning the house could in no way be described as a small job, and therefore worthy of being called "a present". That took 2 days, and I'll probably do some more cleaning tomorrow.

Anyway, I'll start testing Alerts this coming Monday. The bonus is that the chart stuff will also be included in this next release.

Saturday, August 19, 2006

Nearing v1.0

I've been working on this software for about 2 years now, and it's finally getting close to having all the bits that I originally imagined.

v0.8.0, the release I'll be testing this week, adds Alerts.

v0.8.1 will add some more charts functionality.

v0.8.2 will add Holidays.

v0.8.3 will be bug fixes, and will become RC1 (the "Release Candidate #1").

If necessary, v0.8.4 will fix any bugs found in RC1, and will become RC2.

And so on and so forth until I'm happy to say that it's worthy of being v1.0.

As soon as that happens, the prices go up :-)

-----------

N.b. There are some things I did want to have in v1.0 but won't make it, most notably the Interactive Brokers functionality. Actually there's still a thousand things I'd like to add, but I had to draw a line in the sand. It's time for me to start using this software instead of making it. At last :-) It's also time to get a job.

I'll still be adding new functionality from time-to-time. Obviously bug-fixes are important and will get done as they arise. But I won't be working on the software more-than-full-time like I have been up to now.

Friday, August 18, 2006

Coding For Alerts Functionality Finished

I'll start testing it when the markets open again on Monday.

There are a million companies which offer price alerts, so you might wonder why I bothered?

Well, those other Alerts services are generally price-based. You set the alert to fire when the EURUSD hits a certain price. Yay.

The Thinking Stuff software offers indicator-based alerts. As the simplest example, you can set an Alert to fire when the Low of the most recently completed bar is above a simple moving average.

You can use *any* of the Rules listed on this page, specifying 1 or many. And you can use them in *any* combination with each other (if you specify more than 1, then all must be true for the alert to fire).

There are also Trading Alerts, which fire when you have a system auto-trading. There are 6 to choose from - Order Placed, Order Modified, Order Cancelled, Trade Entered, Stop Loss or Take Profit Modified, and Trade Exited. Any combination of those alerts can be chosen.

Alerts are sent to an email address, displayed on screen, or both. You can set the Alerts to use completed bars only for their calculations, or include incomplete bars also. They can be set to fire a set number of times and then stop, or to continue firing until you switch it off manually.

Incidentally, you can achieve the same thing as a price-based alert by using this Rule: "[OHLC] Is Above X" (or "[OHLC] Is Below X"). Specify 'High' ('Low') as the [OHLC], and that you don't want to use completed bars only, and that's it.

Monday, August 07, 2006

v0.7.5 - Emergency Release

*sigh*

The Command Centre wouldn't open unless you had the Interactive Brokers trading platform (TWS) and possibly the TWS API installed.

Not good for people who don't want to use IB.

So... I moved the IB proof of concept onto its own window, rather than having it on the Command Centre (where the Gain Capital and Oanda bits are).

That's done, and v0.7.5 is now available for download.

----

The Commodity Channel Index saga continues. Word back from the makers of charting module has it that their calculations match those in TradeStation and MetaStock.

So now it's Oanda and me versus those companies. They were kind enough to send me their code, so I'll go through it and see what's going on.

Saturday, August 05, 2006

Change Log

I know you'll be very excited to know that I finished the Change Log. The entry for v0.7.4 is the longest so far, which probably explains why it felt like writing the code was dragging on forever.

I downloaded some prices from Oanda, and checked my Commodity Channel Index against theirs. It seems like the 3rd-party module I bought is the odd one out, so I sent the makers an email. It means that Backtesting and Auto-Trading will work off the proper CCI values, but the Chart (i.e. the 3rd-party module in question) will not.

The next release will be v0.8.0. The jump up in numbering (ever closer to the elusive v1.0.0) is due to the major functionality that will be added - Alerts.

Alerts will be sent to the email address you specify. There will be the ol' "Price rises/falls to a specific level" alerts. But, there will also be Indicator-based alerts. For example, "Simple Moving Average rises/falls to a specific level".

Furthermore, you can have multiple rules for an alert to be triggered. In fact Alerts will work just like the Entry Rules for a system - you can use any of the available Rules, as many as you like, and in any combination you like.

The list of available Rules to pick from can be found here (I just updated that page so it's up to the minute).

Friday, August 04, 2006

v0.7.4 - More Indicators

As mentioned in the post "The Never-Ending Release", this release just didn't want to be made public. Until now. Go get it.

Be warned though - at time of writing I have not done a test install on a machine other than my own. Please let me know of any problems.

The Change Log will be updated with a full list of changes soon, but that post I mentioned lists most of them.

Thursday, August 03, 2006

Commodity Channel Index Construction

Anybody have the formula for the Commodity Channel Index?

The results I get are different to a 3rd-party module I have, and I was wondering which was correct.

The way I calculate it is from Incredible Charts.

Due to this and a bizarre Excel problem (if you opened once and closed, then opened again, it would only show the top and bottom part of the Excel window - the worksheet was invisible) the release date of v0.7.4 is moved to tomorrow.

Unless someone gets back to me v.quickly then I'll release v0.7.4 with the CCI thing as a known bug.

Wednesday, August 02, 2006

The Never-Ending Release

Wow, this release seemed like it would never end. But it will be out soon. Today I'll do some testing, and if all goes well (putting emphasis on those words) then it should be out tomorrow.

The first thing you're going to notice is that you can now save your password so you don't have to enter it each time. Careful though - it saves your password in plain text.

The second thing you're going to notice is the major changes in layout. Hopefully it's prettier now. I got rid of those Info boxes, with the blue writing. They kind of looked ugly, took up a lot of space, and limited me to the amount I could write. I replaced them with a scrollable field on the right hand side of those windows that need it. And you can hide that field if you don't want it. (N.b. the Login window still has the Info box at this time).

You can make the backtesting output files Excel files (2002/XP and above), or you can keep them as they are now, which is comma-separated text files.

You can vary the number of units/contracts bought during backtesting. Up until now backtesting always bought 100,000 units (1 contract) for comparing apples-with-apples purposes, but now you can choose to continue to do that, or to follow the Money Mgmt rules for the particular Trading System. It's still going to start with a bank of $100K though.

There's an Interactive Brokers proof of concept which you can muck around with. If you're bored one day.

Last but definitely not least, there's a whole bunch of new Rules and Values:

Bar Formations (existing Family)
Spread Is X Or Below

Simple Moving Averages (existing Family)
SMA Is Falling
SMA Is Rising

Bollinger Bands (existing Family)
Bollinger Bandwidth Is Above X
Bolllinger Bandwidth Is Below X

Commodity Channel Index
Commodity Channel Index In Overbought
Commodity Channel Index In Oversold

Commodity Channel Index X-Over
One CCI Is Above Another
One CCI Is Below Another

Bollinger Bands X-Over
One Upper Bollinger Line Is Above Another
One Upper Bollinger Line Is Below Another
One Lower Bollinger Line Is Above Another
One Lower Bollinger Line Is Below Another
Upper Bollinger Line Is Above Lower Bollinger Line
Upper Bollinger Line Is Below Lower Bollinger Line
Lower Bollinger Line Is Above Upper Bollinger Line
Lower Bollinger Line Is Below Upper Bollinger Line

What I mean here is, for example, the Upper Bollinger Line with period 20 is below the Lower Bollinger Line with period 100. Obviously the Upper Bollinger Line with period 20 is never going to be below the Lower Bollinger Line of the same period.

Typical Price - (H+L+C)/3
Typical Price of Last X Bars Clear of Entry
Typical Price Is Rising
Typical Price Is Falling
Typical Price Is Above X
Typical Price Is Below X
Typical Price Minus X Percent (value)
Typical Price Minus X Pips (value)
Typical Price Plus X Percent (value)
Typical Price Plus X Pips (value)

Typical Price Average
[OHLC] Above Typical Price Average
[OHLC] Below Typical Price Average
Value of TPA Is Above X
Value of TPA Is Below X
Typical Price Average Is Rising
Typical Price Average Is Falling
Typical Price Average (value)

Typical Price Average X-Over
One Typical Price Average Is Above Another
One Typical Price Average Is Below Another

Exponential Moving Averages
Close Above Exponential Moving Average
Close Below Exponential Moving Average
High Above Exponential Moving Average
High Below Exponential Moving Average
Low Above Exponential Moving Average
Low Below Exponential Moving Average
Value of EMA Is Above X
Value of EMA Is Below X
EMA Is Rising
EMA Is Falling
Exponential Moving Average (value)

Exponential Moving Average X-Over
One Exponential Moving Average Is Above Another
One Exponential Moving Average Is Below Another

Exponential Moving Average Swings
Current EMA Swing Pattern Is Higher Peak
Current EMA Swing Pattern Is Higher Trough
Current EMA Swing Pattern Is Lower Peak
Current EMA Swing Pattern Is Lower Trough
EMA Swing High Higher Than Previous Swing High
EMA Swing High Lower Than Previous Swing High
EMA Swing High Lower Than Either Previous 2 Swing Highs
EMA Swing Low Higher Than Previous Swing Low
EMA Swing Low Higher Than Either Previous 2 Swing Lows
EMA Swing Low Lower Than Previous Swing Low
Previous EMA Swing Pattern Was Higher Peak
Previous EMA Swing Pattern Was Higher Trough
Previous EMA Swing Pattern Was Lower Peak
Previous EMA Swing Pattern Was Lower Trough
Currently In Exponential Moving Average Swing Down
Currently In Exponential Moving Average Swing Up
On Or After Day X Of Exponential Moving Average Swing
On Or Before Day X Of Exponential Moving Average Swing
EMA Swing High (value)
EMA Swing Low (value)

Look out for it tomorrow... probably.