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

[amibroker] Re: It's Tax Time - Anyone using Tradekeeper ?



PureBytes Links

Trading Reference Links

I modified the code with your suggested changes, but I still don't 
quite understand how it's different from Johan's. His code prevents a 
line from being drawn when there is no higher/lower pivot to draw 
from if I understand correctly. Could you explain?

Anyway, here are better settings for the pivot points. These are 
provided, I believe, as the default settings in the trading 
software/system I was talking about.

pivothigh = Ref(C,-3)<H AND Ref(H,-2)<H AND Ref(H,-1)<H AND H>=Ref
(H,1);
pivotlow = Ref(C,-3)>L AND Ref(L,-2)>L AND Ref(L,-1)>L AND L<=Ref
(L,1);

They seem to work well on a daily timeframe in large trending stocks.

--- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxx> 
wrote:
> Yes, I saw it, but, if the very first candle is indeed a pivothigh 
> [or a pivotlow] ??
> Dimitris Tsokakis
> --- In amibroker@xxxxxxxxxxxxxxx, "marmal417" <marmal@xxxx> wrote:
> > Thank you for your reply, Dimitris.
> > 
> > Have you seen message 58922 by Johan? This is getting complicated 
> for 
> > my uneducated brain, but it seems that his code also does the 
job? 
> or 
> > is there a difference I'm missing?  
> > 
> > //Martin
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> <TSOKAKIS@xxxx> 
> > wrote:
> > > We could ask x0!=0 and x3!=0, but it is possible for the very 
> first 
> > > bar of your data to be the Lowest [Highest].
> > > So,
> > > The 2nd trendline point should not be the Lowest L[respectively 
> the 
> > > Highest H] up to this bar.
> > > The pivot bar occurred L1-x1 bars ago [respectively L1-x3]
> > > L1=LastValue(BarIndex());
> > > CondL=LastValue(y1==Ref(Lowest(L),-(L1-x1)));
> > > CondH=LastValue(y3==Ref(Highest(H),-(L1-x3)));
> > > The above conditions should be false in order to have 
a "regular" 
> > > line.
> > > One idea is to paint the lines with the ground color.
> > > 
> > >  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));
> > > L1=LastValue(BarIndex());
> > > CondL=LastValue(y1==Ref(Lowest(L),-(L1-x1)));
> > > 
> > > 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));
> > > 
> > > CondH=LastValue(y3==Ref(Highest(H),-(L1-x3)));
> > > 
> > > supplyline=LineArray(x2,y2,x3,y3,1);
> > > Plot(supplyline,"",IIf(CondH!
=1,colorRed,0),styleLine|styleThick|
> > > styleNoRescale|styleNoLabel);
> > > demandLine=LineArray(x0,y0,x1,y1,1);
> > > Plot(demandLine,"",IIf(CondL!=1,colorBlue,0),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;
> > > 
> > > You may arrange also not to plot the shape when CondL, CondH 
are 
> > true 
> > > [they are at the very first bar]
> > > 
> > > Dimitris Tsokakis
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "marmal417" <marmal@xxxx> 
wrote:
> > > > Hello Dimitris,
> > > > 
> > > > I know it's like that. My question is if the code can be 
> modified 
> > > to 
> > > > draw no line if there are no valid pivot points to draw the 
> line 
> > > from?
> > > > 
> > > > //Martin
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> > > <TSOKAKIS@xxxx> 
> > > > wrote:
> > > > > Nice code.
> > > > > You ask although 
> > > > > x0=LastValue(ValueWhen(pivotlow AND L<y1,Cum(1)-1,1));
> > > > > and, respectively
> > > > > x2=LastValue(ValueWhen(pivothigh AND H>y3,Cum(1)-1,1));
> > > > > In this way, some first points may go back more than 2 
years.
> > > > > In the specific case when the recent pivothigh is the 
highest 
> > in 
> > > > the 
> > > > > available stock history the trendline will not be defined. 
> The 
> > > same 
> > > > > when the recent pivotlow is the lowest [many N100 stocks 
> would 
> > be 
> > > > > without support line back in Oct2002...].
> > > > > Besides that, if the recent pivothigh is the highest, the 
> > > > resistance 
> > > > > line has a strange beginning.Try for example to import is 
> some 
> > > > > database APOL from Feb2001 till now to see what I mean.
> > > > > Dimitris Tsokakis
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "marmal417" <marmal@xxxx> 
> > wrote:
> > > > > > 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



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

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/