Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 8/11/2005(UTC) Posts: 104
|
Hi
Using the MetaStock Channel formula below
I would like to draw a vertical line from the
" Start point " on the Upper Channel Line
Down to the "Start point "on the Lower Channel Line
Forming a Rhomboid figure ( lozenge shape )
( not a vertical line from zero to the top of the Chart )
----------"------------------------------------------------------------
Periods:=Input("Periods",5,1000,633);
nd:= Input("number of deviations",0,10,2);
end:=LastValue(Cum(1));
pt:=LastValue(LinearReg(C,Periods));
slope:=LastValue(LinRegSlope(C,Periods));
start:=BarsSince(Cum(1)>=end-(Periods-1));
center:=If(start=0,pt - (slope*(end-Cum(1))),0);
dis:=nd*LastValue(STE( C, Periods));
center+dis;
{center;}
center-dis
-----------"---------------------------------------------------------------------------------------
Hoping you can oblige
Best regards,
Derek
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Views messages in topic : 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi Derek
As far as I'm aware it is not possible to draw a perfectly vertical line between two values on a chart simply by using MFL code. There are ways that you can approximate this and one method is to "float" a histogram line and then "blank" the unwanted lower part of the line with a wider line the same colour as the chart background. This type of solution really needs to be set up in a template as it takes some time to create the required effect.
By "float" I'm referring to the practice of adding an N/A result or output immediately after an indicator's valid result so that the valid plot is no longer constrained by the upper and lower limits of the chart window to which it is applied. The valid plot can then be scaled to the price plot without grossly distorting the price it's scaled to - the histogram's zero / inactive value floats out of view below the bottom edge of the window.
Perhaps a more appropriate solution, albeit one that has a one-bar slope for the box "vertical" lines, is to use the method demonstrated in the "Volume By Price" indicator discussed in the August 2008 issue of MSTT. The method plots an upper and lower line and uses the first and last bar of the box to switch lines to the opposite border - the lower line switches from the top to the bottom on the first bar of the box and the upper line switches from the top to the bottom on the last bar of the box.
Sloping lines are drawn by marking start and end points and using the change in value between those points to calculate a precise increment or decrement for each bar. This is what I wrote in the January 2006 issue of MSTT about drawing simple lines.
"The concept of drawing a line on an MS chart is quite simple once the basic steps are understood. Here are the steps I see as necessary to create an elementary straight line in a chart.
1. Determine the start point.
2. Determine the start value.
3. Determine the end point.
4. Determine the end value.
5. Calculate the number of bars between the start and end points.
6. Divide the difference between the start and end values by the number of bars between the start and end points.
7. Cumulatively add the result from step 6 to each successive bar from the start point."
Terminating lines prior to the right side of the chart is probably most easily accomplished by using the "Ref() two-step" piece of code. First calculate how many bars need to be blanked (forced to plot N/A), then shift the line that many bars to the right and then the same number of lines to the left. In other words use one Ref() function nested inside another. The inner Ref() function is calculated first so it's the one requiring a positive value.
Ref(Ref("My line variable", +N), -N);
You might like to do a search to find posts on various points of interest.
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Views messages in topic : 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi Derek
My mistake. The "Ref() two-step" requires the inner Ref() function to have a negative Periods value to move the line to the right. Here's the line-drawing exercise I used in the MSTT article.
{Exercise 1} {drawing a line} Date1:=(DayOfMonth()=5)*(Month()=10)*(Year()=2009); {starting date} Date2:=(DayOfMonth()=21)*(Month()=12)*(Year()=2009); {ending date} Price1:=C; {starting price} Price2:=C; {ending price} V1:=ValueWhen(1,Date1,Price1); V2:=LastValue(ValueWhen(1,Date2,Price2)); B1:=LastValue(BarsSince(Date1)); B2:=LastValue(BarsSince(Date2)); Line:=V1-Cum((Date1=0)*(V1-V2)/(B1-B2)); Ref(Ref(Line,-B2),+B2);
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 8/11/2005(UTC) Posts: 104
|
Hi Roy,
Thank you very much for your help.
Kind regards,
Derek
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 8/11/2005(UTC) Posts: 104
|
Hi,
Below is my best attempt so far
Could you tidy up the formula below?
I plotted the formula below on the S&P 500 Index.
Could anyone inform me how attach a screen shot to a letter to the forum ?
------------------------------------------------------"
Periods:=Input("Periods",5,1000,633);
nd:= Input("number of deviations",0,10,2);
end:=LastValue(Cum(1));
pt:=LastValue(LinearReg(C,Periods));
slope:=LastValue(LinRegSlope(C,Periods));
start:=BarsSince(Cum(1)>=end-(Periods-1));
center:=If(start=0,pt - (slope*(end-Cum(1))),0);
dis:=nd*LastValue(STE( C, Periods));
center+dis;
{center; }
center-dis;
If(Cum(1)=(end-(Periods-1)),center+dis,center-dis); If(Cum(1)=(end-(Periods-1)),center-dis,center+dis);
-----------------------------------------------------------------------"
Kind regards,
Derek
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Views messages in topic : 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi Derek
I've looked at the code and chart you sent me by email and my immediate comment is "Wow". It looks pretty near perfect to me and the only things I'd change are to eliminate one of the "verical" lines at the beginning of the plot and to comment out the duplicated ouputs. I don't think you really need any further help as you obviously know what you want and you've demonstrtated that you have the skills needed to follow through. Well done.
Roy
|
|
|
|
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.