| 
Rank: Advanced Member
 Groups: Registered, Registered UsersJoined: 1/19/2005(UTC)
 Posts: 1,065
 Location: Koh Pha-Ngan, Earth
 
 Was thanked: 2 time(s) in 2 post(s)
 | 
            
	      
                As mentioned above, this version of the PEMA plots much faster, thanks to the use of variable-period DLLs which circumvent the very slow PREV functions.
[code:1:ef3bb517da]
MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formulae between "---8<---" lines.
==========================
EMA - pivotal, dll version
==========================
---8<------------------------------------
{ Pivotal Exponential Moving Average v.dll
 - Plots much faster than PREV-based version.}
{ PEMA based on trough/peak support/resistance.
 Options:
 [1] Composite EMA: (Upper+Lower)/2;
 [2] Upper EMA band based on peaks;
 Lower EMA band based on troughs;
 [3] EMA shifts to Upper/Lower on crossovers }
{ Forum.dll from http://forum.equis.com
 or ASI.dll from http://www.thedml.com
 must be in:
 ...\\MetaStock\\External Function DLLs\\ folder.}
{ ©Copyright 2004~2005 Jose Silva.
 The grant of this license is for personal use
 only - no resale or repackaging allowed.
 All code remains the property of Jose Silva.
 http://www.metastocktools.com }
{ User inputs }
pds:=Input("EMA periods",1,2520,21)/2;
plot:=Input("EMA: [1]Composite, [2]Upper+Lower, [3]Long/Short",1,3,1);
spread:=Input("Upper/Lower EMA bands shift %",
 0,100,2)/200;
x:=Input("use: [1]Close, [2]High/Low",1,2,1);
{ Peak/Troughs }
xpk:=If(x=1,C,H);
pk:=xpk<Ref(xpk,-1) AND Ref(xpk,-1)>Ref(xpk,-2);
pkVal:=ValueWhen(1,pk,Ref(xpk,-1));
xtr:=If(x=1,C,L);
tr:=xtr>Ref(xtr,-1) AND Ref(xtr,-1)<Ref(xtr,-2);
trVal:=ValueWhen(1,tr,Ref(xtr,-1));
{ Peak-based EMA }
pkpds:=If(pds>Cum(pk),Cum(pk),pds);
pkpds:=If(pkpds<1,1,pkpds);
{pkEma:=ExtFml("Forum.VarMOV",pkVal,pds,e);}
pkEma:=ExtFml("ASI.EMA",pkVal,pds);
pkEma:=pkEma*(1+spread);
{ Trough-based EMA }
trpds:=If(pds>Cum(tr),Cum(tr),pds);
trpds:=If(trpds<1,1,trpds);
{trEma:=ExtFml("Forum.VarMOV",trVal,pds,e);}
trEma:=ExtFml("ASI.EMA",trVal,pds);
trEma:=trEma*(1-spread);
{ Composite EMA }
Ema:=(pkEma+trEma)/2;
LngShtEma:=If(C>=Ema,trEma,pkEma);
{ Plot on price chart }
If(plot=1,Ema,If(plot=2,trEma,LngShtEma));
If(plot=1,Ema,If(plot=2,pkEma,LngShtEma))
---8<------------------------------------
[/code:1:ef3bb517da]
jose '-) |