_SECTION_BEGIN("ADX +MACD");
// This combines two indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
// { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
// adx di lines
range = Param("ADX Periods", 10, 2, 200, 1 );
myPdi = PDI(range );
myMdi = MDI(range );
upAdx = IIf( myPdi > myMdi, 1, 0);
// macd
r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 );
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);
upMacd = IIf(myMacd > mySignal, 1, 0);
// switch test calculation and compare the results
if(tgl)
{
myBuy =upAdx AND upMacd;
myShort = !upAdx AND !upMacd;
}
else
{
myBuy = IIf(myMacd > mySignal AND myPdi > myMdi,1,0);
myShort = IIf(myMacd < mySignal AND myPdi < myMdi,1,0);
}
Buy = Cover = ExRem(myBuy, myShort);
Short = Sell = ExRem(myShort, myBuy);
// exploration
Filter = Buy OR Short;
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Short, "Short",1.0);
_SECTION_END();