Sunday, June 12, 2005

More On Thinking Stuff

I've gleaned a lot of good ideas and information out of the Currency Secrets website (see also the link in the sidebar). Its author, Ryan Sheehy, kindly gave my program a look over and posted some questions. So, here are the answers.


1. Where does the program pull its data from to generate live buy and sell signals?

I've set it up so it can store data from multiple providers. And you can specify which provider's data to use for making trading decisions, even if the account to trade with is with someone else.

For example, you can use the Oanda data to make trading decisions with, but you actually make the trades with your FXCM account.

I'm not sure when this scenario would occur, but I made it possible anyway. Well, maybe your system works better with Oanda's data, but FXCM might provide better spreads (hypothetically, and in no way implying that FXCM's spreads are or are not better than Oanda's). Or something.

But as for where the data *actually* comes from *right now*, that'd be from Gain Capital, the company you recommended for free forex data. I managed to find the link to the historical data files by reading through the Oanda messageboard. Make sense?

The program reads in the text files and stores the tick data. Then it runs over the tick data and creates the interval data. Out of the files I've processed so far, (all of the EURUSD and USDJPY ones) I've found only a couple of obviously erroneous ticks, and one file which was formatted slightly differently to all of the others.

When I purchase the Oanda API, I'll be storing data from that as well.


2. Can the process be tested on Oanda's FXGame platform before going live?

Of course. You'd set up your system to first trade with your Oanda FXGame account. Then if you're satisfied, a few mouse clicks changes the account to be the real Oanda one. Or you could just add another account, and then it would trade in both the real and game.

Here we are looking at the Accounts tab of the window where you create your system. You can see that this system will trade the EURUSD and USDJPY in the Oanda BT a/c ("BT" = Back Testing).

Thinking Stuff System Update Screen - Accounts


If you want to change this, highlight the row to change and click the Edit... button. That brings up the Change Settings window, where you change the Account by selecting from the pull-down list, and click Save:

Thinking Stuff Change Settings Screen - Accounts

Thinking Stuff Change Settings Screen - Accounts


That's it.


3. Can the user input their own system? Or will they need you to program it for them?

Well, the user can mix and match any rules I've already coded. And if I haven't coded something they want, then yes, I'd have to code it and send out a new version of the executable. But that's the trade-off from trying to make the system as easy to use and as far away from coding as possible.

It'll have all the "normal" indicators. But if someone had some fancy indicator they'd created by themself, they'd have to tell me how it worked so I could code it for them.

Here's a bit of an example of creating/modifying a system. I was going to modify a system I'd already made, and then I thought, well, I should copy this system before I go about making any changes. So I clicked the Copy button, and this little window popped up:

Thinking Stuff System Copy Screen


Entered the new ID and description and clicked Save.

That brought me to this screen:

Thinking Stuff System Update Screen - Trading Rules


And then I thought, well, I should delete all the Short rules to remove some clutter, to make it easier for people to see what I'm doing. Highlight a row to delete, click Delete button.

Thinking Stuff System Update Screen - Trading Rules


That system don't go short no more.

And now we're all set to "start" the explanation :-)

Thinking Stuff System Update Screen - Trading Rules


To explain the system in the screenshot above, it's kind of a "counter-intuitive" system. You can see it wants to go long when the price closes below the lower Bollinger band. I didn't think this would work, and it doesn't, but that's the point of the software - to test new theories, to experiment, to know myself how well a system I've bought actually does before using real money.

The second entry rule is that the RSI has to be in oversold. Nothing amazing about that. If both entry rules are satisfied, the entry order will be placed at the lower Bollinger line. The initial stop loss is X pips below the entry, and initial take profit set at the upper Bollinger line.

Every bar we move the take profit to keep it the same as the new value of the upper Bollinger line.

So we backtest that, and find it doesn't do very well. Or for whatever reason we want to experiement, and we want to change that second entry rule to be using the MACD Histogram instead of RSI.

Select the second entry rule, and click Edit...

Thinking Stuff Change Settings Screen - Trading Rules


Select "MACD Histogram" from the Config Family pull-down list. Select "MACD Histogram In Oversold" from the Config Type pull-down list.

Thinking Stuff Change Settings Screen - Trading Rules

Thinking Stuff Change Settings Screen - Trading Rules


The default settings of 12, 26, 9, 0, 0 are populated:

Thinking Stuff Change Settings Screen - Trading Rules


If you just want to use the default, click Save. That's it. Back to the previous screen and you see the changes were saved:

Thinking Stuff System Update Screen - Trading Rules


And then you decide that you'd like a bit of upward pressure before setting the long order. So we want the entry bar to be a Bullish Bar - that is, where the price opened in the lower third of the candle, and closed in the upper third. Click Add... and the Change Settings window opens again, but this time it's empty:

Thinking Stuff Change Settings Screen - Trading Rules


Select "Long - Entry Rules" from the Rule Type pull-down list. Select "Bar Formations" from the Config Family pull-down list.

Thinking Stuff Change Settings Screen - Trading Rules

Thinking Stuff Change Settings Screen - Trading Rules


Select "Bullish Bar" from the Config Type pull-down list. Select "Daily" from the Interval pull-down list.

Thinking Stuff Change Settings Screen - Trading Rules

Thinking Stuff Change Settings Screen - Trading Rules


Note I also selected "3" as the Rule Ordering. Actually this doesn't do anything functional - it just improves the readability on the previous screen when everything's shown in a list.

Click Save. That's it. Back to the previous screen and you see the changes were saved:

Thinking Stuff System Update Screen - Trading Rules


We just added a new entry rule, and it took 7 clicks of the mouse.


4. Is there a system that can strangle the markets at a specified time entered by the user? This would be a great feature to have as sometimes I'd like to strangle the market when economic announcements are released but cannot physically BE in front of the computer when these announcements ARE released. An example of this system would be... at 827 NY EST (3 minutes BEFORE the 830 NY EST announcement) place a buy entry stop and a sell-entry stop at 20-day 2-StDev Bollinger Bands distance away, or the highest high of the last 20-days (and lowest low of the last 20-days), or maybe just an arbitrary figure like 20pips away from whatever the closing price is 2-3 minutes prior to the announcement! I guess the possibilities are endless!

Well, you can do this with the Holidays functionality. I made this functionality so the system would *stop* trading when a major announcement was coming up (if I'd enabled that setting for that particular system).

But it could be used in reverse as well - create a "holiday" that finishes 5 minutes before the announcement. Then, taking your three examples in the question, have your system set up as below. (Remember that you're just selecting all this stuff from pull-down lists. The only typing needed is to enter the Bollinger period, number of Std Devs, etc):

Bollinger Band Example
    Long - Entry Rules - Every Bar
    Long - Entry Values - Upper Bollinger Band
    Short - Entry Rules - Every Bar
    Short - Entry Values - Lower Bollinger Band

Breakout Example
    Long - Entry Rules - Every Bar
    Long - Entry Values - Highest High of Last X Bars
    Short - Entry Rules - Every Bar
    Short - Entry Values - Lowest Low of Last X Bars

Arbitrary Pips Example
    Long - Entry Rules - Every Bar
    Long - Entry Values - Close of Current Bar
    Long - Entry Values - Pip Offset (20)
    Short - Entry Rules - Every Bar
    Short - Entry Values - Close of Current Bar
    Short - Entry Values - Pip Offset (20)
(It's ok - the Pip Offset setting knows whether to add or subtract the amount specified)

So that's all well and good for the entry. But when to get out? I guess maybe you'd add something like this as well to the systems above (where you specify X):
    Long - Init. S/L Values - X Pips Below Entry
    Long - Init. T/P Values - X Pips Above Entry
And reverse for shorts.

Sounds good so far? Well, now it's problem time. You set your system up to throw an entry signal on every bar. When the trade you wanted to make (on the announcement) is finished, the software is going to keep throwing entry signals. You'll need to create another holiday which begins soon after the announcement, and ends in the year 2999 (or whatever). Then when you get back to your computer, you could just switch off the "live" setting for this system.

So a combination of holidays and the "Every Bar" rule (normally used for trade management), the system does in fact do what you want.

However, this scenario highlights that while I've made this software as easy to use as possible (i.e. selecting rules from pull-down lists rather than having to learn some kind of simplified programming language), the user still needs to think hard about what they've set the system up to do. In this case, without the second holiday, the system is going to keep throwing entry signals when you probably don't want it to.


5. Is it possible to set up an OCO order? I know Oanda doesn't allow this, but let's say that if a system mentioned in step 4 were able to be created and I wanted to strangle the market - would it be possible to cancel the order that wasn't hit to prevent any whipsaw action that may happen?

Hmmmm, it's a little bit difficult. The way I've set it up is that every bar it calculates whether the system should create a long order or not, and whether it should create a short order or not.

You can have both a long order and short order at the same time, that's fine. But to cancel one when the other is entered? Hmmmm, hmmmmm...

I mean, to cancel an order when a trade in the opposite direction is entered is quite easy. Simple. The problem is that next bar is coming along, and it's probably going to want to create the order again.

I mean, to check that a trade in the opposite direction is still open and therefore don't create the new order is quite easy. Simple. The problem is that the trade previously entered may well be closed. So now there is no trade in the opposite direction, so it's probably going to want to create the order again.

Unless that holiday is there, saying don't trade anymore. We're a bar or two away from the announcement now anyway...

So I add a checkbox or something that says "Cancel/don't create orders if a trade in the opposite direction is entered", and I think it would work fine for your announcement scenario, assuming you've got a holiday in place straight after the announcement as I recommended in the answer to the previous question.

But the next bar comes around and there's no holiday, and no trade in place, then there is nothing to stop a new order being created if the rules say to do so. Again, the software is only going to do what you tell it to do, so it's important to think about how you've set up your system.


6. If an OCO cannot be set up would it be possible to cancel at a specified time? Or at times different to Oanda's? I guess it would need to rely on the computer's own internal clock (wouldn't want there to be a power surge... but that's okay, I've got a laptop... which brings up another interesting question...)

The holiday thing has the options:
    - Don't make new orders/enter new trades during the holiday period
    - Get out of all trades when the holiday starts
    - Get out of trades when the holiday starts unless the trade has X pips profit

By "holiday" I don't necessarily mean a holiday such as New Years Day. You can create whatever "holidays" you like. Maybe you don't want the thing to trade between 5AM and 10AM on Tuesdays. Or no trading on Thursday. Or between 11:16AM and 11:17AM on 27-Nov-2005. You can punch in whatever you like.

It relies on the computer clock.


7. Would it be possible to read the amount of battery power left in a laptop and to have some preset configuration where if the laptop gets to within 10% remaining on its battery life all open positions are closed or all pending positions are closed (or both... depending upon the users settings)? Ok, maybe I'm getting a bit too carried away now!

I'll think about it for the future :-)

I should say though, that actually the system doesn't create new orders if you don't have an Initial Stop Loss Value specified. i.e. There is *always* a stop loss in place. This should prevent a disaster in the case of power failure or other unexpected happenings.


8. With your systems are they all on the same time frame? Or can the user select their own time frame?

You can choose whatever time frame you like, assuming you want to use any of these time frames:
    - 5 Minutes
    - 15 Minutes
    - 30 Minutes
    - Hourly
    - 3 Hours
    - Daily
    - Weekly
    - Monthly

To continue the example, let's say you want to change the interval of the system to be 5 Minutes instead of Daily. Select any of the rules that use an interval, and click the Edit... button. Select "5 Minutes" from the pull-down list, check the "Apply Interval change to all rules" checkbox, and click Save. Done.

Thinking Stuff System Update Screen - Trading Rules

Thinking Stuff System Update Screen - Trading Rules


The screenshot on the left is the "before" shot - you can see down the right hand side that all the rules are "Daily". Then on the right is the "after" shot - everything is now 5 Minutes. That took about 6 clicks.

Why nothing less than 5 Minutes?

Because the 4 years of data I have now, without 1 minute data, takes up about 1.5Gb for each currency. Multiply that by maybe 5 or 6 currencies you might want to backtest on, it all adds up very quickly.

Add to that the time it would take to backtest a system based on 1 minute data.

Add to that Oanda's API gives you about 500 candles of history, it means if the computer/internet/electricity went down, you'd have only 500 minutes (~8.5 hours) in order to get it up again before you'd start having holes in your historical data.

Taking all that into consideration, I decided that 5 minutes was the "safest" minimum interval. 500 x 5 minutes is about 1.7 days. If you're still not online after that time, you'll be making the call to Oanda to purchase their ridiculously expensive historical data (like $40 per month per currency or something).


9. Can orders that have been executed be sent to an email address? The benefits of this would be to receive an alert via my mobile phone when I'm out (just need to make sure that the email message doesn't have any more than 150 characters!). Hopefully the alerts that are sent via email are also within the 150 character limit!

In Japan we can receive emails on our mobile phone. When I left Australia they had only SMS. Has it changed? Anyway, yep, email alerts are included, if you specify. I'll make sure the message is brief.

You can specify zero, one or many email addresses to send the alert to. Alerts are triggered on Order Placement, Order Cancelled, Trade Entered, Trade Exited. You specify which of those you want to be informed about.


10. Just to confirm: this program allows you to automatically trade any system that is programmed into it?

This program allows you to create trading systems by specifying, one-by-one, the rules that you want.

Rules are created by selecting options from pull-down lists, and sometimes entering numbers, like the Bollinger period (yes, sorry, a bit of typing involved :-).

It can then backtest that system. It spits out Excel files with the summary, and a listing of all trades it would have entered. Then an Excel Macro I created pretties up a nice chart so you can see exactly what the system is trying to do.

If you're satisfied with that, you let it loose on your demo account.

And if you're satisfied with that, you let it loose in the real world.

With the backtesting, you just need data from somewhere. Anywhere. But with the demo and real trading, you need the API from that company.


11. Lastly, would it be okay if I informed my visitors about your site?

Please. The more comments/free discussion the better. But...

I guess I'm maybe 2 months away from getting this working for myself.

Then maybe another 4 months after that (give or take) to getting it to something resembling a commercial application (if I decide it's worthwhile to make it into a commercial application).

And then, if I did decide to sell it, there's the thing of money. It uses a MySQL database, which is free for personal use, but needs a licence if it's used with a commercial application. I'm not sure of the exact price, but that'd be a couple of hundred dollars.

Then the Oanda API is $600 to buy. The DynaOrder one, for use with FXCM and the like, is cheaper ($250), but has no historical download facility that I can see. Well, it can get the latest Bid and Ask prices, but I can't see anything like Oanda's "Get the last 500 candles" function.

So before I get a cent of money, the poor user has already forked out $800-$900.

Troubling.


Well, that's all for now.

 

7 Comments:

Anonymous said...

Hi,

did you consider InteractiveBrokers? Minimum account size of 25k$ applies, but API and data are free. They have equal or tighter spreads compared ot OANDA, but charge a fee which amounts to below half a pip.

bmalp

Mon Jun 13, 04:50:34 PM EST  
Mark said...

Hi Mark,

does your Thinking Stuff support the wide spreaded Metatrader API? It is free, as far as I know. There are many brokers, on which could be traded a demo account with that API.
Regards,
Mark

Tue Jun 14, 08:51:22 AM EST  
Sharky said...

Thanks for your comments regarding other APIs. I'll be setting it up to use as many as I can get my hands on.

If anyone knows of others, please list them here.

Tue Jun 28, 12:12:29 PM EST  
Marcel Wissing said...

You are talking about a program that enables trading with oanda.com
Is this program available, working for sale, downloadable?
I would be interested.
Kind regards, Marcel.

Wed Nov 23, 06:22:36 PM EST  
Sharky said...

I replied to Marcel through email, but just for anyone else who's interested:

As of 24 Nov 2005, the program is not yet finished and not ready for download. Maybe in 3 weeks or so the initial release will be available (and we all know initial releases will still contain some bugs).

First to be coded will be the Gain Capital API, then Interactive Brokers, and then Oanda.

Because the Oanda API costs $600 up-front, people will (probably) want to trial my program with Gain or IB first, as those APIs are free. And if it works, and they want to switch to Oanda, that will be possible. But it means the other two will be finished first.

Thu Nov 24, 12:30:26 PM EST  
Anonymous said...

I have checked (Forex)
THe spread of GAIN is quite big. 3-5 pips
The spread of Interactive brokers is better : 1-3-4 pips.
But you have to add 0.5 pip for costs (commision) 0.25 pip to open and 0.5 pip to close (well not in pips but in dollar 2.50 dollar per action of 100.000 units.
Oanda is obviously best.
Regards, Marcel.

Fri Nov 25, 01:54:18 AM EST  
Sharky said...

Thanks Marcel.

The truth is that I mostly coded the interface with Oanda, but put it to one side to delay the payment of the $600.

Anyway, I'll get cracking.

Fri Nov 25, 01:38:06 PM EST  

Post a Comment

<< Home