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

Notification

Icon
Error

Options
Go to last post Go to first unread
CN001532  
#1 Posted : Friday, September 23, 2005 2:19:48 AM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

I've tried the snippets of code posted here concerning breaking a straight trendline, but nothing seems to fit to the following task: I'd like to create an indicator that will indicate when the CCI(14) crosses a "straight trendline" drawn from the most recent low/high of the CCI(14). I don't need the trendline to actually be drawn on the chart. Bearish Break of CCI Trendline The trendline should begin when value of the CCI(14) is at its most recent lowest low (under -100). The trendline should end when the value of the CCI(14) is at its most recent highest high (over +100). The signal is a break of the "upsloping" CCI trendline by the CCI (14) only when the value of the CCI(14)>100. i.e After the CCI exceeds +100, we are looking for a break of the trendline to downside and have the CCI(14) come back under +100 for a signal is generated. If the trendline is broken anytime before the value of the CCI(14) reaches +100, ignore. The pattern is dashed. Bullish Break of Trendline The trendline should begin when value of the CCI(14) is at its most recent high (above +100). The trendline should end when the value of the CCI(14) is at its most low point (less - 100). The signal is a break of the "downsloping" CCI trendline by the CCI (14) only after the value of the CCI(14)<-100. i.e After the CCI(14) crosses < -100, we need the CCI(14) to cross back over the trendline and have the CCI(14) cross the -100 line for a signal to be generated. If the CCI(14) crosses "straight trendline" anytime before the value of the CCI(14) reaches -100, ignore. I'm not sure if this can be coded at all. very easy to draw a manual trendline and observe however. Any thoughts or approaches would be welcomed. Regards, Joe
Jose  
#2 Posted : Friday, September 23, 2005 5:15:16 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)
CN001532 wrote:
I don't need the trendline to actually be drawn on the chart.
Believe me, you will. ;) You need to keep all code visual to verify that it works, otherwise the whole process becomes hit-and-miss. My advice would be to adapt the trendline code at http://www.metastocktools.com/MetaStock/2plot.txt Here is a hint: [code:1:22c0d7a112] MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste formula below. =============== Trendline - CCI =============== ---8<----------------------- { CCI trendline v1.0 } { ©Copyright 2005 Jose Silva } { For personal use only } { http://www.metastocktools.com } { User Inputs } pr:=Input("Indicator Peak/Trough %", .01,1000,50); pds:=Input("Indicator periods",1,2600,14); { Indicator } x:=CCI(pds); { Indicator peak/troughs } pk:=PeakBars(1,x,pr)=0; tr:=TroughBars(1,x,pr)=0; { Define trendline events } time1:=pk; time2:=tr; time2:=time2 AND time2<>time1; val1:=ValueWhen(1,pk,x); val2:=ValueWhen(1,tr,x); { Restrict trendline to last two events} time1:= time1 AND Cum(time1)=LastValue(Cum(time1)); time2:= time2 AND Cum(time2)=LastValue(Cum(time2)); { Sort trendline events} t1pds:=LastValue(BarsSince(time1)); t2pds:=LastValue(BarsSince(time2)); x1:=If(t1pds>=t2pds,time1,time2); x2:=If(t1pds>=t2pds,time2,time1); y1:=If(t1pds>=t2pds,val1,val2); y2:=If(t1pds>=t2pds,val2,val1); { Fix trendline coordinates} y1:=ValueWhen(1,x1,y1); y2:=LastValue(ValueWhen(1,x2,y2)); b1:=LastValue(BarsSince(x1)); b2:=LastValue(BarsSince(x2)); { Trendline definition} plot:=y1+BarsSince(x1)*(y2-y1)/(b1-b2+.000001); { Un-rem line below to restrict trendline } {plot:=Ref(Ref(plot,-b2),b2);} { Plot in own window } x;plot ---8<----------------------- [/code:1:22c0d7a112] jose '-) http://www.metastocktools.com .
CN001532  
#3 Posted : Friday, September 23, 2005 10:27:25 AM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

thanks Jose i'll give it a try, If found that if as long as CCI(14)>Ref(CCI(14),-3) approximates the "trendline" fairly well.
CN001532  
#4 Posted : Friday, September 23, 2005 11:14:16 AM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

wow jose, this code gets me unbelieveably close. Now I know I defined the trendline as a straight line between the the highest and lowest point and that is appropriate for a 2 point plot. I do have a general question - which probably entails a much greater level of complexity - What would it take to draw an upward sloping trendling that touches the bottom various "bumps" of the line on the way up- conversely if the trendline were downward sloping - the various tops of the "bumps" on the way down. I'm guessing that this kind of programming exceeds the capability of the 2 point plot, (And I realize one could get awfully close to the optimal solution by defining a % break away from the 2 plot line with a lot less complexity) - just curious though. regards, joe
Jose  
#5 Posted : Friday, September 23, 2005 11:38:41 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)
Joe wrote:
What would it take to draw an upward sloping trendling that touches the bottom various "bumps" of the line on the way up- conversely if the trendline were downward sloping - the various tops of the "bumps" on the way down.
Unless someone else would like to tackle this one, it would probably take the professional services of a competent MetaStock programmer. ;) jose '-) http://www.metastocktools.com .
CN001532  
#6 Posted : Saturday, September 24, 2005 5:05:42 PM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

Is there anyway to use the Dynamic trading tools trendline up auto function to work on an indicator rather than price?
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.