6 ema crossing strategy

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #84226 quote
    rae
    Participant
    New

    Hi all, please help me with the code on this 6ema crossing strategy.

    set 1: ema 34/89/144 (LT ema)
    set 2: ema 8/13/21 (ST ema)

    for short term trading:

    1. determine trend
    when both sets of ema are in alignment, can go long or short in according to the alignment (small to big = long) (big to small = short)

    2. Determine Trigger
    when the 2 smallest EMA (8 cuts 13) in according to the alignment, then enter LONG or SHORT

    exit trade (take profit) also in accordance to the crossing of the 2 smallest ema (8 cuts 13)

    thanks in advance!

    Screen-Shot-2018-11-06-at-12.05.19-PM.png Screen-Shot-2018-11-06-at-12.05.19-PM.png
    #84230 quote
    robertogozzi
    Moderator
    Master

    Try this (tested only for syntax errors):

    DEFPARAM CumulateOrders = false
    ONCE MAtype = 1                        //1 = ema
    LTema1 = average[34,MAtype](close)     //34
    LTema2 = average[89,MAtype](close)     //89
    LTema3 = average[144,MAtype](close)    //144
    STema1 = average[8,MAtype](close)      //8
    STema2 = average[13,MAtype](close)     //13
    STema3 = average[21,MAtype](close)     //21
    // LONG  setup
    l1     = STema2 > STema3
    l2     = STema3 > LTema1
    l3     = LTema1 > LTema2
    l4     = LTema2 > LTema3
    l5     = STema1 CROSSES OVER STema2
    GoLong = l1 AND l2 AND l3 AND l4 AND l5
    // SHORT setup
    s1     = STema2 < STema3
    s2     = STema3 < LTema1
    s3     = LTema1 < LTema2
    s4     = LTema2 < LTema3
    s5     = STema1 CROSSES UNDER STema2
    GOShort= s1 AND s2 AND s3 AND s4 AND s5
    //
    // Exit LONG  trades
    IF s5 AND LongOnMarket THEN
       SELL AT MARKET
    ENDIF
    //
    // Exit SHORT trades
    IF l5 AND ShortOnMarket THEN
       EXITSHORT AT MARKET
    ENDIF
    //
    // LONG  trade
    IF GoLong AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    // SHORT trade
    IF GoShort AND Not OnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    rae thanked this post
    #84242 quote
    rae
    Participant
    New

    hi robert, there is no syntax error but how can adjust the coding to get a better win/lose ratio? and also to avoid multiple entries.

    i tested in on EU 1h and it gave me the result in the attachment

    Screen-Shot-2018-11-06-at-10.59.07-PM.png Screen-Shot-2018-11-06-at-10.59.07-PM.png
    #84245 quote
    robertogozzi
    Moderator
    Master

    Apart from modifying the periods of the averages, you could add a trailing stop and have a try.

    What do you mean by “avoid multiple entries“?

    Line 1 and also lines 36 and 40 make sure there are not multiple entries at the same time.

    After a crossing occurs there will be no new entry till the next crossing, provided there is the correct alignement of MA’s.

    #84251 quote
    rae
    Participant
    New

    thanks robert.
    1. there is this case in one of the attachments below where it entered twice.

    2. and how is possible to code to capture entry after the STemas crossing but before LTemas are in alignments? (see attachment)

    thanks again

    Screen-Shot-2018-11-07-at-12.39.09-AM.png Screen-Shot-2018-11-07-at-12.39.09-AM.png Screen-Shot-2018-11-07-at-12.39.42-AM.png Screen-Shot-2018-11-07-at-12.39.42-AM.png
    #84255 quote
    robertogozzi
    Moderator
    Master

    As for question 1, I have experienced two almost adjacent crossings causing a long trade to enter twice on Oct. 16th (see attached pic), which is correct, but you may want to ban the strategy from entering again before, say, 10-15 bars, or till the next day!

    As for question 2, despite not requiring LTemas to be aligned do you want them ALL to still be above/below STemas & STemas to be aligned besides crossing?

    x-1.jpg x-1.jpg
    #84257 quote
    rae
    Participant
    New

    hi robert, perhaps this attachment is clearer of what the strategy is intended to be. thanks for your help

    Screen-Shot-2018-11-07-at-1.39.09-AM.png Screen-Shot-2018-11-07-at-1.39.09-AM.png
    #84260 quote
    robertogozzi
    Moderator
    Master

    Point 3 requires ALL STemas to crossover ALL LTemas?  If not, which LTemas needs to be crossed over by STemas and which one doesn’t?

    Unfortunately your pic is fine for trading manually while watching your charts, but coding that behaviour in an automated strategy is not that easy, for instance you, at point 2, say “approaching”, but a piece of software cannot understand, approaching is 10 pips away or maybe just 2, or crossing (which one of the six EMAs should approach or cross the other group to handle it properly)?

    You must TELL (pics don’t help me much in this case) me what those six EMAs have to do exactly.

    #84261 quote
    rae
    Participant
    New

    hi robert, replying to your questions:

    Point 3 requires ALL STemas to crossover ALL LTemas? All STemas has to first cross over Ema34 and subsequently all STemas together with Ema34 has to cross over Ema89 and Ema144

    STemas are for entry and exit and they react the fastest to trend change, hence they are also the trend determinant. When the smallest Ema crosses the middle one, it will signal a sign of trend change.

    LTemas are more for the long term trend change, they respond the slowest, hence the crossing of all STemas with LTemas will be the confirmation for trend change.

    So to consolidate my points:

    1. STemas crossing – (ema8 over ema13) or (ema8 over ema21)
    2. all STemas cross LTema1 (ema34) – to take action
    3. all STemas is above all LTemas

    Thks.

    #84321 quote
    robertogozzi
    Moderator
    Master

    Sorry for not being able to take a look at it today, I’ll have one tomorrow.

    rae thanked this post
    #84393 quote
    robertogozzi
    Moderator
    Master

    Your last post differs considerably from your first one, this is the code:

    DEFPARAM CumulateOrders = false
    ONCE MAtype = 1                        //1 = ema
    LTema1 = average[34,MAtype](close)     //34
    LTema2 = average[89,MAtype](close)     //89
    LTema3 = average[144,MAtype](close)    //144
    STema1 = average[8,MAtype](close)      //8
    STema2 = average[13,MAtype](close)     //13
    STema3 = average[21,MAtype](close)     //21
    // LONG  setup
    l1     = (STema1 CROSSES OVER STema2)  OR (STema1 CROSSES OVER STema3)   //STema8 crosses over STema13 or STema21
    l2     = min(STema1,min(STema2,STema3)) > max(LTema1,max(LTema2,LTema3)) //all STemas > all LTemas
    l3     = (STema1 CROSSES OVER LTema1) AND (STema2 CROSSES OVER LTema1) AND (STema3 CROSSES OVER LTema1)  //ALL STemas cross over LTema1
    l5     = STema1 CROSSES OVER STema2    //exit trigger for SHORT trades
    GoLong = l1 AND l2 AND l3
    // SHORT setup
    s1     = (STema1 CROSSES UNDER STema2) OR (STema1 CROSSES UNDER STema3)  //STema8 crosses under STema13 or STema21
    s2     = max(STema1,min(STema2,STema3)) < min(LTema1,max(LTema2,LTema3)) //all STemas < all LTemas
    s3     = (STema1 CROSSES UNDER LTema1) AND (STema2 CROSSES UNDER LTema1) AND (STema3 CROSSES UNDER LTema1)  //ALL STemas cross under LTema1
    s5     = STema1 CROSSES UNDER STema2  //exit trigger for LONG trades
    GOShort= s1 AND s2 AND s3
    //
    // Exit LONG  trades
    IF s5 AND LongOnMarket THEN
       SELL AT MARKET
    ENDIF
    //
    // Exit SHORT trades
    IF l5 AND ShortOnMarket THEN
       EXITSHORT AT MARKET
    ENDIF
    //
    // LONG  trade
    IF GoLong AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    // SHORT trade
    IF GoShort AND Not OnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF

     

    Due to multiple crossings on the same bar it generates very few trades.

    rae thanked this post
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

6 ema crossing strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rae @rae Participant
Summary

This topic contains 10 replies,
has 2 voices, and was last updated by robertogozzi
7 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/06/2018
Status: Active
Attachments: 6 files
Logo Logo
Loading...