three EMAs in trading system

Discussion in 'Automated Trading' started by johnyjj2, Jul 5, 2010.

  1. johnyjj2



    I have tested several trading systems found in the web and those were not so good. So I decided to create my own system in AmiBroker.

    I found such a description: "We can use combination of moving averages: 4-, 9- and 18-days. If 9-days average is above 18-days but 4-days came below 9-days, we can state that there is no trend on the market. We can say the same if 9-days will be below 18-days and 4-days will cross 9-days from the bottom. We have got increasing trend if 4-days would be above 9-days, and this one above 18-days. The opposite moving averages indicate decreasing trend".

    However this description is somehow unclear for me because it says which moving average is above which but not which one crosses which (with one exception). Because of this I made little research in the internet and the only one useful what I found was this , which unfortunately says only little about this topic. I created this . There are eight little pictures, first four are for the above description, next four for the website. First two are about situation when there is no trend, third for increasing, fourth for decreasing, fifth and sixth for opening long position, last two for closing long position. I also created the code shown below but I'm not satisfied with this code. I also wonder if I should move to the bottom, leave or delete the part about clearing (making 'zero'). I used in code below 'no trend' part from the description above and buy/sell from the website.

    //I make buy and sell zero if there is no trend
    buy = IIf(
      (((ema(C,9) > ema(C,4)) AND (ema(C,4) > ema(C,18))) OR ((ema(C,18) > ema(C,4)) AND (cross(ema(C,4),ema(C,9)))))
    sell = IIf(
      (((ema(C,9) > ema(C,4)) AND (ema(C,4) > ema(C,18))) OR ((ema(C,18) > ema(C,4)) AND (cross(ema(C,4),ema(C,9)))))
    //I buy for increasing trend
    buy = IIf(
      //AND (ema(4) > ema(9)) AND (ema(4) > ema(18))
    //I sell for decreasing trend
    sell = IIf(
      //AND (ema(18) > ema(4)) AND (ema(18) > ema(9))
    I also thought about adding the other condition, i.e. to wait for increasing the price above price maximum of the day, in which there is crossing of moving averages. It should be at the end of the code and additional condition.

    was_there_highest_price = IIf(C > Ref(H,-1),1,0)
    buy = IIf(was_there_highest_price, buy, 0)
    However this additional condition won't work because it should work one day later. For example:
    Wednesday - crossing of averages shows to buy
    Thursday - price above yesterday's high so both conditions are fulfilled and I buy

  2. You can read more about this type of strategy in Curtis Faith's book "Way of the Turtle". Like all common trend-following strategies it cycles in and out of favor over time. But you can find success with it if you stick with it until you catch the trends.
  3. Look up "rainbows", too.
  4. johnyjj2


    Thanks for your answers!

    I expected you to explain those things to me and you gave me title of the book in which it is explained and... that's even better because I can have wider knowledge about the given topic.

    I also tried to find good kind of stop for my trading system. I tried to look for something about it but most articles covered only stop loss and take profit. I'm sure there are much more kinds of stop. Can you suggest me any easily available book in which I can find more about this topic?

  5. Page 142 of that book explains the triple-MA system. Bear in mind the Turtles systems used daily bars and different MA periods than you mentioned, but the concepts would be the same. Stops are where the shortest period MA crosses back under (over) the middle period MA.
  6. johnyjj2



    I tried to use optimization in order to check which stop would be better. However, when I execute this code, it gives me six the same results! I think those results should be different. AmiBroker accepts the syntax of the following code but I'm afraid it understands it in different way than I do and this is the reason why I have got the same result of optimization for every value of which_stop. (On the other hand it looks like I cannot use nested optimize function because it wants to execute it for each which_stop even if optimize is inside the iif function). Can you tell me, please, what should I change in order not to have the same result for all the values of which_stop? (I assume you agree with me that it shouldn't give the same results for different stops).

    Buy = Cross( CCI(), 100 );
    Sell = Cross( 100, CCI() );
    which_stop = Optimize("which_stop",6,1,6,1);
    /* max loss stop optimization */
    IIf(which_stop == 1,
             //Optimize( "max. loss stop level", 10, 2, 30, 1 ),
             True )
    /* single-line implementation of Chandelier exit */
    IIf(which_stop == 2,
    ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(14), True, True )
    /* N-bar stop */
    IIf(which_stop == 3,
    ApplyStop( stopTypeNBar, stopModeBars, 5 )
    /* Back testing your trading ideas - Trailing stops */
    IIf(which_stop == 4,
    ApplyStop( stopTypeTrailing, stopModePercent, 10, True )
    /* Back testing your trading ideas - Dynamic stops */
    IIf(which_stop == 5,
    ApplyStop( 0, 2, 2 * ATR( 10 ), 1 )
    /* other */
    IIf(which_stop == 6,

    PS Artur Deco: what do you mean by "rainbows"?