[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: TD Lines



PureBytes Links

Trading Reference Links

Yes, that's it! Now it automatically draws the most recent demand 
line. I took the liberty to add a supply line by mirroring your code 
and making the small changes necessary, but I never understood what I 
was doing :-) I noticed a weird thing when this indicator is applied 
to a stock making a new all time high. If the most recent pivothigh 
is higher than any other pivothigh in the database then a line is 
drawn from the bottom in the middle of the chart through the most 
recent pivot high. It looks really strange. Can the code be modified 
to draw no supplyline when there are no higher pivots to draw the 
line from and draw no demand line when there are no lower pivots to 
draw the line from?

The basis for the systems I have seen based on TD Lines is that you 
buy/cover when the supplyline is exceeded and sell/short when the 
demand line is broken. Trendlines let you know in advance the day 
before, the value of the trendline for the next trading day by 
calculating the slope of the line and adding it to today's value of 
the line. Therefore, one can place the orders in the evening as stop 
orders so if a line is broken during the day a position is taken. 
Anyway, I wrote the values of the lines for the next day in the 
title. I realise it's not perfect, because some lines are no longer 
valid lines (for example a supply line that has been exceeded etc.). 
But more on that later.

There are more improvements to be made, but I think it's getting 
there :-)
//Martin

Here is the modified code with both a supply and demand line:

Plot(C,"",colorBlack,styleBar);
pivothigh = Ref(H,-1)<H AND H>Ref(H,1);
pivotlow = Ref(L,-1)>L AND L<Ref(L,1);

x1=LastValue(ValueWhen(pivotlow,Cum(1)-1,1));
y1=LastValue(ValueWhen(pivotlow,L,1));
x0=LastValue(ValueWhen(pivotlow AND L<y1,Cum(1)-1,1));
y0=LastValue(ValueWhen(pivotlow AND L<y1,L,1));
x3=LastValue(ValueWhen(pivothigh,Cum(1)-1,1));
y3=LastValue(ValueWhen(pivothigh,H,1));
x2=LastValue(ValueWhen(pivothigh AND H>y3,Cum(1)-1,1));
y2=LastValue(ValueWhen(pivothigh AND H>y3,H,1));

supplyline=LineArray(x2,y2,x3,y3,1);
Plot(supplyline,"",colorRed,styleLine|styleThick|
styleNoRescale|styleNoLabel);
demandLine=LineArray(x0,y0,x1,y1,1);
Plot(demandLine,"",colorBlue,styleLine|
styleThick|styleNoRescale|styleNoLabel);

PlotShapes((Cum(1)-1==x0 OR Cum(1)-1==x1)
*shapeSmallCircle,colorBlue,0,L);
PlotShapes((Cross(Cum(C<demandLine AND Cum(1)-1>x1),0))
*shapeDownArrow,colorRed,0,H);
PlotShapes((Cum(1)-1==x2 OR Cum(1)-1==x3)
*shapeSmallCircle,colorRed,0,H,12);
PlotShapes((Cross(Cum(C>supplyline AND Cum(1)-1>x3),0))
*shapeUpArrow,colorGreen,0,L);

Title= Name()+" "+Date()+EncodeColor(colorBlack) +" Open-"+WriteVal
(Open)+" Hi-"+WriteVal(High)+" Lo-"+WriteVal(Low)+" Close-"+WriteVal
(Close) +EncodeColor(colorBlue)+WriteVal((y1-y0)/(x1-x0)+LastValue
(DEMAndline))+EncodeColor(colorRed)+WriteVal((y3-y2)/(x3-x2)+LastValue
(supplyline));
GraphXSpace=4;
--- In amibroker@xxxxxxxxxxxxxxx, "johsun" <johanskatt@xxxx> wrote:
> OK, I think I get it. Is this what you're looking for?
> 
> Johan
> 
> 
> Plot(C,"",colorGreen,styleBar);
> pivotlow = Ref(L,-1)>L AND L<Ref(L,1);
> 
> x1=LastValue(ValueWhen(pivotlow,Cum(1)-1,1));
> y1=LastValue(ValueWhen(pivotlow,L,1));
> x0=LastValue(ValueWhen(pivotlow AND L<y1,Cum(1)-1,1));
> y0=LastValue(ValueWhen(pivotlow AND L<y1,L,1));
> 
> Line=LineArray(x0,y0,x1,y1,1);
> Plot(Line,"",colorBlue,styleLine|
> styleThick|styleNoRescale|styleNoLabel);
> PlotShapes((Cum(1)-1==x0 OR Cum(1)-1==x1)
> *shapeSmallCircle,colorBlue,0,L);
> PlotShapes((Cross(Cum(C<Line AND Cum(1)-1>x1),0))
> *shapeDownArrow,colorRed,0,H);
> 
> 
> Title="TD Demand Line";
> GraphXSpace=4;
> 
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "marmal417" <marmal@xxxx> wrote:
> > Thank you very much, Johan. I replaced all the SelectedValue with 
> > Lastvalue to only get the most recent trendline. I think your 
> formula 
> > does exactly what I described. However, after looking at some 
> charts 
> > I realised my description was a bit wrong. You see, there should 
> > always be a demand line (upward sloping line) connecting the most 
> > recent pivot with the second most recent pivot that is also lower 
> > than the most recent. This code compares the two most recent 
> > pivotpoints and if the second most recent is greater than the 
most 
> > recent, then no line is drawn. What it really should do is first 
> > identify the most recent pivot, and then go back and look for the 
> > next pivot that is lower and connect those two with a line, 
> wherever 
> > that next pivot is. The exception is when a stock makes a new all 
> > time low, because then no lower pivot point can exist to draw a 
> line 
> > from.  
> > 
> > Maybe this requires a lot more programming, but can it be done?
> > 
> > So far I think it's a great start!
> > //Martin



Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
     amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/