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, May 8, 2011

EmaSADX strategy requested by a blog reader.

Received an email from a blog reader with the question if could write a small strategy for him. Many thanks to Marius for this strategy. He agreed of posting it.

Strategy description and rules:

Long Entries:
1. The EMA(20) must be going UP. For better trend following, SMA(40) must be going UP too
2. The EMA(5) must have gone UP at least 2 Bars or more.
3. The Setup bar LOW must be LESS than or touching the EMA(5) and the Setup bar HIGH must be greater than the EMA(20) and SMA(40) .
4. The ADX must be below 25 and heading up
5. From the Setup bar, count 5 bars backwards including the setup bar.
6. Set ENTER point 1 tick/pip above the Highest High of the 5 bars.


Short Entries:
1. The EMA(20) must be going DOWN. For better trend following, SMA(40) must be going DOWN too
2. The EMA(5) must have gone DOWN at least 2 Bars or more.
3. The Setup bar HIGH must be GREATER than or touching the EMA(5) and the Setup bar LOW must be less than the EMA(20) and SMA(40).
4. The ADX must be below 25 and heading up
5. From the Setup bar, count 5 bars backwards including the setup bar.
6. Set ENTER point 1 tick/pip below the Lowest Low of the 5 bars.

Belows you see the code for this strategy. Hold on this isn't the final version.

strategy EmaSADX ==> original strategy
/* written by ctlprogrammer for EUR/USD  */
/* Many thanks to Marius for this strategy*/
/* Warning for demonstration purpose only, no live trading please*/
/* you can freely copy the code but plz leave this header*/
/*
http://ctltrading.blogspot.com*/
input periodema20 = 20,periodema5=5,periodsma40=40, lots = 1;
begin
integer currentbar,i;
number high5,low5;
series ema20,ema5,sma40,adx;
currentbar := back(close);
if currentbar <= max(periodsma40,max (periodema20,periodema5)) then return;
 
Mov_Avg_Exponential(close,periodema20);
ema20:=Mov_Avg_Exponential.line;
Mov_Avg_Simple(close,periodsma40);
sma40:=Mov_Avg_Simple.line;
Mov_Avg_Exponential(close,periodema5);
ema5:=Mov_Avg_Exponential.line;
Directional_Movement_ADX(5);
adx:=Directional_Movement_ADX.line;
high5:=0.0;
low5:=100000.0;
if ema20[currentbar-2]<ema20[currentbar-1] and
   sma40[currentbar-2]<sma40[currentbar-1] and
   ema5[currentbar-3]<ema5[currentbar-2] and ema5[currentbar-2]<ema5[currentbar-1] and
   low[currentbar-1]<=ema5[currentbar-1] and high[currentbar-1]>ema20[currentbar-1] and high[currentbar-1]>sma40[currentbar-1] and
   adx[currentbar-1]<25 and adx[currentbar-2]<adx[currentbar-1] then
   begin
       for i:=1 to 5 do
       begin
       if high[currentbar-i]>high5 then high5:=high[currentbar-i];
       end;
   if high[currentbar]>high5 then
       begin
       if short() then exitshort();
       if not long() then buy(lots);
       end;
   end;

 if ema20[currentbar-2]>ema20[currentbar-1] and
   sma40[currentbar-2]>sma40[currentbar-1] and
   ema5[currentbar-3]>ema5[currentbar-2] and ema5[currentbar-2]>ema5[currentbar-1] and
   high[currentbar-1]>=ema5[currentbar-1] and low[currentbar-1]<ema20[currentbar-1] and low[currentbar-1]<sma40[currentbar-1] and
   adx[currentbar-1]<25 and adx[currentbar-2]<adx[currentbar-1] then
   begin
       for i:=1 to 5 do
       begin
       if low[currentbar-i]<low5 then low5:=low[currentbar-i];
       end;
   if low[currentbar]<low5 then
       begin
       if long() then exitlong();
       if not short() then sell(lots);
       end;
   end;
  
end.

Let see how it would have performed the last days. If that's isn't promising its going to the waste bin!

Eur/usd => 1 min , 5 min, 10 min, 15 min , 30 min, 1 hour chart
Everybody who would have used this strategy last week would have made profit. Maybe the current market conditions where ideal for this strategy but still maybe this isn't so bad at all.

Marius did some test on the DAX.cfd and he liked it. But he suggested the following.

For the DAX he adviced the SMA 50 instead of SMA 40. This can be true. I advice to try out different setting for the different ema's and sma depending on the pair or CFD you are going to trade. He also noticed that the strategy is always in the market and he doesn't find that the ideal scenario. He prefers clear entry and exit rules and a stop loss.

So lets try that and add:
  • a profit taking level
  • a stop stop loss
  • an exit for when the entry doesn't looks so great anymore

strategy EmaSADX;
/* written by ctlprogrammer for EUR/USD */
/* Many thanks to Marius for this strategy*/
/* Warning for demonstration purpose only, no live trading please*/
/* you can freely copy the code but plz leave this header*/
input periodema20 = 20,periodema5=5,periodsma40=40,profit_taking=1000000, stop_loss=-1000000, exit_when_looks_bad=true, lots = 1;

begin

integer currentbar,i;
number high5,low5;
series ema20,ema5,sma40,adx;

currentbar := back(close);
if currentbar <= max(periodsma40,max (periodema20,periodema5)) then return;
Mov_Avg_Exponential(close,periodema20);
ema20:=Mov_Avg_Exponential.line;
Mov_Avg_Simple(close,periodsma40);
sma40:=Mov_Avg_Simple.line;
Mov_Avg_Exponential(close,periodema5);
ema5:=Mov_Avg_Exponential.line;
Directional_Movement_ADX(5);
adx:=Directional_Movement_ADX.line;
high5:=0.0;
low5:=100000.0;

if ema20[currentbar-2]<ema20[currentbar-1] and
sma40[currentbar-2]<sma40[currentbar-1] and
ema5[currentbar-3]<ema5[currentbar-2] and ema5[currentbar-2]<ema5[currentbar-1] and
low[currentbar-1]<=ema5[currentbar-1] and high[currentbar-1]>ema20[currentbar-1] and high[currentbar-1]>sma40[currentbar-1] and
adx[currentbar-1]<25 and adx[currentbar-2]<adx[currentbar-1] then
begin
for i:=1 to 5 do
begin
if high[currentbar-i]>high5 then high5:=high[currentbar-i];
end;
if high[currentbar]>high5 then
begin
if short() then exitshort();
if not long() then buy(lots);
end;
end;
if ema20[currentbar-2]>ema20[currentbar-1] and
sma40[currentbar-2]>sma40[currentbar-1] and
ema5[currentbar-3]>ema5[currentbar-2] and ema5[currentbar-2]>ema5[currentbar-1] and
high[currentbar-1]>=ema5[currentbar-1] and low[currentbar-1]<ema20[currentbar-1] and low[currentbar-1]<sma40[currentbar-1] and
adx[currentbar-1]<25 and adx[currentbar-2]<adx[currentbar-1] then
begin
for i:=1 to 5 do
begin
if low[currentbar-i]<low5 then low5:=low[currentbar-i];
end;
if low[currentbar]<low5 then
begin
if long() then exitlong();
if not short() then sell(lots);
end;
end;
if fpl()>profit_taking or fpl()<stop_loss then
begin
if long() then exitlong();
if short() then exitshort();
end;

if exit_when_looks_bad=true then
begin
if crossdown(ema5,ema20) then
begin
if long() then exitlong();
if short() then exitshort();
end;
/* you can add your own rules here*/
end;

end.

Important:

How to use this! Run a backtest on the pair or CFD you are going to trade. Longer is better. Than look at the result. Especially look at the big profits and the big losses. Now look what settings you need for the profit taking and stop loss to have the best result. This means look what setting you need to cut off the big losses and make sure your profit taking isn't to small either. The profit level doesn't need to be bigger than the biggest winner but it should be about half of the biggest winner. Anyway try out out and share with us.

18 comments:

  1. I tried testing the first strategy with data from April FTSE100 index, 1,2,10min, 1,2hr, timeframes.
    Despite trying different settings only the 2min timeframe was slightly profitable all the rest were negative.
    Curious as in the original post " Marius did some test on the DAX.cfd and he liked it"
    as the FTSE100, DAX, tend to move in tandem alongwith the DOW what time frame was he using and which, date period for testing?

    Quick test on April EUR/USD data 2,30, 60min
    all positive.

    ReplyDelete
  2. Hi,

    First of all thanks for your feed back. Let me help you out. I just loaded UK100.cfd from January till now. I changed the SM40 into SMA50. (that's what marius noticed for the DAX)

    I let the strat run (lots = 10) and look at the results. Especially the biggest losers and biggest winners. If i see the losers I decide that -400 is more than enough for me. Based on that i wanna use a profit taking bigger than 400 of course. I am not greedy so i go for 600.

    Let see what the result are. Remember this is quickly done between 2 coffee's. I didn't optimize.
    => profit factor becomes 1,43
    => 8 winners 10 losers
    => average winner = 1,8 times average looser
    (back test from January till now)

    Remember these strategies are just examples. I advice to use on demo account.

    If you have time and you find great settings for a specific pair or CFD. Please share. The readers of this blog will must appreciate it.

    ReplyDelete
  3. Thanks,

    I was using the first strategy you posted, my mistake, with the second strategy, on the FTSE100 60min timeframe,
    Jan to May 2011 I can reproduce your results, overall positive,approx the same settings you found.
    Extending back another six months July 2010 to May 2011, same timeframe same settings results turn negative, trying different settings results still negative,
    When I have the time will experiment more.

    ReplyDelete
  4. Hi,

    from the previous post we see:

    Adding a half year of data can turn out that the strategy is not profitable. And 10 trades are not a reliable amount to prove that a strategy is profitable in the future.

    Please (for your own benefit) do the effort an backtest your strategy for the years 2001 to 2005. Optimize it for this period. And the let it run over the years 2006 to 2010. If it survives than you have the chance to be profitable in the future.

    I know it takes a long time to backtest. But how long will it take to save up again your lost money? Please think about it...

    ReplyDelete
  5. Very good advice! I know we are all want to make money fast. But there is no such thing as fast and easy money in trading. There is a learning period that you have to respect. A good trader wasn't born good. It took him sweat and tears to get their. Don't believe the advertisements claiming easy money can be made trading. So remember this:

    - always ask yourself what currency or CFD the strategy has been written for and what time period
    - never start any strategy without serious back testing over a long period of time. The lesser trades a strategy make the longer the back test period must be
    - never start a strategy before running it for a long period on a DEMO account
    - never leave any strategy unattended for a long period of time without some emergency stop (doesn't mean you can't go to the toilet of course LOL)

    And finally I still find the best strategy is the strategy you wrote YOURSELF. That doesn't mean there are not bits and parts that you can use from the many examples on this blog.

    Happy programming and trading

    ReplyDelete
  6. Could you please modify this to use Slow Stoch instead of ADX. The same thing but with Stoch moving above 20 or below 80?

    Thanks!

    ReplyDelete
  7. Below the code with stoch instead of ADX.

    strategy EmaSSTOCH;
    /* written by ctlprogrammer for EUR/USD */
    /* Many thanks to Marius for this strategy*/
    /* Warning for demonstration purpose only, no live trading please*/
    /* you can freely copy the code but plz leave this header*/
    /* www.ctltrading.blogspot.com*/
    input periodema20 = 20,periodema5=5,periodsma40=40,profit_taking=1000000, stop_loss=-1000000, exit_when_looks_bad=true, lots = 1;

    begin

    integer currentbar,i;
    number high5,low5;
    series ema20,ema5,sma40,stoch;

    currentbar := back(close);
    if currentbar <= max(periodsma40,max (periodema20,periodema5)) then return;
    Mov_Avg_Exponential(close,periodema20);
    ema20:=Mov_Avg_Exponential.line;
    Mov_Avg_Simple(close,periodsma40);
    sma40:=Mov_Avg_Simple.line;
    Mov_Avg_Exponential(close,periodema5);
    ema5:=Mov_Avg_Exponential.line;
    Slow_Stochastics(close);
    stoch:=Slow_Stochastics.line_d;
    high5:=0.0;
    low5:=100000.0;

    if ema20[currentbar-2]ema20[currentbar-1] and high[currentbar-1]>sma40[currentbar-1] and
    stoch[currentbar-1]<20 and stoch[currentbar-2]high5 then high5:=high[currentbar-i];
    end;
    if high[currentbar]>high5 then
    begin
    if short() then exitshort();
    if not long() then buy(lots);
    end;
    end;
    if ema20[currentbar-2]>ema20[currentbar-1] and
    sma40[currentbar-2]>sma40[currentbar-1] and
    ema5[currentbar-3]>ema5[currentbar-2] and ema5[currentbar-2]>ema5[currentbar-1] and
    high[currentbar-1]>=ema5[currentbar-1] and low[currentbar-1]profit_taking or fpl()<stop_loss then
    begin
    if long() then exitlong();
    if short() then exitshort();
    end;

    if exit_when_looks_bad=true then
    begin
    if crossdown(ema5,ema20) then
    begin
    if long() then exitlong();
    if short() then exitshort();
    end;
    /* you can add your own rules here*/
    end;

    end.

    ReplyDelete
  8. Very cool! But I got a few errors:

    Ln: 28 Col:23 unexpected identifier
    Ln: 28 Col:43 unexpected and
    Ln: 28 Col:86 unexpected and
    Ln: 29 Col:20 unexpected <
    Ln: 29 Col:47 unexpected identifier
    Ln: 30 Col:1 unexpected END, expecting ;
    Ln: 36 Col:4 unexpected ;, expecting .

    I'm using the Dealbook 360 beta....

    Thanks again!!

    ReplyDelete
  9. Dame! Some characters are lost when i copy the code into a comment. Must be a bug.

    You can download the code here

    https://docs.google.com/leaf?id=0B4qVe5jNBQJiMzMzMmVkMzctNjBhMy00NTI1LTkwYmQtZGZmMjkxODE2MzQ4&hl=en_US&authkey=CKLth9wL

    ReplyDelete
  10. Why do you use a different number for low5?

    high5:=0.0;
    low5:=100000.0;

    ReplyDelete
  11. I made this one with RSI but it never seems to take a long position in all the back testing. Any idea? Thanks!

    strategy EmaRSI;
    /* written by ctlprogrammer for EUR/USD */
    /* Many thanks to Marius for this strategy*/
    /* Warning for demonstration purpose only, no live trading please*/
    /* you can freely copy the code but plz leave this header*/
    /* www.ctltrading.blogspot.com*/
    input periodrsi = 20,periodema20 = 20,periodema5=5,periodsma40=40,profit_taking=150, stop_loss=-25, exit_when_looks_bad=true, lots = 1;


    begin


    integer currentbar,i;
    number high5,low5;
    series ema20,ema5,sma40,rsi;


    currentbar := back(close);
    if currentbar <= max(periodsma40,max (periodema20,periodema5)) then return;
    Mov_Avg_Exponential(close,periodema20);
    ema20:=Mov_Avg_Exponential.line;
    Mov_Avg_Simple(close,periodsma40);
    sma40:=Mov_Avg_Simple.line;
    Mov_Avg_Exponential(close,periodema5);
    ema5:=Mov_Avg_Exponential.line;
    relative_strength(close,periodrsi);
    rsi:=Relative_Strength.line;
    high5:=0.0;
    low5:=100000.0;


    if ema20[currentbar-2]ema20[currentbar-1] and high[currentbar-1]>sma40[currentbar-1] and
    rsi[currentbar-1]<20 and rsi[currentbar-2]high5 then high5:=high[currentbar-i];
    end;
    if high[currentbar]>high5 then
    begin
    if short() then exitshort();
    if not long() then buy(lots);
    end;
    end;
    if ema20[currentbar-2]>ema20[currentbar-1] and
    sma40[currentbar-2]>sma40[currentbar-1] and
    ema5[currentbar-3]>ema5[currentbar-2] and ema5[currentbar-2]>ema5[currentbar-1] and
    high[currentbar-1]>=ema5[currentbar-1] and low[currentbar-1]profit_taking or fpl()<stop_loss then
    begin
    if long() then exitlong();
    if short() then exitshort();
    end;


    if exit_when_looks_bad=true then
    begin
    if crossdown(ema5,ema20) then
    begin
    if long() then exitlong();
    if short() then exitshort();
    end;
    /* you can add your own rules here*/
    end;


    end.

    ReplyDelete
  12. Looks like the code got cut off but it is the same as the ADX but with RSI levels of 20 and 70. For some reason it doesn't seem to take any longs when demo testing...

    ReplyDelete
  13. Nevermind I figured out my questions... :-)

    ReplyDelete
  14. Hye,
    i have some trouble to install
    message error
    integer currentbar,i;
    Ln11col9:unexpected identifier, expexting'['or:=
    number high5, low5;
    Ln12col1: unexpected NUMBER
    series ema20,ema5,sma40,stoch;
    Ln13col1: unexpected SERIES

    have you some solutions
    thanks

    ReplyDelete
  15. On which version do you have those error messages? There are so many. The original or one of the codes in the comments?

    ReplyDelete
  16. Version 2003 CTL IDE 1.0.39.19
    if it's to old were i can upgrade
    thanks

    ReplyDelete
  17. No, its fine. Make the following changes.

    Add before the first begin

    vars currentbar(number), i(number), high5(number),low5(number), ema20(series),ema5(series),sma40(series),adx(series);

    And delete the following:

    integer currentbar,i;
    number high5,low5;
    series ema20,ema5,sma40,adx;

    Should work after these modifications.

    ReplyDelete
  18. happy new year, thanks a lot a woorks.
    now i have a question with the Filtered EMA Strategy.
    thanks for replay

    ReplyDelete