logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Jose  
#1 Posted : Sunday, November 13, 2005 11:44:08 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Below is a Breakout-sensitive Exponential Moving Average indicator (BEMA for short). It reacts quicker (tightens) on price breakouts, and loosens back to normal progressively thereafter. Perhaps it should do the opposite, i.e. loosen on breakouts and tighten progressively thereafter instead. Anyway, maybe there is some usefulness in this variable-period EMA. MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste complete formulae between "---8<---" lines. [code:1:ecb062053d] ============================== EMA - Breakout-sensitive (BEMA) ============================== ---8<------------------------------------- { [B]reakout-sensitive [E]xp [M]ov [A]vg v1.0 } { BEMA based on bars since price breakouts. Options: [1] Composite BEMA: (Upper+Lower)/2; [2] Upper BEMA band based on upside breaks; Lower BEMA band based on downside breaks; [3] BEMA shifts to Upper/Lower on crossovers} { ©Copyright 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("BEMA and HHV/LLV lookback periods", 1,2520,21); plot:=Input("BEMA: [1]Composite, [2]Upper+Lower, [3]Long/Short",1,4,1); spread:=Input("Upper/Lower BEMA bands shift %", 0,100,2)/200; x:=Input("Breakouts, use: [1]Close, [2]High/Low",1,2,1); { Upside breakouts } xup:=If(x=1,C,H); up:=xup=HHV(xup,pds); { Downside breakouts } xdw:=If(x=1,C,L); dw:=xdw=LLV(xdw,pds); { Remove ghost breakout signals } init:=Cum(IsDefined(up+dw))=1; bin:=ValueWhen(1,up-dw<>0 OR init,up); up:=bin AND (Alert(bin=0,2) OR init); dw:=bin=0 AND (Alert(bin,2) OR init); NullZone:=Cum(up)>0 AND Cum(dw)<1 OR Cum(up)<1 AND Cum(dw)>0; { Periods since breakouts } upPds:=BarsSince(up OR Cum(1)=pds)+2; upPds:=If(upPds>pds,pds,upPds); dwPds:=BarsSince(dw OR Cum(1)=pds)+2; dwPds:=If(dwPds>pds,pds,dwPds); { Upside breakout-based EMA } upEma:=xup*2/(upPds+1)+PREV*(1-2/(upPds+1)); upEma:=If(NullZone,Mov(xup,pds,E),upEma); upEma:=upEma*(1+spread); { Downside breakout-based EMA } dwEma:=xdw*2/(dwPds+1)+PREV*(1-2/(dwPds+1)); dwEma:=If(NullZone,Mov(xdw,pds,E),dwEma); dwEma:=dwEma*(1-spread); { Composite BEMA } BEMA:=(upEma+dwEma)/2; LngSht:=If(C>=BEMA,dwEma,upEma); { Plot on price chart } If(plot=1,BEMA,If(plot=2,dwEma, If(plot=3,LngSht,up))); If(plot=1,BEMA,If(plot=2,upEma, If(plot=3,LngSht,-dw))) ---8<------------------------------------- [/code:1:ecb062053d] jose '-)
Jose  
#2 Posted : Sunday, November 13, 2005 11:46:54 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
[code:1:f5c7103ea5] ========================= EMA - (BEMA), dll version ========================= ---8<------------------------------------- { [B]reakout-sensitive [E]xp [M]ov [A]vg v.dll - Plots much faster than PREV-based version.} { BEMA based on bars since price breakouts. Options: [1] Composite BEMA: (Upper+Lower)/2; [2] Upper BEMA band based on upside breaks; Lower BEMA band based on downside breaks; [3] BEMA 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 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("BEMA and HHV/LLV lookback periods", 1,2520,21); plot:=Input("BEMA: [1]Composite, [2]Upper+Lower, [3]Long/Short",1,4,1); spread:=Input("Upper/Lower BEMA bands shift %", 0,100,2)/200; x:=Input("Breakouts, use: [1]Close, [2]High/Low",1,2,1); { Upside breakouts } xup:=If(x=1,C,H); up:=xup=HHV(xup,pds); { Downside breakouts } xdw:=If(x=1,C,L); dw:=xdw=LLV(xdw,pds); { Remove ghost breakout signals } init:=Cum(IsDefined(up+dw))=1; bin:=ValueWhen(1,up-dw<>0 OR init,up); up:=bin AND (Alert(bin=0,2) OR init); dw:=bin=0 AND (Alert(bin,2) OR init); NullZone:=Cum(up)>0 AND Cum(dw)<1 OR Cum(up)<1 AND Cum(dw)>0; { Periods since breakouts } upPds:=BarsSince(up OR Cum(1)=pds)+2; upPds:=If(upPds>pds,pds,upPds); dwPds:=BarsSince(dw OR Cum(1)=pds)+2; dwPds:=If(dwPds>pds,pds,dwPds); { Upside breakout-based EMA } {upEma:=ExtFml("Forum.VarMOV",xup,upPds,e);} upEma:=ExtFml("ASI.EMA",xup,upPds); upEma:=If(NullZone,Mov(xup,pds,E),upEma); upEma:=upEma*(1+spread); { Downside breakout-based EMA } {dwEma:=ExtFml("Forum.VarMOV",xdw,dwPds,e);} dwEma:=ExtFml("ASI.EMA",xdw,dwPds); dwEma:=If(NullZone,Mov(xdw,pds,E),dwEma); dwEma:=dwEma*(1-spread); { Composite BEMA } BEMA:=(upEma+dwEma)/2; LngSht:=If(C>=BEMA,dwEma,upEma); { Plot on price chart } If(plot=1,BEMA,If(plot=2,dwEma, If(plot=3,LngSht,up))); If(plot=1,BEMA,If(plot=2,upEma, If(plot=3,LngSht,-dw))) ---8<------------------------------------- [/code:1:f5c7103ea5] jose '-)
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.