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

[amibroker] Convexity, Concavity and their use



PureBytes Links

Trading Reference Links




An ideal sinusoidal has 4 phases:
 
Convex AND Ascending;// <FONT 
face=Verdana size=2><FONT 
face="Times New Roman">colorDarkGreen
Concave AND Ascending;// <FONT 
face=Verdana size=2><FONT 
face="Times New Roman">colorTurquoise
Concave AND Descending;// <FONT 
face=Verdana size=2><FONT 
face="Times New Roman">colorDarkRed
Convex AND Descending;// <FONT 
size=2>colorPink
The IB code illustrates the example 

 
// The 4 phases of an ideal 
sinusoidal<FONT 
face=Verdana size=2>
freq = 1<FONT 
face="Times New Roman">;
y=sin( <FONT 
size=2>Cum( freq/10<FONT 
face=Verdana size=2> ) );<FONT 
face="Times New Roman">
t=1<FONT 
face="Times New Roman">;
Convex=(y-Ref<FONT 
size=2>(y,-t))/t>=(y-Ref<FONT 
size=2>(y,-(t+1)))/(t+<FONT 
size=2>1<FONT 
face="Times New Roman">);
Concave=NOT(Convex);<FONT 
face="Times New Roman">
Ascending=y>=Ref<FONT 
size=2>(y,-1<FONT 
face="Times New Roman">);
Descending=NOT(ascending);
Bullstart=Convex AND Ascending;
Bullend=Concave AND ascending;
Bearstart=Concave AND Descending;
Bearend=Convex AND 
Descending;
Color=IIf<FONT 
size=2>(Bullstart,colorDarkGreen,IIf<FONT 
size=2>(Bullend,colorTurquoise,IIf<FONT face=Verdana 
size=2><FONT 
face="Times New Roman">(Bearstart,colorDarkRed,colorPink)));<FONT 
face=Verdana size=2>
Plot(y,""<FONT 
size=2>,Color,8<FONT 
face="Times New Roman">);
 
[see sin.gif]
We shall use a smoothing procedure 
[IIR2 filter] as close to the sinusoidal as possible. [see 
IIR2.gif]
Of course the trend characteristics do 
not give the [-1, +1] oscillation, but the convexity/concavity are still 
detectable.
The superimpose of actual price candles 
gives a more descriptive picture of the 4 phases.
[see 4phases.gif]
The full code is
 
// The 4 
phases of a stock graph
// A. 
Smothing procedure
function<FONT 
face="Times New Roman"> IIR2( input, f0, f1, f2 )
{
result[ 0 ] = input[ <FONT 
size=2>0 ];result[ 1 
] = input[ 1<FONT 
face="Times New Roman"> ]; 
for( i 
= 2<FONT 
face="Times New Roman">; i < BarCount; i++ )
{
result[ i ] = f0 * input[ i ] + f1 * result[ i - <FONT 
size=2>1 ] + f2 * result[ i - <FONT 
size=2>2 ]; 

}
return<FONT 
face=Verdana size=2> result;
}
C1=C;<FONT 
face="Times New Roman">
k=0.3<FONT 
face="Times New Roman">;
RD=IIR2( C1, 0.3, <FONT 
size=2>1.2+K, -0.5<FONT 
face=Verdana size=2>-K);
// B. Convexity 
definition
y=RD;<FONT face=Verdana 
size=2>
t=1<FONT 
face="Times New Roman">;
Convex=(y-Ref<FONT 
face="Times New Roman">(y,-t))/t>=(y-<FONT 
size=2>Ref<FONT 
size=2>(y,-(t+1)))/(t+<FONT 
size=2>1<FONT 
face="Times New Roman">);
Concave=NOT(Convex);<FONT 
face="Times New Roman">
Ascending=y>=Ref<FONT 
face="Times New Roman">(y,-1<FONT 
face=Verdana size=2>);
Descending=NOT(ascending);
// C. Trend 
phases
Bullstart=Convex AND Ascending;// from A to 
B
Bullend=Concave AND ascending;// from B to 
C
Bearstart=Concave AND Descending;// from C to 
D
Bearend=Convex AND Descending;// from D to 
E
// D. Application
Color=IIf<FONT 
face="Times New Roman">(Bullstart,colorDarkGreen,<FONT 
size=2>IIf<FONT 
size=2>(Bullend,colorTurquoise,IIf<FONT 
face=Verdana size=2><FONT 
face="Times New Roman">(Bearstart,colorDarkRed,colorPink)));<FONT 
face=Verdana size=2>
Plot(y,""<FONT 
size=2>,Color,8<FONT 
face="Times New Roman">+styleThick);<FONT face=Verdana 
size=2>
Plot(C,""<FONT 
size=2>,47,<FONT 
size=2>64);GraphXSpace=5<FONT 
face=Verdana size=2>;
 






Yahoo! Groups Sponsor


  ADVERTISEMENT 









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



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



Attachment:
4phases.gif

Attachment: Description: "Description: GIF image"