# Excel FX autotrader



## MS+Tradesim (10 March 2009)

So for interest's sake, per stormin's suggestion, I am starting a new thread to update on my effort to develop an FX autotrader using Excel. Having said that, it can also be relatively easily adapted to trade anything on IB. This for me is a major undertaking given that this is the FIRST time I have ever tried programming.

The last error I discovered resulted in the order placing module under a certain condition to continue looping without ever exiting resulting in a potentially infinite number of new orders being sent. Catastrophically bad...!

I think I've isolated and fixed that, but we'll see.

Once I'm fully operational I hope to go into some detail on how I'm doing it (without disclosing the exact trading system). Due to a long discussion with wabbit today, I also hope to start learning MQL4 and learn to write EAs from scratch, as I recognise the cumbersome nature of this exercise. 

Anyways, I have the relevant charts open in Metastock, and here is a pic of my trading spreadsheet. It's basically the IB sample sheet with a whole bunch of my own code and buttons added.

Theoretically, when it's running I don't need to do anything - but each of the buttons can be used for either manual trading (when auto off) or for overriding the auto if needed, though I've yet to add that functionality.

There actually seem to be quite a few people here who write their own autotrader's using C++/# or whatever. Would be good to hear from more about ins and outs, etc. Would probably really benefit us programming noobs.

EDIT: Yes, looping error has been fixed!!!  Just did exactly what it was meant to!!!! It has now gone through several full cycles of ordering/modifying/closing/cancelling/etc successfuly. :alcohol:

I'm excited!


----------



## Stormin_Norman (10 March 2009)

when something bad (or potentially bad) happens we have a saying


'a cashtastrophy'.


----------



## MS+Tradesim (11 March 2009)

Think I have most of the problems fixed now. I've substantially rewritten the main program. One thing I eliminated was modules having more than one exit point (for the module, not for trades). I think that was causing unnecessary looping and incorrect order placing by having multiple redundant triggers. By rewriting I also found a bunch of logic errors that were resulting in unnecessary order cancellations and resubmissions. 

3 days of bug removals so far!


----------



## wabbit (11 March 2009)

MS+Tradesim said:


> 3 days of bug removals so far!




Is that all!  Keep going then! 

Are functions working better for you than Subs?



wabbit


----------



## Stormin_Norman (11 March 2009)

great work! 

is this a model of your actual trading method? or another model of trading youre using?

itll be good to see how it goes forward testing. its amazing how much discretion is still used in a mechanical system. im trying to code up the franklin based on my system, and the initial rules werent enough. we've had to do 4 versions just to get the entry point correct and have the computer take into account things i as a trader didnt realise i really did (things like support/resistance, movement of other currencies, viewing of the chart for a longer time period etc). now just have to move onto the hard part - exits!

working through the logic steps and seeing the outcomes, and limitations (and strengths) of automated trading is probably 70% of the lesson. the coding of the syntax is no where near as challenging when you have step by step method of what you want to achieve. 

if you can create such a complicated excel sheet with google, i think youd be able to create a MT4 (or other platform) language with consummate ease.


----------



## MS+Tradesim (11 March 2009)

wabbit said:


> Is that all!  Keep going then!




 How long should it take? 



> Are functions working better for you than Subs?




Haven't started with them yet, but I have tidied up the number of sub calls and the way they operate; also got rid of "Set".



Stormin_Norman said:


> is this a model of your actual trading method? or another model of trading youre using?




It's my strategy which I trade manually. However, it's time intensive as I need to adjust/place/cancel orders every 5mins. The time plus the human error factor adds up to lots of headaches. Hence, my effort to automate it. The beauty of what I'm doing though, is once it's fully operational, I will have a template for other strategies I'll develop.



> its amazing how much discretion is still used in a mechanical system.



Thankfully, mine is completely rule based so it can be automated with relative ease (relative to the skill of the programmer  ).



> if you can create such a complicated excel sheet with google, i think youd be able to create a MT4 (or other platform) language with consummate ease.




Yep, I will be looking at learning MQL4 and writing it up - that's my next goal.

Update: it's been running beautifully now since 4pm. I've only encountered one problem since then but that wasn't in the program.


----------



## Stormin_Norman (11 March 2009)

well done on getting your system onto a computer!


----------



## MS+Tradesim (11 March 2009)

Thanks.

I've just turned it off. It ran for about 6 hours with no problems and did about 10 round trips. Next thing to focus on is getting the order trigger method right to minimise slippage. It's tracking slightly higher slippage than backtested. Only a few pips here and there but it makes a big difference to my strategy results.

To give some idea of what I'm trying to achieve, this is some backtest results. I didn't trade the circled area in real life. I sat it out until I was happy the drawdown phase was finished. That was achieved by backtesting every few days and waiting until the simmed equity curve was recovering. So stormin, there is an element of discretion in whether or not to trade overall, but not for any given individual trade. Saved a lot of real life money. When I'm happy with the autotrader I hope to report forward test results which are the only ones that really count.

This test was at 1% risk. Optimum results are achieved at about 1.8-2% risk. A very smooth curve with highly reduced returns can be achieved by using a set dollar risk of $500 per trade.

Edit: I'll be ecstatic if the real results are half as good. This backtest takes every valid signal it can afford. Manually on live trading, I've been taking way fewer trades as the time intensiveness of managing each trade was quite high - another reason why I want it fully automated.


----------



## pilbara (12 March 2009)

MS+Tradesim said:


> I didn't trade the circled area in real life. I sat it out until I was happy the drawdown phase was finished. That was achieved by backtesting every few days and waiting until the simmed equity curve was recovering.



Good work with getting your system up and running, it's the most amazing thing, an Excel spreadsheet that makes money.  Usually Excel spreadsheets just help you to add up your losses 

I agree with the "virtual" equity curve, this is a good filter.  I think you should have the system doing virtual trading on all signals (even when above your leverage limit), and use this to help choose when the system should make "real" trades.


----------



## barney (12 March 2009)

Hey lads .... been trading FX small time for a while now .... total novice with anything related to programming, but you guys have got me interested 

I like to do the hard yards, so just give me a hint where I should start looking so I can start learning the stuff I need to try this auto business ....

My system is basically discretionary, but only when certain criteria/indicators etc are met....

Main question for a start ..... Is it actually possible to 'programme' in things like for example .... 

"entry after X MA crosses Y MA, but only if the X period Stochastic has crossed below 20 and is now above 20 etc etc ........"     are these the types of parameters you can programme in ?? ........ that would be interesting stuff  ... I might actually get more sleep at night   ... lol  

Cheers.


----------



## CanOz (12 March 2009)

Excellent work MS, how many hours so far have you put into this?

Cheers,


CanOz


----------



## wabbit (12 March 2009)

barney said:


> Main question for a start ..... Is it actually possible to 'programme' in things like for example ....
> 
> "entry after X MA crosses Y MA, but only if the X period Stochastic has crossed below 20 and is now above 20 etc etc ........"     are these the types of parameters you can programme in ?? ........ that would be interesting stuff  ... I might actually get more sleep at night   ... lol




If you can write down the logic, it can be programmed.... within reason of course 

Yes, your "system" can be scripted.



Hope this helps.

wabbit


----------



## MS+Tradesim (13 March 2009)

Didn't get near this project yesterday but back at it today. Refining the trigger and order types to minimise slippage. I will probably run a day or two on each trigger type to collect enough samples to make a decision as to what will work best on auto. I use Booktrader on IB for manual which gives a great deal of flexibility - I can quickly change order type or price. But the auto will have to work a bit more simply at least until I have the time and energy to set up all the different variables. 

*Pilbara*



> I think you should have the system doing virtual trading on all signals (even when above your leverage limit), and use this to help choose when the system should make "real" trades.




I agree.


*Barney*

Wabbit is the person to talk to about all things programming when it comes to trading.

Personally, if I knew six months ago what I knew now, I would start by getting familiar with Metatrader4 (MT4) and learning Meta Quotes Language 4 (MQL4). If you don't already know, MT4 is a programmable trading platform used by most of the bucketshops and some reputable FX brokers. MQL4 is the language you program it with. 

The way I've done things is very round-about and inelegant but I am enjoying the learning and getting used to thinking the way a computer operates.

*Canoz*

I've been working on the trading strategy for about 3 mths. I believe it will only operate well in these current volatile conditions. I will probably replace it with a longer-term trend following system at some point. 

The basic manual trading spreadsheet only took about one or two days to put together. All I did for it was create some position sizing functions based on live data and added some database queries to grab the trading signals from Metastock. Beyond that it was just a matter of making some buttons and assigning various simple macros to them.

The auto trading program however has taken about 2 weeks so far. I am new to programming and this is my first project. I'm very happy with the outcome so far.


----------



## Stormin_Norman (13 March 2009)

youre kicking ass!

it good to see a couple of different people getting into programming up autotraders.

when i first started i totally discounted them, now i think they will become my only method of trading.


----------



## MS+Tradesim (13 March 2009)

This is the guts of it. The first sub, Autostart(), is basically redundant but there are some things I want to add and I will probably put them in there so it stays for the time being. Something I will do on the next version is define all the variables as an appropriate data type to keep the memory happy and replace a lot of subs with functions...per Wabbit's suggestion. 

Also, copy and paste to here lost all the formatting and I can't be stuffed indenting everything.
========================================


*Sub AutoStart()*
    ' Checks for safety trigger
    Trigger = Sheets("Orders").Range("V1")
    If Trigger = 1234 Then
        Sheets("Orders").Range("V9").FormulaR1C1 = "ON"
    End If
    ' Begin loop
    AutomateTrading
End Sub

*Sub AutomateTrading()*
    Trigger = Sheets("Orders").Range("V1")
    If Trigger <> 1234 Then Exit Sub Else
    If Trigger = 1234 Then
        ' Clear all non-open orders and refresh data
        RefreshData
        Clear
        EURJPY
    End If
End Sub

*Sub EURJPY()*
    'Set all variables
        EJEntry = Sheets("DataSheet").Range("AA4")
        EJLow = Sheets("DataSheet").Range("AB4")
        EJHigh = Sheets("DataSheet").Range("AC4")
        EJFilter = Sheets("DataSheet").Range("AQ4")
        EJQty = Sheets("DataSheet").Range("M2")
        EJLO = Sheets("Orders").Range("S18")
        EJSO = Sheets("Orders").Range("S22")
        EJOT = Sheets("DataSheet").Range("AW4")
        EJC = Sheets("Orders").Range("S45")
        EJCCon = Sheets("Orders").Range("L45")
    On Error Resume Next

    ' Long Side Orders
        ' Place initial Long order
            Select Case EJEntry > EJLow And EJFilter >= 70 And EJQty = 0 And EJOT = 1
                Case True
                BuyEURJPY
            End Select
        ' Cancel redundant Long order
            Select Case EJLO = "PreSubmitted" And EJFilter < 70 And EJQty = 0 And EJOT = 1
                Case True
                CancelEURJPY
            End Select
        ' Close Long without reversing
            Select Case EJQty > 0 And EJFilter > 30 And EJOT = -1
                Case True
                CloseEURJPY
            End Select
        ' Replace Close with Buy
            Select Case EJC = "PreSubmitted" And EJFilter >= 70 And EJCCon = "BUY"
                Case True
                CancelEURJPY
                BuyEURJPY
            End Select
        ' Replace Buy with Close
            Select Case EJEntry > EJLow And EJFilter < 70 And EJLO = "PreSubmitted" And EJQty < 0 And EJOT = 1
                Case True
                CancelEURJPY
                CloseEURJPY
            End Select

    ' Short Side Orders
        ' Place initial Short order
            Select Case EJEntry < EJHigh And EJFilter <= 30 And EJQty = 0 And EJOT = -1
                Case True
                SellEURJPY
            End Select
        ' Cancel redundant Short order
            Select Case EJSO = "PreSubmitted" And EJFilter > 30 And EJQty = 0 And EJOT = -1
                Case True
                CancelEURJPY
            End Select
        ' Close Short without reversing
            Select Case EJQty < 0 And EJFilter < 70 And EJOT = 1
                Case True
                CloseEURJPY
            End Select
        ' Replace Close with Sell
            Select Case EJC = "PreSubmitted" And EJFilter <= 30 And EJCCon = "SELL"
                Case True
                CancelEURJPY
                SellEURJPY
            End Select
        ' Replace Sell with Close
            Select Case EJEntry < EJHigh And EJFilter > 30 And EJSO = "PreSubmitted" And EJQty > 0 And EJOT = -1
                Case True
                CancelEURJPY
                CloseEURJPY
            End Select
    EURUSD
End Sub

****Followed by 3 more modules for other FX pairs then....*****

...
...
    SetDelay
End Sub

*Sub SetDelay()*
    Trigger = Sheets("Orders").Range("V1")
    If Trigger <> 1234 Then Exit Sub Else
    If Trigger = 1234 Then
        ' Set loop delay
        Application.OnTime Now + TimeValue("00:00:30"), "AutomateTrading"
    End If
End Sub

*Sub AutoStop()*
' End AutoStart macro by deleting trigger code
    Sheets("Orders").Range("V1").ClearContents
    Sheets("Orders").Range("V9").FormulaR1C1 = "OFF"
End Sub


----------



## MS+Tradesim (13 March 2009)

Ps. And no, it is not possible to reverse engineer my trading method from that post so don't waste your time.  

Pps. There are a bunch of calls to things like CloseEURJPY or CancelEURJPY or SellEURJPY etc. They call a bunch of minor subs (sub-procedures) that execute the relevant command by using the modules IB included on the spreadsheet. There is some redundant duplication in those processes which I will eliminate in the next version.

*Wabbit* I got _Excel VBA Programming for Dummies_ and it has some decent (IMHO) chapters in there on data types and sub/functions so I will be using all that in the next version.


----------



## nizar (13 March 2009)

MS+Tradesim said:


> Edit: I'll be ecstatic if the real results are half as good. This backtest takes every valid signal it can afford. Manually on live trading, I've been taking way fewer trades as the time intensiveness of managing each trade was quite high - another reason why I want it fully automated.




Very impressive MS.

Have you decided how you are going to rank the trade?
Have you montecarloed these different possible outcomes on TradeSim ?

I'd be keen to see full backtested stats.


----------



## MS+Tradesim (13 March 2009)

nizar said:


> Have you decided how you are going to rank the trade?




Yep. There is no trade ranking. If it signals and there's spare margin according to the overall MM strategy then it takes it. 



> Have you montecarloed these different possible outcomes on TradeSim ?
> 
> I'd be keen to see full backtested stats.




Yes, and I will post some later.


----------



## Stormin_Norman (13 March 2009)

MS+Tradesim said:


> Ps. And no, it is not possible to reverse engineer my trading method from that post so don't waste your time.




ill wait patiently to purchase it for $195 with the free e-book. :


----------



## MS+Tradesim (13 March 2009)

Stormin_Norman said:


> ill wait patiently to purchase it for $195 with the free e-book. :




  

The book will be _"How to write **** EAs and convince people to buy them"._


----------



## wabbit (13 March 2009)

MS+Tradesim said:


> *Wabbit* I got _Excel VBA Programming for Dummies_ and it has some decent (IMHO) chapters in there on data types and sub/functions so I will be using all that in the next version.





The code is starting to look neater too!  With less subs being called, the code maintenance and debugging should be getting easier?  I notice you still have the reading the data from the pages in each sub routine; as mentioned before, I'd take all of them out and one function which reads the worksheet data into variables.

As for the data types, you'll find just about all of that information in the help files too!  The Dummies book might explain it better in the first instance, but now that you know what the differences are, you can just refer to the help functions for the info.  When you're done, donate the book to your local library!

The use of sub vs function is debatable, but as we discussed I prefer to use functions because they return a value.  Combined with "on error" you can trap errors at each function level; if the function returns false you can stop the app and find out why.  Continuously calling sub routines just ends up hurting!  (On error... is a poor-man implementation of the much more powerful concept available in programming languages like C/C++ etc, which is Try...Catch where you can Throw specific errors and have your code deal with these errors on a type-by-type, case-by-case basis.  Happy days  )

I know it's a personal preference thing; but if you're going to have a Select Case with only one case, then its the same as an If...Then statement (without an else).  I have never speed tested the two so don't know if one is faster than the other, but I think in readability If...Then is a little easier on the eyes when there is not a list of possbilities.  Also, with Boolean logic (true and false) you wouldn't need to specify the case in an If...Then e.g.

If test Then something

instead of

If test=true Then something


and for the false cases:

If Not test Then something

is the same as

If test=false Then something


As I said, it's a preference thing.


Did you eventually get a matrix of all the routines and function calls?  I started, but then got really pi55ed off with how many places one section of code can visit! so stopped working on it!  There are a lot of efficiencies to be made to optimise the running of the code.


Hope this helps.


wabbit


----------



## MS+Tradesim (13 March 2009)

Hi wabbit,

I have taken all your advice onboard and it will all be implemented in version 2.

My primary goal here was to get _this_ program fully operational. 

As you know, the code I sent you used IF-THEN. I rewrote with Select Case and it 'seems' to run smoother and maybe quicker but I did so many other things I can't tell if that was a difference of note. But in terms of just looking at the code, my eyes seem to follow the Select Case easier than the IF-THEN so as long as it does the same thing I'll leave it this way.

I am still working on an overall map and I agree with the efficiency/optimising part - all of that to come in v2.

Thanks for your ongoing advice.


----------



## barney (13 March 2009)

wabbit said:


> If you can write down the logic, it can be programmed.... within reason of course
> 
> Yes, your "system" can be scripted.
> 
> ...




thanks Wabbit.... you Wascal you  ....  

are we talking logic in the literal sense of language, or a form of computer logic which is related to the programme we are working with? ..... told you I was a novice lol ....



MS+Tradesim said:


> Personally, if I knew six months ago what I knew now, I would start by getting familiar with Metatrader4 (MT4) and learning Meta Quotes Language 4 (MQL4). If you don't already know, MT4 is a programmable trading platform used by most of the bucketshops and some reputable FX brokers. MQL4 is the language you program it with.
> 
> The way I've done things is very round-about and inelegant but I am enjoying the learning and getting used to thinking the way a computer operates.




Good advice MS ....  Had a quick squiz at the computer "language" you guys are dealing with here MS+   ......  holy crap .... how can you understand this stuff  lol .....   I'll keep digging, but I may be *too old* to cotton on to the lingo !!



MS+Tradesim said:


> *Barney*
> 
> Wabbit is the person to talk to about all things programming when it comes to trading.




Yep, gathered that reading through the posts   .... Bit of a S/Sydney supporter myself, so the Bunnies might be an omen !! .... I'll do a bit more research before I pester you lads too much ..... certainly interested in the automation stuff though ...... agree with S/Norm ... it looks the way into the future, particularly if a lot of big punters are playing the same game ...... I guess the only problem eventuates when too many punters start tracking the same style of programme ..... the big players would be continually trying to adapt their "auto's" to extract the maximum amount of cash from the other players, so the game would be continually evolving ..... for that reason, I've always thought us small players should concentrate on the "meat" in the middle of the trend, and be happy with small pickings .... just a theory of course  .....   

Cheers lads ... gotta go ... have a gig tonight ...... the Les Paul waits to hammered, caressed and bent into tonal (sometimes atonal .... on purpose of course !!)  artistry .... lol.


----------



## MS+Tradesim (13 March 2009)

barney said:


> Cheers lads ... gotta go ... have a gig tonight ...... the Les Paul waits to hammered, caressed and bent into tonal (sometimes atonal .... on purpose of course !!)  artistry .... lol.




Have a good nite. I envy you! This is my axe which I _might_ get to pick up again some time soon. Lol.


----------



## barney (14 March 2009)

MS+Tradesim said:


> Have a good nite. I envy you! This is my axe which I _might_ get to pick up again some time soon. Lol.




Nice !!!!!!!!  

Trading must be going well to afford that MS  ........   I'd nearly consider a swap of my 1972 "Les" for that (been my friend for over 30 years) ...... but I'm pretty sure you wouldn't lol ....


----------



## bingk6 (14 March 2009)

MS+Tradesim said:


> Thanks.
> 
> I've just turned it off. It ran for about 6 hours with no problems and did about 10 round trips. Next thing to focus on is getting the order trigger method right to minimise slippage. It's tracking slightly higher slippage than backtested. Only a few pips here and there but it makes a big difference to my strategy results.




Hi MS,

Congrats on getting your system onto an automated platform, certainly no easy task and you appear to have done quite well.

Re: the slippage that you have been experiencing, your findings certainly concur with what I have found with my systems and is one of the reasons why I don't assume or rely on backtested results. With an EOD system or  weekly system, you can be certain of the fill because of the auction process that takes place at the beginning of each bar, which means that the fills on your backtested results match with your actual fills. With an intraday system, you don't have that luxury because you cannot say I want a fill at the opening price of the next bar, as there is no auctioning process between bars. I have found that there can be significant differences between what you expect your fill price to be and the actual fill price.

I have tried a number of ways (at different times) to overcome these discrepancies, including
1) making sure that the order is submited only when there is 3 seconds or less left in the current bar (I trade off 1min bars) to try and get as close to the opening price of the next bar and
2) Examine the bid and ask prices just prior to pushing the button to make sure that the spread is not too wide and if it is, to abandon the order and
3) Start off initially with a LMT order to try and trigger a favourable fill price and if not filled by a certain time within the current bar to then change it into a MKT order to ensure a fill.

To date, these different options have given some minor improvements, but not enough for me to want to depend on backtested results. I have also found on vary rare occassions that even MKT orders do not execute immediately and when they do, which can be up to 30secs after submision, you can imagine that the fillcan be nothing like the fill that you are expecting.

I have to say that this inability to depend on backtested results is causing the process to take longer than I like it to. Every change has to be put through the simulator to be monitored over a period of time and that can take a long time indeed.

Finally, one last piece of advice, when your system submits or amends a order, always make sure that your code remembers what it has done and hence can successfully check that previous instructions have taken place correctly before moving on. Your code cannot assume anything, it must check for everything and be aware of its status at all times, just as a human trader would be.


----------



## pilbara (14 March 2009)

MS+Tradesim said:


> Next thing to focus on is getting the order trigger method right to minimise slippage. It's tracking slightly higher slippage than backtested. Only a few pips here and there but it makes a big difference to my strategy results.



I was wondering when using the Interactive Brokers ECN, are you using the Depth of Market to place limit orders?  This should be an advantage of an ECN compared to marketmaker brokers where you are forced to be price takers.  But also I think in real trading the IB ECN is aimed for large traders working with 10 or more standard contracts, and maybe small orders don't get the priority.


----------



## MS+Tradesim (14 March 2009)

barney said:


> Trading must be going well to afford that MS  ........   I'd nearly consider a swap of my 1972 "Les" for that (been my friend for over 30 years) ...... but I'm pretty sure you wouldn't lol ....




Thankfully I got this one for cost price. The owner got it for cost from a dealer but decided he wanted a Les Paul so he onsold it for the same price still brand new. He'd never played it.  And, no I definitely wouldn't swap it for anything else. 



bingk6 said:


> I have tried a number of ways (at different times) to overcome these discrepancies, including...<SNIP>....
> 2) Examine the bid and ask prices just prior to pushing the button to make sure that the spread is not too wide and if it is, to abandon the order and




One thing I've done is to setup dynamic order pricing in the spreadsheet. It grabs the spread and divides by two then adds/substracts that from the entry price to create an offset which is used for the trigger price - this is constantly updated. So no matter how wide or narrow the spread the trigger is offset by an appropriate amount to compensate. That has trimmed some slippage out. I am still playing around with limit and market orders similar to what you've tried. 



> Your code cannot assume anything, it must check for everything and be aware of its status at all times, just as a human trader would be.




That's a good point and something that I will spend some time on. 



pilbara said:


> I was wondering when using the Interactive Brokers ECN, are you using the Depth of Market to place limit orders?  This should be an advantage of an ECN compared to marketmaker brokers where you are forced to be price takers.  But also I think in real trading the IB ECN is aimed for large traders working with 10 or more standard contracts, and maybe small orders don't get the priority.




Dunno about size and priority, but yes, you can use DOM. Also IB has a range of orders and trigger methods giving quite a lot of control. I am still testing different ideas to optimise fill price. The difference with IB is more than just being ECN. Their setup is geared for professional traders and institutions and account managers so it can be as complex as you want.


----------



## pilbara (14 March 2009)

another thing to check regarding slippage is the effect of time delays in the system (latency).  From what I've seen IB's ECN updates prices very quickly.  If your system is running in Australia there will be a minimum half second delay (quarter second each direction) between when a price is published on IB in USA and when your order arrives on their server.  Also you could measure your processing time and make sure that's not delaying things too much.  Because IB is setup for professionals then you are competing on speed and latency might be an issue.  Running your system on a VPS server (Virtual Private Server) in USA might get you a hundredth of a second away from the IB server, instead of a quarter of a second here in Aus.


----------



## MS+Tradesim (14 March 2009)

Hi Pilbara,

As far as I know, my orders actually go through IB's server in Hong Kong and being an ECN, other orders could be coming from anywhere in the world, not just the USA. But I take your point.

Anyways FWIW, here are the results for day one. I ran it from about 4pm till about 9:30pm QLD time. When it goes live it will trade later. Currently set to trade EURUSD, EURJPY, GPBUSD and USDJPY. 

Nominal sim account equity of about 29k, risking 0.8% per trade. I don't think there was ever more than about 8k up as margin. Results are in AUD. Not sure of the R:R yet as I still need to correlate the trades with the initial stops. The last three trades were closed prematurely. Don't know yet how they would have panned out had I left them to exit properly.


----------



## barney (14 March 2009)

MS+Tradesim said:


> Thankfully I got this one for cost price. The owner got it for cost from a dealer but decided he wanted a Les Paul so he onsold it for the same price still brand new. He'd never played it.  And, *no I definitely wouldn't swap it for anything else*.





Funny ..... I figured that would be your reply ... lol .... it certainly is a nice piece of equipment ..... of course the old "Les", which is now worth over 5 times what I paid for it 30 years ago is not to be sneezed at  ........ Cheers.


----------



## Stormin_Norman (14 March 2009)

sexy graph! what time period is that over?


----------



## pilbara (15 March 2009)

MS+Tradesim said:


> Dunno about size and priority, but yes, you can use DOM. Also IB has a range of orders and trigger methods giving quite a lot of control. I am still testing different ideas to optimise fill price.



I'm first trying to get an EA to work with a marketmaker broker because they have a simple pricing model.  Once I can get this to work then I'll try to understand ECN trading.  I think the main difference is that a marketmaker guarantees fills at a published price for a certain time (unless they have a serious problem with liquidity).  Every price has a "time to live" during which they will automatically execute a limit order.  This "time to live" might only be a few seconds but it means there is less chance of entry slippage with a marketmaker (an order is either filled or killed). This makes system development a bit easier.


----------



## MS+Tradesim (16 March 2009)

The trading strategy with a few tweaks also works on the SPI. So I'm adding functionality for the autotrader to trade the SPI during the ASX session and then trade FX after that.

*Stormin*

Which chart do you mean? The first one I put up in post #8 was a backtested equity curve over about 5-6mths. 

The excel chart in post #30 was a forward test over about 5-6 hours on Friday afternoon/evening.


----------



## Stormin_Norman (16 March 2009)

500% return in 6 hours.

BOOYA!


----------



## MS+Tradesim (16 March 2009)

Stormin_Norman said:


> 500% return in 6 hours.
> 
> BOOYA!




Not sure what you're looking at Stormin but it was more like about 11%.


----------



## ojm (16 March 2009)

MS+Tradesim said:


> Not sure what you're looking at Stormin but it was more like about 11%.




Post 30? 200 to 1000. More than 11%?


----------



## MS+Tradesim (16 March 2009)

Oh, I see what you're thinking. No, that is just closed trade equity. As I said in that post the account equity was about 29k and about 8k was used in margin. But I do apologise - I wasn't clear that the chart was only closed trade equity, not growth in total equity.

So the account return was about 900/29000 = 3% or about 11% ROI if only the used margin is considered.


----------



## ojm (16 March 2009)

MS+Tradesim said:


> So the account return was about 900/29000 = 3% or about 11% ROI if only the used margin is considered.




That clears it up. 

Just a question for you, how long have you been trading currencies? I've just started learning about it all. Any tips you could offer a newcomer? Any resources that you find useful?


----------



## Stormin_Norman (16 March 2009)

read read and read some more.

test systems. dont trade willy nilly. 

demo until u find one that works. then put a small amount into an account and use it.

google 'babypips forum' and 'forexfactory'.

both are excellent resources.


----------



## MS+Tradesim (16 March 2009)

ojm said:


> That clears it up.
> 
> Just a question for you, how long have you been trading currencies? I've just started learning about it all. Any tips you could offer a newcomer? Any resources that you find useful?




Hi OJM,

I'm relatively new to FX (but not new to trading) so I'm not the person to ask about FX.

But use the search function on the forex sub-forum here and you will find a number of very informative threads for newbies to FX. Also, have a look for the sites that Stormin mentioned in the post above.

-------------------------

General update:

The autotrader took one punt on the SPI today and it went in my favour. Backtesting indicates about 48% win rate for SPI at W:L about 2:1. Might start looking at other futs/indices and see what can happen.


----------



## ojm (16 March 2009)

Stormin_Norman said:


> read read and read some more.
> 
> test systems. dont trade willy nilly.
> 
> ...




Thanks Stormin. Don't plan on putting real dollars on the line for a long time yet - see too many posts on various forums with people getting burnt. I got a demo account and have managed to get it from $5000 to $8600 (some big losses but some bigger gains). But am no where near confident enough to use real $.

Got the Babypips eBook printed out and have been studying that, and some other eBooks. Also discovered the ForexFactory website. I feel like maybe I'm on the right track if you are recommending them. 

Thanks guys, I'll leave this thread for MS and his Excel.


----------



## MS+Tradesim (16 March 2009)

Some backtesting sim results for Nizar...

This is a 20,000 run MC. I've cut out some insignificant details and left the meat.

*Trade Parameters* 
Initial Capital:  $25,000.00                    
Portfolio Limit:                                            50.00%                        
Maximum number of open positions:                          4                             
Default Position Size Model:                                Fixed Percent Risk            
Percentage of capital risked per trade:                     1.00%                         
Position size limit:                                        100.00%                       
Portfolio Heat:                                             100.00%                       
Pyramid profits:                                            Yes                           

*Simulation Stats * 
Number of trade simulations:                                20000                         
Trades processed per simulation:                            3183                          
Maximum Number of Trades Executed:                          2838                          
Average Number of Trades Executed:                          2834                          
Minimum Number of Trades Executed:                          2829                          
Standard Deviation:                                         1.76                          

*Profit Stats * 
Maximum Profit:                                             $319,792.80 (1279.17%)        
Average Profit:                                             $283,916.41 (1135.67%)        
Minimum Profit:                                             $251,590.29 (1006.36%)        
Standard Deviation:                                         $10,260.33 (41.04%)           
Probability of Profit:                                      100.00%                       
Probability of Loss:                                        0.00%                         

*Percent Winning Trade Stats* 
Maximum percentage of winning trades:                       39.88%                        
Average percentage of winning trades:                       39.74%                        
Minimum percentage of winning trades:                       39.63%                        
Standard Deviation:                                         0.05%                         

*Percent Losing Trade Stats* 
Maximum percentage of losing trades:                        60.37%                        
Average percentage of losing Trades:                        60.26%                        
Minimum percentage of losing trades:                        60.12%                        
Standard Deviation:                                         0.05%                         

*Average Relative Dollar Drawdown Stats* 
Maximum of the Average Relative Dollar Drawdown:            $1,085.05                     
Average of the Average Relative Dollar Drawdown:            $1,026.61                     
Minimum of the Average Relative Dollar Drawdown:            $963.21                       
Standard Deviation:                                         $22.13                        

*Average Relative Percent Drawdown Stats* 
Maximum of the Average Relative Percent Drawdown:           0.8592%                       
Average of the Average Relative Percent Drawdown:           0.8569%                       
Minimum of the Average Relative Percent Drawdown:           0.8547%                       
Standard Deviation:                                         0.0008%                       

*Maximum Peak-to-Valley Dollar Drawdown Stats * 
Maximum Absolute Dollar Drawdown:                           $109,222.87                   
Average Absolute Dollar Drawdown:                           $98,864.24                    
Minimum Absolute Dollar Drawdown:                           $88,143.31                    
Standard Deviation:                                         $3,523.71                     

*Maximum Peak-to-Valley Percent Drawdown Stats* 
Maximum Absolute Percent Drawdown:                          40.8850%                      
Average Absolute Percent Drawdown:                          38.9103%                      
Minimum Absolute Percent Drawdown:                          36.5618%                      
Standard Deviation:                                         0.9958% 

**** The MaxDD should never be experienced. Trading would cease in real life at a certain drawdown point and continue on sim if/until equity curve recovers.


----------



## Stormin_Norman (16 March 2009)

do u have/know where to get historical data for indexes/futures?

1 minute data preferably.


----------



## MS+Tradesim (16 March 2009)

More for Nizar. Here's a fairly average single sim result. Keep the MaxDD caveat above in mind. Also as mentioned, the equity curve smoothness and MaxDD can both be significantly improved by using a Fixed Dollar Risk model, but at the expense of returns halving.

======================

*Trade Parameters   * 
Initial Capital:                                            $25,000.00                    
Portfolio Limit:                                            50.00%                        
Maximum number of open positions:                           4                             
Automatically Use Position Size Model from database:        No                            
Default Position Size Model:                                Fixed Percent Risk            
Percentage of capital risked per trade:                     1.00%                         
Position size limit:                                        100.00%                       
Portfolio Heat:                                             100.00%                       
Pyramid profits:                                            Yes                           

*Trade Summary * 
Earliest Entry Date in the Trade Database:                  2/10/2008-12:15:000           
Latest Entry Date in the Trade Database:                    13/03/2009-22:20:000          
Earliest Exit Date in the Trade Database:                   2/10/2008-12:30:000           
Latest Exit Date in the Trade Database:                     13/03/2009-22:35:000          

*Start Trade Entry Date:*                                     2/10/2008-12:15:000           
Stop Trade Entry Date:                                      13/03/2009-22:20:000          
First Entry Date:                                           2/10/2008-12:15:000           
Last Entry Date:                                            13/03/2009-22:20:000          
First Exit Date:                                            2/10/2008-12:30:000           
Last Exit Date:                                             13/03/2009-22:35:000          

*Total Trading duration: *                                    162 days                      

*Profit Status:*                                              PROFITABLE                    
Starting Capital:                                           $25,000.00                    
Finishing Capital:                                          $315,420.52                   
Maximum Equity/(Date-Time):                                 $301,389.37 (13/03/2009-21:05:000)
Minimum Equity/(Date-Time):                                 -$2,021.29 (2/10/2008-20:35:000)
Gross Trade Profit:                                         $1,392,522.57 (5570.09%)      
Gross Trade Loss:                                           -$1,102,102.06 (-4408.41%)    
Total Net Profit:                                           $290,420.52 (1161.68%)        
Average Profit per Trade:                                   $102.44                       
Profit Factor:                                              1.2635                        
Profit Index:                                               20.86%                        
Total Transaction Cost:                                     $86,403.63                    
Daily Compound Interest Rate:                               1.5771%                       
Annualized Compound Interest Rate:                          30136.7660%                   

*Trade Statistics* 
Trades Processed:                                           3183                          
Trades Taken:                                               2835                          
Partial Trades Taken:                                       0                             
Trades Rejected:                                            348                           
Winning Trades:                                             1129 (39.82%)                 
Losing Trades:                                              1706 (60.18%)                 
Breakeven Trades:                                           0 (0.00%)                     

Largest Winning Trade/(Date-Time):                          $17,973.40 (6/03/2009-18:00:000)
Largest Losing Trade/(Date-Time):                           -$2,989.03 (9/03/2009-19:00:000)
Average Winning Trade:                                      $1,233.41                     
Average Losing Trade:                                       -$646.02                      
Average Win/Average Loss:                                   1.9093                        

*Consecutive Trade Statistics  * 
Maximum consecutive winning trades:                         8                             
Maximum consecutive losing trades:                          15                            
Average consecutive winning trades:                         1.82                          
Average consecutive losing trades:                          2.75                          

*Trade Expectation Statistics* 
Normalized Expectation per dollar risked:                   $0.10                         
Maximum Reward/Risk ratio:                                  14.32                         
Minimum Reward/Risk ratio:                                  -1.17                         
Average Positive Reward/Risk ratio:                         $1.05                         
Average Negative Reward/Risk ratio:                         -$0.54                        

*Relative Drawdown * 
Maximum Dollar Drawdown/(Date-Time):                        $16,733.22 (20/02/2009-17:40:000)
Maximum Percentage Drawdown/(Date-Time):                    8.8080% (20/02/2009-17:40:000)

*Absolute (Peak-to-Valley) Dollar Drawdown* 
Maximum Dollar Drawdown:                                    $102,914.28 (38.9500%)        
Capital Peak/(Date-Time):                                   $264,196.47 (28/01/2009-13:20:000)
Capital Valley/(Date-Time):                                 $161,282.19 (25/02/2009-21:35:000)

*Absolute (Peak-to-Valley) Percent Drawdown* 
Maximum Percentage Drawdown:                                38.9500% ($102,914.28)        
Capital Peak/(Date-Time):                                   $264,196.47 (28/01/2009-13:20:000)
Capital Valley/(Date-Time):                                 $161,282.19 (25/02/2009-21:35:000)


----------



## MS+Tradesim (16 March 2009)

Stormin_Norman said:


> do u have/know where to get historical data for indexes/futures?
> 
> 1 minute data preferably.




Don't GO Markets allow you to trade synthetic futures? Otherwise, open an account with IB and subscribe to whatever exchanges you want. You can get tick data and up. Sydney Futures Exchange data is free with them.  At least $45/mth with anyone else, I think.


----------



## Stormin_Norman (16 March 2009)

gomarkets has very little historical data on their platform.

how far back does IB's data go?


----------



## MS+Tradesim (16 March 2009)

Stormin_Norman said:


> gomarkets has very little historical data on their platform.
> 
> how far back does IB's data go?




I think for tick/1min you might be able to go back about 6mths or so...not real sure as I only use 5min and above. For that I can get nearly a year. However, IMO it's not the cleanest historical data. Given what you are trying to achieve you might want to look at something like eSignal Pro or similar. You'll pay but it will be clean and reliable. That's just IMO. Other IB users may disagree.


----------



## MS+Tradesim (17 March 2009)

Bit of an update.

Autotrader works great.

However, I've collected enough data now to backtest with realistic slippage, controlled as well as I can get it. Market orders are fatal. Cumulative slippage at market results in negative expectancy when backtesting.

Result: account blowup guaranteed. 

So the next step is to play around with limit orders.


----------



## pilbara (18 March 2009)

it's a shame that slippage with market orders is a problem for the system.  Is this only slippage on entry, or also a problem on stop-loss exits?

The first thing to double check with IB is whether the orders went through IDEALPRO not IDEAL.

IB always has a deep order book, so I guess they can match a "market" order to whichever price in the book suits them the best at that moment.  If the market is moving fast, and you are buying with the trend, then slippage will be significant.


----------



## MS+Tradesim (18 March 2009)

It's a reversal system so low win rate and often rapid moves away from the trigger area. I'm going to road test limit orders but that will create exit hassles on auto-trading. 

I'm thinking it more likely though that I just come up with a different trading idea where slippage won't cause such a dramatic difference to the results.


----------



## Stormin_Norman (24 March 2009)

hows it coming along MS+T?


----------



## MS+Tradesim (24 March 2009)

Howdy,

Haven't touched it for a week or so. Been trading this great rally on the XAO, which might end this week. Then I'll get back to this project.

Looks like your ideas are coming along well.


----------



## Stormin_Norman (5 April 2009)

hows it going MS+T?


----------



## MS+Tradesim (13 December 2009)

Lol. Hi stormin. I never got back to this. Got too busy with ASX. Since this time I've tried a lot of non-automated ideas on FX and found a few workable ones which I do trade but I'm not running any automated ideas yet. I guess I like watching the DOM too much.


----------

