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

[amibroker] Multi MA with Shift



PureBytes Links

Trading Reference Links

Hi,

I've posted the below code in case anyone else like me is starting out
and notice some of the indicators installed by AB are a little lacking.
Being used to Metatrader and now starting to use AB for a particular
divergence strategy, I noticed I didn't readily have MA types with
period shift. (Special thanks to Ara Kaloustian for his divergence
indicator - powerful stuff)

[1] I quickly coded the below and wondered if I could make improvements
and/or cut down any on the repetition

[2] Does AB have an equivalent of a SWITCH / CASE function which might
cut down on the IF / ELSE statements as well as speed up the code ?

====code start====
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 400, 1, 10 );
MAType = ParamList("MA Type", "Simple MA|Exponential MA|Weighted
MA|Wilder's Smoothing|Double EMA|Triple EMA" ,1);
MAshift = Param( "Shift", 0, -25, 0, 1 );

if (MAType == "Simple MA")			
{
Plot( Ref(MA( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
else
if (MAtype == "Exponential MA")
{
Plot( Ref(EMA( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
else
if (MAType == "Weighted MA")
{
Plot( Ref(WMA( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
else
if (MAType == "Wilder's Smoothing")
{
Plot( Ref(Wilders( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
else
if (MAType == "Double EMA")
{
Plot( Ref(DEMA( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
else
if (MAType == "Triple EMA")
{
Plot( Ref(TEMA( P, Periods ), MAshift), _DEFAULT_NAME(), ParamColor(
"Color", colorCycle ), ParamStyle("Style") );
}
====code end====

Cheers
Martin



------------------------ 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/