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

Re: [amibroker] Re: Peaks and Troughs detection



PureBytes Links

Trading Reference Links

1. To calculate peaks and troughs as resistances and supports, I prefer to use Ref() function, because breakouts couldn't correctly detect any time one of them happens the same day when a new peak (or trough) is established.

res = Ref(Peak(H,Change,1),-1);
sup = Ref(Trough(L,Change,1),-1);

2. As you suggested, I ran your full formula on ACG and these are the results:

ACG 12/11/2001 8.94 0.00 
ACG 27/12/2001 0.00 7.25 

Your yellow line reproduces last closing price, but what I need is the value indicated by my yellow line, that is 8.3, and not 7.25 or 7.94.

Thanks in advance and best regards,

Franco
----- Original Message ----- 
From: dtsokakis 
To: amibroker@xxxxxxxxxxxxxxx 
Sent: Saturday, April 20, 2002 6:47 PM
Subject: [amibroker] Re: Peaks and Troughs detection


And here is the full formula for any use [AA explore mode and 
indicator builder]

perc=5;//Calibrate sensitivity
//Last Peak detection
p1=PeakBars(H,perc,1)==0;
H1=ValueWhen(p1,H,1);p2=H1>LastValue(C);
p=p1 AND p2;x1=Cum(p);x1max=LastValue(x1);
//Last Trough Detection
t1=TroughBars(L,perc,1)==0;
L1=ValueWhen(t1,L,1);t2=L1<LastValue(C);
t=t1 AND t2;y1=Cum(t);y1max=LastValue(y1);
PeakA=p AND x1==x1max;
TroughA=t AND y1==y1max;
Filter= PeakA OR TroughA;
AddColumn(IIf(PeakA,H,0),"Last Peak",1.2);
AddColumn(IIf(TroughA,L,0),"Last Trough",1.2);
Sell=p AND x1==x1max;
Buy=t AND y1==y1max;
LastPt=ValueWhen(PeakA,Cum(1),1);
LastPeak=ValueWhen(PeakA,H,1);
LastTt=ValueWhen(TroughA,Cum(1),1);
LastTrough=ValueWhen(TroughA,L,1);
Plot(C,"",1,64);
Plot(IIf(Cum(1)>=LastPt,LastPeak,-1e10),"",4,1);
Plot(IIf(Cum(1)>=LastTt,LastTrough,-1e10),"",5,1);
Plot(IIf(Cum(1)>=Max(LastPt,LastTt),LastValue(C),-1e10),"",7,1);

I do not think I have something more to add.
DT
--- In amibroker@xxxx, "dtsokakis" <TSOKAKIS@xxxx> wrote:
> Franco,
> If the previous code was confusing you, try this one.
> In AA select a stock and EXPLORE for all quotations.
> Then double click on the results list.
> You read the values of the last Peak [Last trough] above [below] 
last 
> close value [I forced the useless reading to zero] and the arrows 
> mark the respective points.
> If you need anything else, please advise.
> DT
> 
> perc=5;//Calibrate sensitivity
> //Last Peak detection
> p1=PeakBars(H,perc,1)==0;
> H1=ValueWhen(p1,H,1);p2=H1>LastValue(C);
> p=p1 AND p2;x1=Cum(p);x1max=LastValue(x1);
> //Last Trough Detection
> t1=TroughBars(L,perc,1)==0;
> L1=ValueWhen(t1,L,1);t2=L1<LastValue(C);
> t=t1 AND t2;y1=Cum(t);y1max=LastValue(y1);
> PeakA=p AND x1==x1max;
> TroughA=t AND y1==y1max;
> Filter= PeakA OR TroughA;
> AddColumn(IIf(PeakA,H,0),"Last Peak",1.2);
> AddColumn(IIf(TroughA,L,0),"Last Trough",1.2);
> Sell=p AND x1==x1max;
> Buy=t AND y1==y1max;
> 
> --- In amibroker@xxxx, "dtsokakis" <TSOKAKIS@xxxx> wrote:
> > Franco, 
> > please, read again 
> > http://groups.yahoo.com/group/amibroker/message/14929
> > It is an exploration. It works in Automatic Analysis.
> > Select a stock, Explore for All quotations and then doubleclick 
on 
> > the results list.
> > You will see the arrows marking the points you ask.
> > It is NOT an ind. builder formula, there is nothing to be plotted.
> > The arrows are at the last peak [last trough] which satisfies the 
> > above LastValue(close) requirement [respectively below LastValue
> > (close)]. If a peak [trough] does not fulfil this criterion is 
> > skipped [we may change this priority, if you like.]
> > DT
> > 
> > --- In amibroker@xxxx, franco fornari <ffpsi@xxxx> wrote:
> > > Dimitris,
> > > 
> > > I'm manifestly not able to make me clear. Probably it
> > > depends on my poor english.
> > > Since I received more than one messages, out of
> > > chronological order (because Yahoo mail), I'll try to
> > > summarize my (maybe wrong) point of view.
> > > 
> > > 1. Look, please, at the first two attached gif. They
> > > plot my and your formulas, respectively. Do you see
> > > any difference? I can't. Moreover, I suppose for the
> > > two lines of code:
> > > 
> > > AddColumn(H,"Last Peak",1.2);
> > > AddColumn(L,"Last Trough",1.2);
> > > 
> > > you really meant as follows:
> > > 
> > > AddColumn(H1,"Last Peak",1.2);
> > > AddColumn(L1,"Last Trough",1.2);
> > > 
> > > 2. Look, now, at the third attached gif. I have
> > > manually added a yellow line, wich shows what level I
> > > wish to detect: the last trough higher than last
> > > closing price. Not the last trough by absolute. In
> > > this case it is the second last, but sometimes it
> > > could be the third from last or more.
> > > 
> > > 3. Running your exploration system, I don't find the
> > > value I need on the last line of results, but on the
> > > second last one. Then, it is not available for further
> > > applications.
> > > 
> > > 4. You said "Single points localization is not the
> > > easiest AFL sport". Well, I think AmiBroker is very
> > > powerful, but I don't expect it is omnipotent. If you,
> > > or any other person so expert as you are, says a
> > > certain thing is not possible, 
> > 
> > As far as I read my text, I did not say anything impossible.
> > [how should I write such a thing !!]
> > Although this discussion is a bit confused, we could simplify 
> things.
> >  
> > I can accept this.
> > > Maybe Tomasz will turn it possible in future, or maybe
> > > not. Anyway, the life will go on.
> > > 
> > > Best regards and thanks again for the time you spend
> > > to help me.
> > > 
> > > Franco
> > > 
> > > 
> > 
> 
______________________________________________________________________
> > > Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA
> > > http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/
> > > 
> > > 
> > 
> 
______________________________________________________________________
> > > Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA
> > > http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/
> > > 
> > > 
> > 
> 
______________________________________________________________________
> > > Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA
> > > http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/


Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


------=_NextPart_001_004B_01C1E8AA.9D13F620
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Dimitris,</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;</FONT></DIV>
<DIV><FONT face=Arial size=2>as attachment, I send to&nbsp;you some newcharts 
to clarify my thought.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>1. To calculate&nbsp;peaks and troughs as 
resistances and supports, I prefer to use Ref() function, because&nbsp;breakouts 
couldn't correctly detect&nbsp;any time one of them&nbsp;happens the same day 
when a new peak (or trough) is established.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>res&nbsp;= <FONT color=#0000ff>Ref</FONT>(<FONT 
color=#0000ff>Peak</FONT>(<B>H</B>,Change,<FONT color=#ff00ff>1</FONT>),-<FONT 
color=#ff00ff>1</FONT>);</FONT></DIV>
<DIV><FONT face=Arial size=2>sup = <FONT color=#0000ff>Ref</FONT>(<FONT 
color=#0000ff>Trough</FONT>(<B>L</B>,Change,<FONT color=#ff00ff>1</FONT>),-<FONT 
color=#ff00ff>1</FONT>);</FONT></DIV>
<DIV><FONT face=Arial size=1></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>2. As you suggested, I ran your full formula on ACG 
and these are the results:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>ACG&nbsp;12/11/2001&nbsp;8.94&nbsp;0.00&nbsp;<BR>ACG&nbsp;27/12/2001&nbsp;0.00&nbsp;7.25&nbsp;<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>Your yellow line reproduces last closing price, but 
what I need is the value indicated by my yellow line, that is 8.3, and not 7.25 
or 7.94.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Thanks in advance and best regards,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Franco</DIV></FONT>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV 
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
dtsokakis 
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=amibroker@xxxxxxxxxx 
href="mailto:amibroker@xxxxxxxxxxxxxxx";>amibroker@xxxxxxxxxxxxxxx</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, April 20, 2002 6:47 
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [amibroker] Re: Peaks and 
Troughs detection</DIV>
<DIV><BR></DIV><TT>And here is the full formula for any use [AA explore mode 
and <BR>indicator builder]<BR><BR>perc=5;//Calibrate sensitivity<BR>//Last 
Peak 
detection<BR>p1=PeakBars(H,perc,1)==0;<BR>H1=ValueWhen(p1,H,1);p2=H1&gt;LastValue(C);<BR>p=p1 
AND p2;x1=Cum(p);x1max=LastValue(x1);<BR>//Last Trough 
Detection<BR>t1=TroughBars(L,perc,1)==0;<BR>L1=ValueWhen(t1,L,1);t2=L1&lt;LastValue(C);<BR>t=t1 
AND t2;y1=Cum(t);y1max=LastValue(y1);<BR>PeakA=p AND x1==x1max;<BR>TroughA=t 
AND y1==y1max;<BR>Filter= PeakA OR TroughA;<BR>AddColumn(IIf(PeakA,H,0),"Last 
Peak",1.2);<BR>AddColumn(IIf(TroughA,L,0),"Last Trough",1.2);<BR>Sell=pAND 
x1==x1max;<BR>Buy=t AND 
y1==y1max;<BR>LastPt=ValueWhen(PeakA,Cum(1),1);<BR>LastPeak=ValueWhen(PeakA,H,1);<BR>LastTt=ValueWhen(TroughA,Cum(1),1);<BR>LastTrough=ValueWhen(TroughA,L,1);<BR>Plot(C,"",1,64);<BR>Plot(IIf(Cum(1)&gt;=LastPt,LastPeak,-1e10),"",4,1);<BR>Plot(IIf(Cum(1)&gt;=LastTt,LastTrough,-1e10),"",5,1);<BR>Plot(IIf(Cum(1)&gt;=Max(LastPt,LastTt),LastValue(C),-1e10),"",7,1);<BR><BR>I 
do not think I have something more to add.<BR>DT<BR>--- In amibroker@xxxx, 
"dtsokakis" &lt;TSOKAKIS@xxxx&gt; wrote:<BR>&gt; Franco,<BR>&gt; If the 
previous code was confusing you, try this one.<BR>&gt; In AA select a stock 
and EXPLORE for all quotations.<BR>&gt; Then double click on the results 
list.<BR>&gt; You read the values of the last Peak [Last trough] above [below] 
<BR>last <BR>&gt; close value [I forced the useless reading to zero] and the 
arrows <BR>&gt; mark the respective points.<BR>&gt; If you need anything else, 
please advise.<BR>&gt; DT<BR>&gt; <BR>&gt; perc=5;//Calibrate 
sensitivity<BR>&gt; //Last Peak detection<BR>&gt; 
p1=PeakBars(H,perc,1)==0;<BR>&gt; 
H1=ValueWhen(p1,H,1);p2=H1&gt;LastValue(C);<BR>&gt; p=p1 AND 
p2;x1=Cum(p);x1max=LastValue(x1);<BR>&gt; //Last Trough Detection<BR>&gt; 
t1=TroughBars(L,perc,1)==0;<BR>&gt; 
L1=ValueWhen(t1,L,1);t2=L1&lt;LastValue(C);<BR>&gt; t=t1 AND 
t2;y1=Cum(t);y1max=LastValue(y1);<BR>&gt; PeakA=p AND x1==x1max;<BR>&gt; 
TroughA=t AND y1==y1max;<BR>&gt; Filter= PeakA OR TroughA;<BR>&gt; 
AddColumn(IIf(PeakA,H,0),"Last Peak",1.2);<BR>&gt; 
AddColumn(IIf(TroughA,L,0),"Last Trough",1.2);<BR>&gt; Sell=p AND 
x1==x1max;<BR>&gt; Buy=t AND y1==y1max;<BR>&gt; <BR>&gt; --- In 
amibroker@xxxx, "dtsokakis" &lt;TSOKAKIS@xxxx&gt; wrote:<BR>&gt; &gt; Franco, 
<BR>&gt; &gt; please, read again <BR>&gt; &gt; <A 
href="http://groups.yahoo.com/group/amibroker/message/14929";>http://groups.yahoo.com/group/amibroker/message/14929</A><BR>&gt; 
&gt; It is an exploration. It works in Automatic Analysis.<BR>&gt; &gt; Select 
a stock, Explore for All quotations and then doubleclick <BR>on <BR>&gt; &gt; 
the results list.<BR>&gt; &gt; You will see the arrows marking the pointsyou 
ask.<BR>&gt; &gt; It is NOT an ind. builder formula, there is nothing to be 
plotted.<BR>&gt; &gt; The arrows are at the last peak [last trough] which 
satisfies the <BR>&gt; &gt; above LastValue(close) requirement [respectively 
below LastValue<BR>&gt; &gt; (close)]. If a peak [trough] does not fulfilthis 
criterion is <BR>&gt; &gt; skipped [we may change this priority, if you 
like.]<BR>&gt; &gt; DT<BR>&gt; &gt; <BR>&gt; &gt; --- In amibroker@xxxx, 
franco fornari &lt;ffpsi@xxxx&gt; wrote:<BR>&gt; &gt; &gt; Dimitris,<BR>&gt; 
&gt; &gt; <BR>&gt; &gt; &gt; I'm manifestly not able to make me clear. 
Probably it<BR>&gt; &gt; &gt; depends on my poor english.<BR>&gt; &gt; &gt; 
Since I received more than one messages, out of<BR>&gt; &gt; &gt; 
chronological order (because Yahoo mail), I'll try to<BR>&gt; &gt; &gt; 
summarize my (maybe wrong) point of view.<BR>&gt; &gt; &gt; <BR>&gt; &gt;&gt; 
1. Look, please, at the first two attached gif. They<BR>&gt; &gt; &gt; plot my 
and your formulas, respectively. Do you see<BR>&gt; &gt; &gt; any difference? 
I can't. Moreover, I suppose for the<BR>&gt; &gt; &gt; two lines of 
code:<BR>&gt; &gt; &gt; <BR>&gt; &gt; &gt; AddColumn(H,"Last 
Peak",1.2);<BR>&gt; &gt; &gt; AddColumn(L,"Last Trough",1.2);<BR>&gt; &gt; 
&gt; <BR>&gt; &gt; &gt; you really meant as follows:<BR>&gt; &gt; &gt; 
<BR>&gt; &gt; &gt; AddColumn(H1,"Last Peak",1.2);<BR>&gt; &gt; &gt; 
AddColumn(L1,"Last Trough",1.2);<BR>&gt; &gt; &gt; <BR>&gt; &gt; &gt; 2. Look, 
now, at the third attached gif. I have<BR>&gt; &gt; &gt; manually added a 
yellow line, wich shows what level I<BR>&gt; &gt; &gt; wish to detect: the 
last trough higher than last<BR>&gt; &gt; &gt; closing price. Not the last 
trough by absolute. In<BR>&gt; &gt; &gt; this case it is the second last,but 
sometimes it<BR>&gt; &gt; &gt; could be the third from last or more.<BR>&gt; 
&gt; &gt; <BR>&gt; &gt; &gt; 3. Running your exploration system, I don't find 
the<BR>&gt; &gt; &gt; value I need on the last line of results, but on 
the<BR>&gt; &gt; &gt; second last one. Then, it is not available for 
further<BR>&gt; &gt; &gt; applications.<BR>&gt; &gt; &gt; <BR>&gt; &gt; &gt; 
4. You said "Single points localization is not the<BR>&gt; &gt; &gt; easiest 
AFL sport". Well, I think AmiBroker is very<BR>&gt; &gt; &gt; powerful, but I 
don't expect it is omnipotent. If you,<BR>&gt; &gt; &gt; or any other person 
so expert as you are, says a<BR>&gt; &gt; &gt; certain thing is not possible, 
<BR>&gt; &gt; <BR>&gt; &gt; As far as I read my text, I did not say anything 
impossible.<BR>&gt; &gt; [how should I write such a thing !!]<BR>&gt; &gt; 
Although this discussion is a bit confused, we could simplify <BR>&gt; 
things.<BR>&gt; &gt;&nbsp; <BR>&gt; &gt; I can accept this.<BR>&gt; &gt; &gt; 
Maybe Tomasz will turn it possible in future, or maybe<BR>&gt; &gt; &gt; not. 
Anyway, the life will go on.<BR>&gt; &gt; &gt; <BR>&gt; &gt; &gt; Best regards 
and thanks again for the time you spend<BR>&gt; &gt; &gt; to help me.<BR>&gt; 
&gt; &gt; <BR>&gt; &gt; &gt; Franco<BR>&gt; &gt; &gt; <BR>&gt; &gt; &gt; 
<BR>&gt; &gt; <BR>&gt; 
<BR>______________________________________________________________________<BR>&gt; 
&gt; &gt; Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA<BR>&gt; &gt; 
&gt; <A 
href="http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/";>http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/</A><BR>&gt; 
&gt; &gt; <BR>&gt; &gt; &gt; <BR>&gt; &gt; <BR>&gt; 
<BR>______________________________________________________________________<BR>&gt; 
&gt; &gt; Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA<BR>&gt; &gt; 
&gt; <A 
href="http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/";>http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/</A><BR>&gt; 
&gt; &gt; <BR>&gt; &gt; &gt; <BR>&gt; &gt; <BR>&gt; 
<BR>______________________________________________________________________<BR>&gt; 
&gt; &gt; Vinci i Mondiali - La Grande Sfida dei Mondiali FIFA<BR>&gt; &gt; 
&gt; <A 
href="http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/";>http://it.yahoo.com/mail_it/foot/?http://lasfida.yahoo.net/</A><BR><BR></TT><BR><TT>Your 
use of Yahoo! Groups is subject to the <A 
href="http://docs.yahoo.com/info/terms/";>Yahoo! Terms of Service</A>.</TT> 
<BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_001_004B_01C1E8AA.9D13F620--

Attachment:
gif00302.gif

Attachment: Description: "Description: GIF image"