raeParticipant
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!
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
raeParticipant
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
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.
raeParticipant
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
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?
raeParticipant
New
hi robert, perhaps this attachment is clearer of what the strategy is intended to be. thanks for your help
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.
raeParticipant
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.
Sorry for not being able to take a look at it today, I’ll have one tomorrow.
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.