Skip to main content

Combining EMA crossover and ADX for Amibroker (AFL)

vivekjain over 15 years ago Amibroker (AFL)

  • Rating:
    3 / 5 (Votes 4)
  • Tags:
    oscillator, trading system, amibroker

Have been trying to get a better hit ratio with combination of some trend following indicators. Most trend following indicators have worked well in India only on the long side, was trying to come up with some combination that works on the short side as well.

Have tried various combinations targeting a better hit rate and high P/L ratio but smaller drawdown. EMA cross with ADX and RSI worked well. Let me know your thots. Did not find putting a stop (trailing or otherwise) useful.

Its a draft version, need to work on some more combinations and posotion sizing. Has given good returns on a basket of stocks (3+) in India.

Indicator / Formula

Copy & Paste Friendly
//Shortavg=Param("Short average",13,5,25,2);
Longavg=Param("Long average",13,5,80,2);
TrendAvg=Param("Trender average",21,5,100,3);
Dix = Param ("Directional Index",14,5,25,1);
Oversold = Param ( "Oversold", 50, 20, 70, 5 );
Overbot = Param ("Overbot", 50, 50, 100, 5 );
ADXThreshold = Param ("ADXThreshold",15,5,25,1);


//MACD//
FAST = Param("FAST",12,0,100,1);
SLOW = Param("SLOW",26,0,100,1);
SIG  = Param("SIG",5,0,100,1);
 
MACDLine   = MACD(FAST,SLOW);
MACDSignal = Signal(FAST,SLOW,SIG);
 
 
//Trendscore//
TrendScore =
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1)+
IIf(C>=Ref(C,-21),1,-1)+
IIf(C>=Ref(C,-22),1,-1);
 
/////////////////AROON////////////////////
 
Period = 14;
LLVBarsSince = LLVBars(L, Period) + 1;
HHVBarsSince = HHVBars(H, Period) + 1;
 
AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1);
AroonUp   = 100 * (Period - HHVBarsSince) / (Period - 1);

///Buy and cover// 
Buy = Cross(C, EMA(C,Longavg)) //AND (C>=EMA(C,TrendAvg))
AND (ADX (Dix) > ADXThreshold)
AND PDI(Dix)>MDI(Dix) 
//AND MACDLine>MACDSignal;
AND (RSI(14)>Oversold);
//AND AroonUp>30;
Cover = C>EMA(C,Longavg) AND RSI(14)>Oversold;

//Short AND Sell//
Short = Cross(EMA(C,Longavg), C) //AND (C<=EMA(C,TrendAvg))
AND (ADX (Dix) > ADXThreshold)
AND PDI(Dix)>MDI(Dix)
//AND MACDLine<MACDSignal;
AND (RSI(14)<Overbot);
//AND AroonDn>30;
Sell = C<EMA(C,Longavg) AND RSI(14)<Overbot;
 
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

Cover = ExRem(Cover, Short);
Short = ExRem(Short, Cover);
PlotShapes(Buy *shapeUpArrow, colorLime, 0, L, Offset = -20);
PlotShapes(Sell *shapeHollowDownArrow, colorOrange, 0, H, Offset = -10);
PlotShapes(Short *shapeDownArrow, colorRed, 0, H, Offset = -20);
PlotShapes(Cover *shapeHollowUpArrow, colorGreen, 0, L, Offset = -10);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
 
PositionSize = -20;
//StopAmount = 10 * ATR( 20 );
//ApplyStop( 0, 2, StopAmount, 1 );
//AND (ADX (Dix) < 50)
// trendscore>5;
// AND trendscore>5

11 comments

over 15 years ago

Hollow arrows are acting as better buy and short signals. From my visual backtesting, I find it profitable. Buying and Shorting on solid arrows, Selling and Covering on hollow arrows is leading to losses.

over 15 years ago

Extra codes added as mentioned above. last line shows syntax error.Admin-pls correct.Amibroker 5.30.

Leave Comment

Please login here to leave a comment.