Friday, August 17, 2007

Trend-following Score c > ema12, ema26, ma1+ emar+

Trend-following Score

I attempted a simple model using the following TradeStation Indicator (I constructed the equity as an indicator, which gave me some flexibility the Systems Testing feature lacks). The results were quite good.

The code follows, but in English, the system works like this: assign 1 point for each of the following conditions: c > ema12, c > ema26, ema12 > ema26, ma1 > ma1[1], ema ratio > ema ratio [1]. Add, divide by 5, then multiply times your margin0 (e.g., 2 if you are willing to use 2:1 levererage). Make a final check that the ema ratio is rising, otherwise don't use leverage (cap at 1). Multiply last bar's score by this bar's change in closing prices (we assume close to close holding), and adjust equity accordingly, comparing to buy and hold.

{ *******************************************************************

Study : Equity, Trend Score

Last Edit : 4/25/99

Provided By: Mark Vakkur, M.D.

********************************************************************}

Inputs: ma1_len(12) ,ma2_len(26), equity0(10), margin0(2); {ma_len = lengths of moving averages used to determine trend}

Vars : Score(0), ma1_gtr_ma2(0), ma1(0), ma2(0), dma1(0), c_gtr_ma1(0), c_gtr_ma2(0), sys_equity(10),

emar(1), emar_up(0), {ema ratio 12/26 up? }

exposure(0);

ma1 = XAverage(c, ma1_len); {ma1 is the short ema; ma2 is the long ema}

ma2 = XAverage(c, ma2_len);

emar = ma1 / iff (ma2 > 0, ma2, 1);

if ma1 > ma2 then ma1_gtr_ma2 = 1 else ma1_gtr_ma2 = 0; {ma1 > ma2?}

if ma1 > ma1[1] then dma1 = 1 else dma1 = 0; {slope of ma1 up?}

if c > ma1 then c_gtr_ma1 = 1 else c_gtr_ma1 = 0;

if c > ma2 then c_gtr_ma2 = 1 else c_gtr_ma2 = 0;

if emar > emar[1] then emar_up = 1 else emar_up = 0;

if CurrentBar = 1 then sys_equity = equity0; {sets equity at initial equity}

Score = 0;

Score = Score + ma1_gtr_ma2 + dma1 + c_gtr_ma1 + c_gtr_ma2 + emar_up;

Exposure = Score / 5 * margin0; {** change this as number of inputs change **}

If emar_up = 0 then Exposure = MinList( Exposure, 1); {will not allow leverage if ema ratio declining }

if (CurrentBar > 1) and (c[1] > 0) then begin

sys_equity = sys_equity[1] + (sys_equity[1] * Exposure[1] * (c /iff( c[1] > 0, c[1], c) - 1));

{sys equity this bar equals that of last bar plus the profit/loss x exposure }

plot1(Score, "Score");

plot2(sys_equity, "Equity");

plot3(Equity_BH(equity0), "B&H");

end;

Results:

Fidelity Select Home Finance: 7/23/90 - 4/23/99: 520k v. 86.6 k

Fidelity Select Electronics: 253k v. 95.2k

FSEAX 7/6/93 - 4/23/99: 29.9k v. 11.3k

Fidelity Select Medical Delivery: 103k v. 33k

Microsoft 2.428k v. 903k

Dell 3.368 v. 1.077

Best Buy 18.788k v. 1.022k ***

No comments:

Post a Comment