Coding the Bumblebee

Ah, the excitement and sheer joy that is before us as we learn to code a trade system. I am using TradersStudio as my EOD trading software. Though it has its own programming language, its language is very similar to Visual Basic. So it helps to get a grasp of the VB language and since I’m not a programmer (just one in the making), I’ve elicited the help of an online video tutorial service to assist me in my endeavors to learn programming. Programming can be fun, just like re-grouting your shower. So let’s get to it!

Before we get into the very exciting world of coding a trade system, let’s review why it’s a good idea, and why paper and pencil methods are inferior.

1. Properly coded programs don’t miss trades or make the wrong trades.

2. Coded programs enable the system to test over a vast range of dates and markets that would take the better part of a century if it were attempted by hand.

3. Testing done with a coded program accumulates all manner of data that adds to different ways of viewing your results.

4. Coded programs enable a trade system developer to draw valid statistical inferences because of the vast data that is accumulated.

5. Minor changes to a trade system can be easily programmed and tests can be re-run with minimal effort and time.

Okay, that enough for now. For the Luddites who insist on paper and pencil methods, let me grant this benefit to their antiquated methods.

Manual backtesting ‘programs’ the trader to take trades when signals are generated and take them off when their system dictates.

Trust me though, after you’ve invested enough time in programming, backtesting, optimizing and walking forward, the last thing you’ll want to do is violate your trading system in real-time, thus nullifying all the time and effort you put into developing the system.

I offer below the program code for Bumblebee:

‘ Three parameter system, not always in

Sub Hysterosis (SlowLength As Integer, FastLength As Integer, StdMult As Double)

‘Declare variables

Dim SlowAve As BarArray
Dim FastAve As BarArray

Dim SlowPlus As BarArray
Dim SlowMinus As BarArray

‘Direct where the variable gets its data

SlowAve = Average(Close, SlowLength,0)
FastAve = Average(Close, FastLength,0)

SlowPlus = UpperBolBand(Close, SlowLength, StdMult, 0)
SlowMinus = LowerBolBand(Close, SlowLength, StdMult, 0)

‘Enter position criteria

If FastAve > SlowPlus And FastAve[1] < SlowPlus[1] Then
Buy(“Buy”,1,0, Market,Day)
End If

If FastAve SlowMinus[1] Then
End If

‘Exit position criteria

If FastAve SlowAve[1]Then
ExitLong(“XLong”, “Buy”, 1, 0, Market, Day)
End If

If FastAve > SlowAve And FastAve[1] < SlowAve[1] Then
ExitShort(“XShort”, “Sell”, 1, 0, Market, Day)
End If

End Sub

Not that complicated, really. But then again, this is a fairly simple system. What we told our good silicon friends to do is the following:

We would like to enter a long trade when the fast moving average closes above the upper Bollinger band of the slow moving average. To exit this trade, we need the fast moving average to close below the slow moving average. And do the same on the short side, please.

This chatty explanation is called pseudo-code. It’s an important step, but then again it’s pretty obvious.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: