6 ema crossing strategy
Tagged: ema crossing
11/06/2018 at 5:06 AM #84226
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!11/06/2018 at 9:28 AM #84230
Try this (tested only for syntax errors):1234567891011121314151617181920212223242526272829303132333435363738394041DEFPARAM CumulateOrders = falseONCE MAtype = 1 //1 = emaLTema1 = average[34,MAtype](close) //34LTema2 = average[89,MAtype](close) //89LTema3 = average[144,MAtype](close) //144STema1 = average[8,MAtype](close) //8STema2 = average[13,MAtype](close) //13STema3 = average[21,MAtype](close) //21// LONG setupl1 = STema2 > STema3l2 = STema3 > LTema1l3 = LTema1 > LTema2l4 = LTema2 > LTema3l5 = STema1 CROSSES OVER STema2GoLong = l1 AND l2 AND l3 AND l4 AND l5// SHORT setups1 = STema2 < STema3s2 = STema3 < LTema1s3 = LTema1 < LTema2s4 = LTema2 < LTema3s5 = STema1 CROSSES UNDER STema2GOShort= s1 AND s2 AND s3 AND s4 AND s5//// Exit LONG tradesIF s5 AND LongOnMarket THENSELL AT MARKETENDIF//// Exit SHORT tradesIF l5 AND ShortOnMarket THENEXITSHORT AT MARKETENDIF//// LONG tradeIF GoLong AND Not OnMarket THENBUY 1 CONTRACT AT MARKETENDIF// SHORT tradeIF GoShort AND Not OnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIF11/06/2018 at 3:59 PM #84242
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 attachment11/06/2018 at 4:56 PM #84245
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.11/06/2018 at 5:44 PM #84251
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 again11/06/2018 at 6:29 PM #84255
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?11/06/2018 at 6:51 PM #8425711/06/2018 at 7:15 PM #84260
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.11/06/2018 at 7:42 PM #84261
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.11/07/2018 at 12:37 PM #8432111/08/2018 at 8:56 AM #84393
Your last post differs considerably from your first one, this is the code:123456789101112131415161718192021222324252627282930313233343536373839DEFPARAM CumulateOrders = falseONCE MAtype = 1 //1 = emaLTema1 = average[34,MAtype](close) //34LTema2 = average[89,MAtype](close) //89LTema3 = average[144,MAtype](close) //144STema1 = average[8,MAtype](close) //8STema2 = average[13,MAtype](close) //13STema3 = average[21,MAtype](close) //21// LONG setupl1 = (STema1 CROSSES OVER STema2) OR (STema1 CROSSES OVER STema3) //STema8 crosses over STema13 or STema21l2 = min(STema1,min(STema2,STema3)) > max(LTema1,max(LTema2,LTema3)) //all STemas > all LTemasl3 = (STema1 CROSSES OVER LTema1) AND (STema2 CROSSES OVER LTema1) AND (STema3 CROSSES OVER LTema1) //ALL STemas cross over LTema1l5 = STema1 CROSSES OVER STema2 //exit trigger for SHORT tradesGoLong = l1 AND l2 AND l3// SHORT setups1 = (STema1 CROSSES UNDER STema2) OR (STema1 CROSSES UNDER STema3) //STema8 crosses under STema13 or STema21s2 = max(STema1,min(STema2,STema3)) < min(LTema1,max(LTema2,LTema3)) //all STemas < all LTemass3 = (STema1 CROSSES UNDER LTema1) AND (STema2 CROSSES UNDER LTema1) AND (STema3 CROSSES UNDER LTema1) //ALL STemas cross under LTema1s5 = STema1 CROSSES UNDER STema2 //exit trigger for LONG tradesGOShort= s1 AND s2 AND s3//// Exit LONG tradesIF s5 AND LongOnMarket THENSELL AT MARKETENDIF//// Exit SHORT tradesIF l5 AND ShortOnMarket THENEXITSHORT AT MARKETENDIF//// LONG tradeIF GoLong AND Not OnMarket THENBUY 1 CONTRACT AT MARKETENDIF// SHORT tradeIF GoShort AND Not OnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIF
Due to multiple crossings on the same bar it generates very few trades.