2/25/2011

Trend Following.5 - Day Trading

We used an intra-day 1-minute chart to trade.  Using Exponential Moving Average(15) as the indicator.  Different stocks may use different EMA number.  We can add another chart for reference or comparison.  For example, if we want to trade IWM, we can use SPY as a reference for the entry/exit signal.


For each day of trading, we can try different EMA number to find a better fit.  Just remember that the EMA number is not fixed, it should be tuned due to different trading conditions.

Trend Following.4 - Reverse a Losing Strategy

A simple trading strategy will give a serial crossover signals, such as +-+-+-+-. (+) is for price crossing up the trend line, (-) is for down.

For a long only strategy, it will be like (buy-sell) pairs, we buy at (+) and sell at (-).

For a short only strategy, it will be like (sell-buy) pairs, we sell short at (-) and buy cover at (+).

For each trade, we can get the max drawdown and the return.  Then we can get the cumulative return, and compare it with a simple buy-and-hold strategy.

If a strategy is a losing strategy in the long run, we can reverse the trade to see if it's profitable.

Say the cumulative return of strategy A is the product of ReturnA.i.  The return of the reverse strategy B is the product of ReturnB.i.

ReturnA.i = (1+a.i)
ReturnB.i = (1+b.i) = (1-a.i)

so ReturnA.i * ReturnB.i = (1+a.i)(1-a.i) = 1- a.i2 < 1

The product of (ReturnA.i * ReturnB.i) will approach zero in the long run.

Say X = product of (ReturnA.i * ReturnB.i) = product of ReturnA.i * product of ReturnB.i

If X < product of ReturnA.i, then product of ReturnB.i < 1.

If strategy A is a losing strategy and the product of ReturnA.i > X, then the reverse strategy is also a losing strategy.

Trend Following.3 - Programming (Ruby)

Using a simple programming language Ruby to do the analysis. We can verify the results (Entry and Exit) with Excel. A free book of Ruby is at SapphireSteel Software.

A simple program to find
1.the entry and exit
2.the max drawdown
3.the return of each Entry/Exit pair
4.the total return

Strategy:
1. If Crossover(+), then Entry.
2. If Crossover(-), then Exit.
3. If status is Entry and Max Drawdown is over than the stop loss limit, then Exit.


The process:
1. Assign the data array for Stock Price and Filter(moving average parameters)
2. Set up the Stop Loss ratio
3. Define state variables such as current status (in Entry or Exit)
4. Loop through each data (stock price)
      a.Calculate Filtered data
      b.If the status is in "Entry"
           Calculate the Drawdown and update the Maxdrawdown if necessary.
           If Maxdrawdown is over the stop loss limit
              Change status to "Exit"
              Calculate total return.
              Print out results.
           End If
         End If
      c.If Crossover happens
           If Up
               Change status to "Entry"
               Set Entry Price
               Reset Maxdrawndown 
           Else
               If status is in "Entry"
                  Change status to "Exit"
                  Calculate total return.
                  Print out results.
               End If
           End If
        End If
       d.Update status variables.
   End Loop
5. Print out the total return.

2/22/2011

Trend Following.2

Entry when the crossover(+) happens between price and trend line. Exit when the crossover(-) happens between price and trend line.

The Long(buy low/sell high) is 40 percent profitable.

2/17/2011

Working on the Trading System - Trend Following.1

Get FIR filter parameters from TFilter.

Get RUT, SPX, NASDAQ historical data.

Design Entry and Exit Method.

Entry:
1. Up Trend Confirmation
2. Crossover between Price and Trend Curve.

Exit:
1. Trail Stop
2. Stop Loss
3. Crossover between Price and Trend Curve.

Calculate Max drawdown and cumulative returns.

Note:
1. Inverting a losing strategy might not make it profitable.