[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Applying ADX to a momentum oscillator



PureBytes Links

Trading Reference Links

Here are a few examples of how you can combine multiple indicators 
to generate buy and sell signals. You can cut and paste these into 
your indicator. 

I have optimize set in some of these but try that with multiple 
oscillators like this it would literally take days to weeks to run 
it. 

Most of these have Param so that you can play with the periods 
without having to change the code. Right click on the chart to 
change the values.

And some have ParamToggle so you can either look at the waves or the 
buy and sell signals.

Have fun,
Barry

_SECTION_BEGIN("CCI + MACD + RSI");

// This combines three signals into a trading Signal, MACD signal 
crossing, CCI and RSI. 
// The default values are:
// MACD(6,19,9)  crossing 
// RSI(15) > 30 = Buy, < 70 = short
// CCI(30) > 100 = Buy, < -100 = short
// all the parameters are exposed for ease of use
// two functions are exposed, plot and signal (default)

sigPlot = ParamToggle("Display signal", "No|Yes", 1);

perCCI = Optimize( "CCI Period", 100, 90, 150, 2 );
ptCrossCCI = Param("CCI crossover point", 100, 80, 120, 1);
myCCI = CCI( perCCI );

perRSI = Optimize( "RSI Period", 30, 20, 40, 1 );
ptBuyRsi = Param("RSI Buy point", 30, 25, 35, 1);
ptShtRsi = Param("RSI Short point", 70, 65, 75, 1);
myRSI = RSI( perRSI );

// macd 
// Param allows changing parameters without changing the code, the 
default are the standard defaults for MACD
r1 = Param( "MACD Fast avg", 19, 15, 25, 1 );
r2 = Param( "MACD Slow avg", 39, 35, 44, 1 );
r3 = Param( "MACD Signal avg", 9, 8, 12, 1 ); 
tMacd = MACD(r1,r2);
tSig =  Signal(r1,r2,r3);
upMacd = IIf(tMacd > tSig, 1, 0); // up and down signal

myBuy = upMacd AND myRSI > ptBuyRsi AND myCCI > ptCrossCCI ;
myShort = !upMacd AND myRSI < 70 AND myCCI < -ptCrossCCI ;
Buy = Cover = ExRem(myBuy, myShort);
Short = Sell = ExRem(myShort, myBuy);

if (sigPlot)
{
Plot( Buy * C, "CCI(" + NumToStr(perCCI,1.0) + 
	") MACD(" + NumToStr(r1,1.0) +  "," + NumToStr(r2 ,1.0) 
+  "," + NumToStr(r3 ,1.0) + 
	") RSI(" + NumToStr(perRSI ,1.0) +  
	") - myBuy ",  colorGreen); // a positive spike that 
indicates a buy or cover trade.
Plot( -Short * C , "Short ", colorBlue); 
}
else
{
Plot( myCCI, "CCI(" + NumToStr(perCCI,1.0) + ")", colorRed); // a 
positive spike that indicates a buy or cover trade.
Plot( myRSI , "RSI(" + NumToStr(perRSI ,1.0) +  ")", colorBlue);
Plot( tMacd , "MACD(" + NumToStr(r1,1.0) +  "," + NumToStr(r2 ,1.0) 
+  ")", colorGreen); 
Plot( tSig , "Signal(" + NumToStr(r3 ,1.0) + ")",  colorTeal); 
}

// exploration
Filter = Buy OR Short; 
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy/Cover", 1.0);
AddColumn(Short, "Sell/Short",1.0);
_SECTION_END();

_SECTION_BEGIN("ADX + EMA + MACD");

// This combines three indicators into one timing Signal

tgl = ParamToggle("Result", "AND logic|Compare");

// ema 
emaPrice = ParamField("Ema Price field", 3);
PeriodShort = Param("Ema Short Periods", 5, 2, 20, 1);
PeriodLong = Param("Ema Long Periods", 15, 2, 100, 1);
pS = EMA(emaPrice , PeriodShort);
pL = EMA(emaPrice , PeriodLong);
upEma = IIf(pS > pL, 1, 0);		// fast ema is above slow, 
long condition

// 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 = upEma AND upAdx  AND upMacd;
myShort = !upEma AND !upAdx AND !upMacd; 
}
else
{
myBuy = IIf(pS > pL AND myMacd > mySignal AND myPdi > myMdi,1,0);
myShort = IIf(pS < pL AND myMacd < mySignal AND myPdi < myMdi,1,0);
}

Buy = Cover = ExRem(myBuy, myShort);
Short = Sell = ExRem(myShort, myBuy);

Plot( Buy * C, "ADX(" + NumToStr(range,1.0) + 
	") EMA(" + NumToStr(PeriodShort,1.0) + "," + NumToStr
(PeriodLong,1.0) +
	") MACD(" + NumToStr(r1,1.0) + "," + NumToStr(r2,1.0) + "," 
+ NumToStr(r3,1.0) + 
	") - myBuy ",  colorGreen); // a positive spike that 
indicates a buy or cover trade.
Plot( -Short * C , "myShort ", colorRed); 

// exploration
Filter = Buy OR Short; 
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Short, "Short",1.0);

_SECTION_END();

--- In amibroker@xxxxxxxxxxxxxxx, "deherl" <deherl@xxxx> wrote:
>
> Hi,
> 
> Was wondering if anyone can suggest how I would apply ADX to a 
> momentum oscillator like RSI?  Any suggestions would be greatly 
> appreciated.
> 
> Thanks,
> Dave
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/