Risk warning

All articles, strategies and indicators are just reflecting a single traders opinion and should be viewed as that.
I advice everybody to trade with a DEMO account!

Sunday, December 5, 2010

First CTL strategy example. Filtered EMA Strategy.

First CTL strategy example. Filtered EMA Strategy.

First the code:
************************************************************************
strategy filteredEMA;
/* written by ctlprogrammer for EUR/USD timeframe 30 min*/
/*Warning for demonstration purpose only, no live trading please*/
/* http://ctltrading.blogspot.com*/
input period1 = 13,period2=5, lots = 1;
vars ma1(series),ma2(series),ma3(series),currentbar(number),entryallowed(bool);
begin
if back(close) < front(close) + 200 then return;
currentbar := back(close);
ma1 := ema(close, period1);
ma2 := ema(close, period2);
ma3 := ema(close,200);
entryallowed:=true;
if crossdown(ma2,ma1) and low[currentbar-3]<ma1[currentbar-2] then entryallowed:=false;
if crossup(ma2,ma1) and high[currentbar-3]>ma1[currentbar-2] then entryallowed:=false;
if entryallowed=true then
begin
        if crossdown(ma2,ma1) and ma3[currentbar-1]>ma3[currentbar] then
        begin
            if long() then begin exitlong(); sell(lots); end;
            if not short() then sell(lots);
        end;

       if crossup(ma2,ma1) and ma3[currentbar-1]<ma3[currentbar] then
       begin
           if short() then begin exitshort(); buy(lots); end;
           if not long() then buy(lots);
       end;
end;
end.
************************************************************************

How does this strategy works:

It is a trend following based strategy.

if crossup(ma2,ma1) and ma3[currentbar-1]<ma3[currentbar]

The strategy goes long when fast Exponential moving average (period 5) crosses the slow Exponential moving average (period 13) upwards and the Exponential moving average (period 200) is going up.

if crossdown(ma2,ma1) and ma3[currentbar-1]>ma3[currentbar]

The strategy goes short when fast Exponential moving average (period 5) crosses the slow Exponential moving average (period 13) downwards and the Exponential moving average (period 200) is going down.

To avoid to many false signals there is a build in filter:
entryallowed:=true;
if crossdown(ma2,ma1) and low[currentbar-3]<ma1[currentbar-2] then entryallowed:=false;
if crossup(ma2,ma1) and high[currentbar-3]>ma1[currentbar-2] then entryallowed:=false;

This parts makes sure that entries are only valid if the crossing has a descent slope. It checks if the 3 bar before the crossing was above the Exponential Moving Average (period 13).

Back test shows that this strategy works best in time frames 30 min or higher. I wrote it for the EUR/USD currency.

4 comments:

  1. Thanks a lot for these CTL strategies.
    Good work, i try these in my platform.
    1 thing: after the last end must be an end.

    with kind regards.

    Albert

    ReplyDelete
  2. Thanks a lot. I missed that one. I corrected the code hope it is fine now.

    ReplyDelete
  3. i like this strategy, and i want use for scalping, but i need some change.
    if conditions for long are true i want place an long limit order with the higher price from 3 bars ago from the crossover ma1 ma2
    and if conditions for short are true i want place an short limit order with the lower price from 3 bars ago from the crossdown ma1 ma2
    thanks for help
    sorry for my english

    ReplyDelete
  4. I think you are not on the right track with your limit order. First of all limit orders can't be placed to close to the current price. The platform doesn't allow that. That isn't ideal for scalping.

    Second disadvantage is that you can't make any backtest with limit orders.

    Anyway if you want to try things out you can try with

    limit_buy(lots,price);
    limit_sell(lots,price);

    ReplyDelete