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 : Tuesday, April 24, 2007 11:22:05 AM(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)
Xtend.dll is a very simple and useful tool - it is a MetaStock external function that extends a plot's first/last value to each edge of the chart. Xtend.dll is now available for download free to premium members of the Trader's Consortium forum. http://tradersconsortium.com As for any Trader's Consortium premium members that have previously purchased this tool from MetaStockTools.com, please contact me for a full refund of your US$60. From http://www.metastocktools.com/#metastock : ======================================================= Null (N/A) bar removal, with and without PREV functions. ======================================================= Problem:
Indicators and conditions generally introduce leading and (sometimes) trailing Null (N/A) bars on a plot. These Null bars can stop any other generated signals being plotted during that Null period. For example, a 21-bar SMA will not allow any signals based on it to be plotted on any of the first 20 bars. No other related code can possibly plot within this Null zone. Example:
(note 32/31 bar leading/trailing null zone) ---8{ Three month centered Simple Moving Average } pds:=Input("SMA periods",1,2520,63); Ref(Mov(C,pds,S),LastValue(pds/2)) ---8 Solution 1:
(compare plot to above) ======================= Null bar removal - PREV ======================= ---8 { Removes leading/trailing Null (N/A) bars. Centered SMA example uses hindsight - do not trade. To avoid the PREVx2 processing overhead, try the Xtend.dll custom DLL, available for US$60 through MetaStockTools.com. Also available for free at Trader's Consortium forum: http://tradersconsortium.com ©Copyright 2003-2007 Jose Silva. For personal use only: no resale or repackaging allowed. All code remains the property of Jose Silva. http://www.metastocktools.com } { User input } pds:=Input("SMA periods",1,2520,63); { Centered SMA } indic:=Ref(Mov(C,pds,S),LastValue(pds/2)); { 1st valid plot bar } defined:=IsDefined(indic); bar1:=Cum(defined)=1; { Remove leading/trailing Null bars } NoNull:=If(Cum(defined)>0, LastValue(indic+PREV-PREV), LastValue(ValueWhen(1,bar1,indic))); { Plot on chart } NoNull ---8 The solution above introduces PREV function related problems, mainly a major slowdown of processing speed (not suitable for real-time data), and unreliability issues. Solution 2:
Same null-less plot as above, with the much simpler and more reliable Xtend.dll, and without the PREVx2 processing overhead. ====================== Null bar removal - DLL ====================== ---8 { Removes leading/trailing Null (N/A) bars. Centered SMA example uses hindsight - do not trade. Xtend.dll must be in ...\MetaStock\External Function DLLs\ folder. Xtend.dll custom DLL, available for US$60 through MetaStockTools.com. Also available for free at Trader's Consortium forum: http://tradersconsortium.com ©Copyright 2003-2007 Jose Silva. For personal use only: no resale or repackaging allowed. All code remains the property of Jose Silva. http://www.metastocktools.com } { User input } pds:=Input("SMA periods",1,2520,63); { Centered SMA } indic:=Ref(Mov(C,pds,S),LastValue(pds/2)); { Plot on chart } ExtFml("Xtend.Xtend",indic) ---8 Xtend.dll sample application 1:
================== MA - centered (DLL) ================== ---8 { Centered Moving Average v6.1 Uses forward-referencing to center Mov Avg and project future direction. Uses hindsight - do not trade! Xtend.dll must be in ...\MetaStock\External Function DLLs\ folder. Xtend.dll custom DLL, available for US$60 through MetaStockTools.com. Also available for free at Trader's Consortium forum: http://tradersconsortium.com Copyright © 2003~2007 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("Mov Avg periods",1,2600,21); fwPds:=Input("Forward-referencing periods [automatic: -1]",-1,2600,-1); proj:=Input("Project last known MA: [1]Direction, [2]Value",1,2,1); projCl:=Input("Project back last Close? [1]Yes, [0]No",0,1,0); channel:=Input("Channel +/- boundary %", 0,1000,4)/100; type:=Input("[1]EMA [2]SMA [3]TmSr [4]Tri [5]Var [6]Vol [7]Wght",1,7,2); { Choose MovAvg type: 1 - Exponential MA 2 - Simple MA 3 - Time Series MA 4 - Triangular MA 5 - Variable MA 6 - Volume adjusted MA 7 - Weighted MA } ma:= If(type=1,Mov(C,pds,E), If(type=2,Mov(C,pds,S), If(type=3,Mov(C,pds,T), If(type=4,Mov(C,pds,TRI), If(type=5,Mov(C,pds,VAR), If(type=6,Mov(C,pds,VOL), Mov(C,pds,W))))))); { Automatic period-centering } center:=LastValue(If(fwPds<0,Int(pds/2),fwPds)); { Forward-referenced MovAvg } fwd:=Ref(ma,center); { Last valid MovAvg plot point } valid:=Cum(IsDefined(fwd)) =LastValue(Cum(IsDefined(fwd))); valid:=valid AND Alert(valid=0,2); { Extend MovAvg plot into Null zones } movAvg:=ExtFml("Xtend.Xtend",fwd); { Last MA known direction & future projection } init:=Cum(IsDefined(fwd))=1; direction:=movAvg+ If(IsUndefined(fwd), ValueWhen(1,init OR valid,movAvg)- ValueWhen(1,init OR valid,Ref(movAvg,-1)),0) *BarsSince(init OR valid); { Choose Centered MovAvg type } CMA:=If(proj=1,direction,movAvg); { Projection channels } restrict:=If(BarsSince(valid),CMA,CMA); UpChannel:=restrict*(1+channel); DwChannel:=restrict*(1-channel); { Last Close back-projection } x:=LastValue(C); x:=If(projCl,If(BarsSince(valid),x,x),CMA); { Plot on price chart } UpChannel;DwChannel;x;CMA ---8 Xtend.dll sample application 2
Problem:
---8entry:=Cross(C,Mov(C,5,S)); exit:=Cross(Mov(C,21,S),C); entry-exit ---8 Note how the undefined exit signals in the formula above prevent any entry signals from plotting in the first 20 bars. Why would we want to mix entry & exit signals into a single plot? Compare below to plot above: ---8 { Entry/Exit signals } entry:=Cross(C,Mov(C,5,S)); exit:=Cross(Mov(C,21,S),C); { Remove redundant signals } init:=Cum(IsDefined(entry+exit))=1; bin:=ValueWhen(1,entry-exit0 OR init,entry); long:=bin*(Alert(bin=0,2) OR entry*Cum(entry)=1); short:=(bin=0)*(Alert(bin,2) OR exit*Cum(exit)=1); { Plot in own window } long-short ---8 Now compare to the almost identical version below, where the Null zone is removed from the initial 20 bars of the chart: ================= Null zone removed ================= ---8 { Allows the plotting of entry/exit signals during undefined signal periods. Sample only - do not trade! Xtend.dll must be in ...\MetaStock\External Function DLLs\ folder. Xtend.dll custom DLL, available for US$60 through MetaStockTools.com. Also available for free at Trader's Consortium forum: http://tradersconsortium.com Copyright © 2003~2007 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 } { Entry/Exit signals } entry:=Cross(C,Mov(C,5,S)); exit:=Cross(Mov(C,21,S),C); { Remove Null plot bars } entry:=IsDefined(entry)*ExtFml("Xtend.Xtend",entry); exit:=IsDefined(exit)*ExtFml("Xtend.Xtend",exit); { Remove redundant signals } init:=Cum(IsDefined(entry+exit))=1; bin:=ValueWhen(1,entry-exit0 OR init,entry); long:=bin*(Alert(bin=0,2) OR entry*Cum(entry)=1); short:=(bin=0)*(Alert(bin,2) OR exit*Cum(exit)=1); { Plot in own window } long-short ---8 The Xtend.dll custom DLL is a simple time-saving tool, useful for whenever a plot needs to be extended from the last known defined value through and into the Null (N/A) bar zone. The Xtend function will extend the first definable value backwards to the first bar, and the last definable value forward to the last bar. It does this with minimal processing overheads. Xtend.dll is a small and efficient MetaStock DLL, and is compatible with all versions of MetaStock v7.0 and later. The Xtend.dll custom DLL is available for US$60 through MetaStockTools.com. Also available for free at the download section of Trader's Consortium forum: http://tradersconsortium.com Once downloaded, Xtend.dll can be installed easily: Close MetaStock (v8.0 or later), extract the contents of Xtend.zip and run Xtend.exe, which will place Xtend.dll in the ...\MetaStock\External Function DLLs\ folder, and also import "Null bar removal - DLL" & "MA - centered (DLL)" sample indicators. For MetaStock versions earlier than 8.0, please copy Xtend.dll manually to the ...\MetaStock\External Function DLLs\ folder, and re-start MetaStock. jose '-) http://www.metastocktools.com
Jose  
#2 Posted : Tuesday, April 24, 2007 11:26:19 AM(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)
Apologies for any MetaStock code above that has been truncated by this forum's software. The complete MS code can be viewed here. "Null bar removal - removes leading/trailing null (N/A) bars from any plot." jose '-)
ritabrata  
#3 Posted : Thursday, April 22, 2010 4:50:34 PM(UTC)
ritabrata

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/21/2009(UTC)
Posts: 5
Location: India

Jose,

Thanks a ton for the code [:D] . I was really struggling with NULL/non-defined values of some indicators, and you code finally solved the problem for me.

However, I was unable to download the Xtend.dll file from the Traders Consortium website. It keeps telling me that "you do not have access to this portion of the website"


mstt  
#4 Posted : Thursday, April 22, 2010 7:19:45 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi ritabrata

While I have a lot of respect for Jose's code I realized there's a another easy way to eliminate N/A bars using the Forum DLL ( in the files section as Forum200.DLL I think ). Many of the Forum DLL functions substitute zero for N/A when returning results.

ExtFml("Forum.Sum",data array,1);

If you already have zero's in the unmodified data array then you'll probably need to use the IsDefined() or IsUndefined() functions in conjuction with a Forum DLL function to separate leading or trailing N/A areas from legitimate zeros after modifying the data (not a big problem). It works well in all of my Multi-Frame indicators.

Roy

gabibbo  
#5 Posted : Saturday, April 24, 2010 12:16:54 PM(UTC)
gabibbo

Rank: Member

Groups: Registered, Registered Users
Joined: 1/4/2006(UTC)
Posts: 21

Thanks: 1 times

Hi Roy,

I know you publish a private magazine yet I'd like to ask you if you could expand a little the solution you spoke about in your previous post... I'm particularly interested in plotting a (simple) centered MA where the missing (no/plotting) last n/2 data would be those of a no-lag MA (like an Hull's MA, i.e.)... an actual example would be well accepted.

Thnks anyway and keep up the good work as always.

gabibbo

mstt  
#6 Posted : Saturday, April 24, 2010 5:34:05 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi gabibbo

Does this thread help any? http://forum.equis.com/forums/thread/32347.aspx

Roy

gabibbo  
#7 Posted : Monday, April 26, 2010 11:12:08 AM(UTC)
gabibbo

Rank: Member

Groups: Registered, Registered Users
Joined: 1/4/2006(UTC)
Posts: 21

Thanks: 1 times

Thanks a lot Roy,

I've taken a quick reading of the thread you told me and it seems like blackcat has the same my problem... hoping to find a solution myself I thank you again.

cheers

gabibbo

ps: to anybody interested in forwarding plotted indicator: be careful with all of them, in real-life trading they are not absolutely recommended to take buy/sell decisions as they re-paint the past! I can say that I use them, Tri-CMA in particular, just for having an idea of the actual market-cycles.

ritabrata  
#8 Posted : Tuesday, April 27, 2010 5:25:42 AM(UTC)
ritabrata

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/21/2009(UTC)
Posts: 5
Location: India

mstt,

Thanks for the update [:)] . I had mainly been using indicators that contain a lot of BarsSince(a>b) calls where "a" and "b" themselves are backward looking variables containing BarsSince(). Since you suggest, I will try and have a go at mapping all the indicators based on ForumDLL calls and see how it goes.

regards,

Ritabrata

ritabrata  
#9 Posted : Tuesday, April 27, 2010 5:35:48 AM(UTC)
ritabrata

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/21/2009(UTC)
Posts: 5
Location: India

I also had a look at your posts on the http://forum.equis.com/forums/thread/32347.aspx thread and am trying to implement the same.

Thanks
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.