What is a trading system?

For some traders, building a trading system means that they focus on finding the best indicators they could get their hands on or the one trading setup that is backtested to work 99% of the time. All I can say is, to each his own.

For me, the keyword of a trading system lies not with trading, but with system. Remember, it is a system. First of all, it is a system for trading. Not a system to trade. What do I mean by that?

Consider this saying, “traders don’t go broke by missing opportunities, they go broke by taking too many.” A trading system needs to be selective. It needs prudent risk management.

Secondly, you need to generate your own market view to trade. Rather it be technical, fundamental, sentimental, or just following some joe, you trade based on your view. Trading is a test of your market hypothesis using money. If you think the market will rise, you buy. If you think the market will fall, you short.

Lastly, a trading system needs to execute trades. Otherwise you’d be an anlayst. It needs to time entries and exits. Again, this could be as simple as on a whim or as complicated as some n-th order algorithm.

Thus we have the three pillars of a trading system.

  1. Risk Management
  2. Market Analysis
  3. Trade Execution

What’s more, if we combine some of these pillars we get some well known concepts. For example, market analysis + trade execution = trading signals, wherein you derive signals based on market conditions to execute trades. Or risk management + trade execution = position management, wherein you manage your holdings by manipulating your trades based on your risk profile.

All these relationships and composition of a trading system can be summarized with a Venn diagram. So, this is my view of a trading system:

Trading system Venn diagram

read more

Professor Risk Cambridge Ideas

A look at risks in everyday life.

read more

3 reasons why I even bother trading a small account

If you look closely at my trade log, you will see that the amount that I trade is small. I am not going to get rich anytime soon even if I can maintain my 10% return or so every half a year. My wife was asking me the other day why I don’t plunk in more money to my trading accounts since I have even won a trading contest and all.

With accounts and trading sizes so small, I am appearing to be just wasting my time. For example, it took 2 to 3 hours of research and analysis the night before this recent trade in gold and then just to see it make $35. At least it’s slightly better than the minimum wage here.

The real trial though, is in facing a losing streak. Imagine spending hours and hours pouring over price charts, economic news, and financial data only to see your account shrink and shrink. Those are the times when you wonder why you even bother putting in the hours. It just won’t make a difference, right?

Well, here are my three motivations for trading a small account.

  1. Slow and steady. The fact is, trading is about aiming for consistency and not scoring that one-in-a-lifetime trade that’ll make you rich. That took me a few years to realize. It is a lot easier to make pocket change than score a jackpot. Don’t make trading harder on yourself.
  2. Trading comfortably. Hey, this is a hobby. I wouldn’t last too long in this game if I’m sweating my palms with every position. If I bet my farm often, either my account will go broke or my sanity will. I prefer to keep my risk small enough to lasts and make trading enjoyable. If I want thrills, I go to a casino (there is actually a big casino 15 min. from my house).
  3. Walk before you run. Eventually though, as I become consistently profitable, I increase my risk ever so slightly step by step. Couple that with the effect of compounding, I may eventually be able to replace my salary with my trading income. That is probably still years away for me, but as people say, everybody has to start somewhere.

So no, I don’t think trading a small size is a waste of my time. It is a good risk management, psychological mediation, and learning technique for amateur traders such as myself.

read more

JForex Example: Automatic position sizing

Proper position sizing is an integral part of risk management. It can be one of the easiest thing to do too. For example, I typically size my trading position based on the following factors:

  1. Amount of capital willing to put at risk.
  2. Stop price level.
  3. Volatility of the instrument.

The following JForex code calculates a lot size based on these three factors. It is part of my Dukascopy JForex July strategy (complete source code to the strategy is available via that link).

	private double getLot(Instrument instrument) throws JFException
	{
		double riskAmt;
		double lotSize = 0;

		riskAmt = this.acctEquity * (this.riskPct / 100d); // CCYUSD only
		lotSize = riskAmt / (this.atr[instrument.ordinal()] * this.atrFactor);

		lotSize /= 1000000d;					// in millions
		return roundLot(lotSize);
	}

Referring to line 237, riskAmt is the amount of capital to put at risk for a trade (#1). Line 238 calculates lotSize, which is the position size that we want. The denominator in that division is the distance of the stop in pips. The strategy uses a multiple of ATR to set the stop loss. Nothing fancy here.

Lines 240–241 are to set the lotSize value according to the JForex API specification. In which the lot amount is in millions and in steps of a thousand units, or 0.001 step size.

As I’ve noted in the code, the caveat to this implementation is that the secondary currency of the instrument and your account currency needs to be in U.S. dollar. However, it’s just a matter of conversion to extend this method for other currencies.

Update: I expanded on this functionality in the JFUtil open source project.

read more

JForex Example: Not letting profit turn to losses with a breakeven stop

While the dual-timeframe trading setup and much of the algorithm in my contest strategy are for competition only (read: not for use with real money) as I’ve warned numerous times, some of the risk management techniques used there are really what I use in real life. This being one of them.

There’s a saying in trading that “never let profits turns into losses.” That is exactly the motivation behind this JForex code snippet. The following source code are excerpts from my Dukascopy JForex contest’s July strategy. The complete source code file is available in that link.

Back to this concept of not letting profits turn to losses. This is a matter of balancing between giving room for your trade to reach its potential and limiting your drawdown. If you’re too careful, you may find yourself being whipsawed out before a price move can materialize. If you keep your leash too loose though, well, you may watch your profits turn into losses.

The way I intrepret the saying is that once your trade is profitable enough, you shouldn’t let it slip back into a loss.

I implement the above statement in my automated strategy as follows. Note that everything goes in the onTick() method so that it watches your position on every tick. The line numbers correspond to the complete source code of my automated strategy.

		boolean isLong;
		double open, stop, diff, newStop;

		for (IOrder order : engine.getOrders(instrument)) {
			if (order.getState() == IOrder.State.FILLED) {
				isLong = order.isLong();
				open = order.getOpenPrice();
				stop = order.getStopLossPrice();
				diff = (open - stop);

				// ********* BREAKEVEN ***********************
				if (isLong && diff > 0 && tick.getBid() > (open + diff))
				{
					order.close(roundLot(order.getAmount() * beRatio));	// close a portion

					newStop = open + instrument.getPipValue() * LOCKPIP;
					order.setStopLossPrice(newStop);
               print(order.getLabel() + ": Moved STOP to breakeven");
				}
				else if (!isLong && diff < 0 && tick.getAsk() < (open + diff))
				{
					order.close(roundLot(order.getAmount() * beRatio));

					newStop = open - (instrument.getPipValue() * LOCKPIP);
					order.setStopLossPrice(newStop);
					print(order.getLabel() + ": Moved STOP to breakeven");
				}

What this does is that it will partially exit a position and move the stop to breakeven once the price is equidistantly positive from your initial stop loss. For example, if my stop loss is 100 pips, then once the position is 100 pips in profit, it will exit partially and set the new stop to breakeven.

Update: This is now integrated into the JFUtil open source project.

read more