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

[amibroker] Re: Convexity, Concavity and their use


  • To: amibroker@xxxxxxxxxxxxxxx
  • Subject: [amibroker] Re: Convexity, Concavity and their use
  • From: "DIMITRIS TSOKAKIS" <TSOKAKIS@xxxxxxxxx>
  • Date: Sat, 27 Sep 2003 13:02:45 -0700
  • In-reply-to: <bl44tj+6acd@xxxxxxxxxxx>

PureBytes Links

Trading Reference Links

Keith,
I see no problem in my N100 database.
The graphic part shows ^NDX and the related signals, for any selected 
ticker.
In AA I see the same trade dates for all stocks as defined by the 
^NDX signals.
There is one important detail : My database is absolutely aligned: 
The lastvalue(cum(1)) for all stocks is the same.
If you try to apply foreign("^NDX","C") signals for a stock with less 
data, it will be OK.
But, you can not apply to a stock with more data, there will be a 
confusion in the Function IIR2 and the especially the script part
for( i = 2; i < BarCount; i++ ).
I do not know how to overcome this difficulty.
I used for both AA and IB the

function IIR2( input, f0, f1, f2 )
{
  result[ 0 ] = input[ 0 ];result[ 1 ] = input[ 1 ]; 
  for( i = 2; i < BarCount; i++ )
  {
    result[ i ] = f0 * input[ i ] + f1 * result[ i - 1 ] + f2 * result
[ i - 2 ]; 
  }
  return result;
}
SetForeign("^NDX");C1=C;
k=Optimize("k",0.45,0,0.5,0.01);
RD=IIR2( C1, 0.3, 1.2+K, -0.5-K);
y=RD;
t=1;
Convex=(y-Ref(y,-t))/t>=(y-Ref(y,-(t+1)))/(t+1);
Concave=NOT(Convex);
Ascending=y>=Ref(y,-1);
Descending=NOT(ascending);
Bullstart=Convex AND Ascending;
Bullend=Concave AND ascending;
Bearstart=Concave AND Descending;
Bearend=Convex AND Descending;
Color=IIf(Bullstart,colorDarkGreen,IIf(Bullend,colorTurquoise,IIf
(Bearstart,colorDarkRed,colorPink)));
Plot(y,"y",Color,8);
Plot(C,"C",1,64);GraphXSpace=5;
Sell=bearstart AND Ref(bullend,-1);Buy=bullstart AND Ref(bearend,-1);
PlotShapes(shapeDownArrow*Sell,colorRed);
PlotShapes(shapeUpArrow*Buy,colorBrightGreen);

Dimitris Tsokakis
PS The AA code is not a trading recommendation, it is an example to 
see the operation and how it works.

--- In amibroker@xxxxxxxxxxxxxxx, "Keith Bennett" <kbennett@xxxx> 
wrote:
> Dimitris;
> 
> Is it possible to use the peaks and troughs on an index (eg NDX) as 
> Buy/Sell timing signals for the stocks in a watchlist?
> 
> I tried to change C1 = C into C1 = Foreign("NDX","C"); but that 
> produced no output.
> 
> TIA
> Keith
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Andrew" <a.perrin@xxxx> wrote:
> > To measure how "deep" the concave/convex is you could insert 
these 
> 2 
> > lines of code into DT's afl.  The greater the upward concave the 
> > higher the value of positive value of "change", The greater the 
> > downward concave the more negative the value of "change".
> > 
> > Change =((y-Ref(y,-t))/t) - ((y-Ref(y,-(t+1)))/(t+1))  ;
> > Plot(Change,"Change",colorYellow,32770);
> > 
> > Andrew
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "sidleysh" <steves@xxxx> wrote:
> > > OK - I will try and be more articulate.
> > > 
> > > The code you generously developed identified concave and convex 
> > > shapes in the chart, after some initial smoothing. This 
indicates 
> > > areas where the chart was accelarating or decelerating in 
either 
> > > an 'up' direction or a'down' direction. You identified these as 
> > > bullstart, bearstart, etc.
> > > 
> > > I optmizied on both your K paraneter (for smoothing) and T 
> > parameter 
> > > (for lookback period) and was able to get nice resutls for 
> > indivdual 
> > > stocks, but could not find a robust set of paramters for a 
basket 
> > (in 
> > > this case the NDX100).
> > > 
> > > This led to a suggestion for 2 possible improvements to the 
code:
> > > 
> > > 1) A way to identify only 'deep' concaves and convexes - which 
> > would 
> > > signal fast acceleration/deceleration, which, presumably would 
> > signal 
> > > the start of a short trend. For 'shallow' concaves and 
convexes, 
> > the 
> > > strategy would be to hold position.
> > > 2) A more adaptive smoothing algorithm
> > > 
> > > 
> > > Cheers,
> > > 
> > > Steve
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> > <TSOKAKIS@xxxx> 
> > > wrote:
> > > > If you have the time, it would be better to give more 
specific 
> > > > descriptions/codes. This would help the [more than 1000] 
> readers 
> > to 
> > > > understand better your text ["optimize", "delta" etc]
> > > > This would also help the progress of this [hopefully 
> > interesting] 
> > > > thread.
> > > > Dimitris Tsokakis
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "sidleysh" <steves@xxxx> 
> wrote:
> > > > > DT - thanks, good stuff. Obviously the smoothing algorithm 
> > causes 
> > > a 
> > > > > lag in signal, so I am finding good results when I 
optimize, 
> > but 
> > > I 
> > > > > fear I am curve fitting.  (I cannot find a set of 
coefficents 
> > for 
> > > K 
> > > > > and T that work reasonably over the whole market). 
> > > > > 
> > > > > This could be vastly improved by only trading on 'serious' 
> > > > covexities 
> > > > > and concavities, and staying out for the shallow ones. The 
> > > serious 
> > > > > ones could be defined as when today delta is greater than 
2* 
> > > > > yesterday's delta, which is greater than 2* the previous 
> day's 
> > > > delta 
> > > > > (or some such). You then stay in the trade (long) until it 
> > starts 
> > > > to 
> > > > > descend. 
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Dimitris Tsokakis" 
> > > > <TSOKAKIS@xxxx> 
> > > > > wrote:
> > > > > > An ideal sinusoidal has 4 phases:
> > > > > > 
> > > > > > Convex AND Ascending;// colorDarkGreen
> > > > > > Concave AND Ascending;// colorTurquoise
> > > > > > Concave AND Descending;// colorDarkRed
> > > > > > Convex AND Descending;// colorPink
> > > > > > The IB code illustrates the example 
> > > > > > 
> > > > > > // The 4 phases of an ideal sinusoidal
> > > > > > freq = 1;
> > > > > > y=sin( Cum( freq/10 ) );
> > > > > > t=1;
> > > > > > Convex=(y-Ref(y,-t))/t>=(y-Ref(y,-(t+1)))/(t+1);
> > > > > > Concave=NOT(Convex);
> > > > > > Ascending=y>=Ref(y,-1);
> > > > > > Descending=NOT(ascending);
> > > > > > Bullstart=Convex AND Ascending;
> > > > > > Bullend=Concave AND ascending;
> > > > > > Bearstart=Concave AND Descending;
> > > > > > Bearend=Convex AND Descending;
> > > > > > Color=IIf(Bullstart,colorDarkGreen,IIf
> > > (Bullend,colorTurquoise,IIf
> > > > > (Bearstart,colorDarkRed,colorPink)));
> > > > > > Plot(y,"",Color,8);
> > > > > > 
> > > > > > [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 IIR2( input, f0, f1, f2 )
> > > > > > {
> > > > > > result[ 0 ] = input[ 0 ];result[ 1 ] = input[ 1 ]; 
> > > > > > for( i = 2; i < BarCount; i++ )
> > > > > > {
> > > > > > result[ i ] = f0 * input[ i ] + f1 * result[ i - 1 ] + f2 
* 
> > > result
> > > > [ 
> > > > > i - 2 ]; 
> > > > > > }
> > > > > > return result;
> > > > > > }
> > > > > > C1=C;
> > > > > > k=0.3;
> > > > > > RD=IIR2( C1, 0.3, 1.2+K, -0.5-K);
> > > > > > // B. Convexity definition
> > > > > > y=RD;
> > > > > > t=1;
> > > > > > Convex=(y-Ref(y,-t))/t>=(y-Ref(y,-(t+1)))/(t+1);
> > > > > > Concave=NOT(Convex);
> > > > > > Ascending=y>=Ref(y,-1);
> > > > > > 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(Bullstart,colorDarkGreen,IIf
> > > (Bullend,colorTurquoise,IIf
> > > > > (Bearstart,colorDarkRed,colorPink)));
> > > > > > Plot(y,"",Color,8+styleThick);
> > > > > > Plot(C,"",47,64);GraphXSpace=5;


------------------------ 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 

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