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

[amibroker] The old divergences thread (for DT)



PureBytes Links

Trading Reference Links

hello,

as usual my question is maybe a little vague .... I wrote a some code 
(see below). My question is how I could write similar code using AFL 
more efficient (since this code is pretty slow ....). For instance 
could I use the correlation function for this?

regards, Ed

//////////////////////////////////////////////////////////////////////
///////////////////
// 
//
// This program correlates price data marked by "markers" in the 
price chart 
// with price data inside a given list of symbols. 
// 
// The purpose could be to correlate discontineous price behaviour 
(gap down after bad news)
// in order to find out how other stocks reacted after such a similar 
event
//
// 1) Put this code in the Automatic Analysis window.
// 2) Select a symbol (type in manually; replace or use "CAT" in the 
code).
// 3) Select a piece of the chart you want to fit with the markers.
// 4) Explore a certain list of symbols ("use filter") for "all 
quotations".
// 5) Sort the sum by clicking on "sum" in the AA window (smallest 
sum is best fit).
//
// Example: if you use as a symbol "CAT", the list is the Dow30 and 
you mark the
// last 30 (or so) days of CAT you will find the best fit will be CAT 
itself on the
// last bar.
//
// ed2000nl, Jan 2004
//
//
//////////////////////////////////////////////////////////////////////
///////////////////


// select a symbol
symb = "CAT";

// select the variables of the stock you want to correlate
xo=Foreign(symb,"Open");
xh=Foreign(symb,"High");
xl=Foreign(symb,"Low");
xc=Foreign(symb,"Close");
xv=Foreign(symb,"Volume");

// define help arrays in which to store the data you want to fit
xoh = xo; xoh = 0;
xhh = xh; xhh = 0;
xlh = xl; xlh = 0;
xch = xc; xch = 0;
xvh = xv; xvh = 0;

// extract the period from the graph selected by using the markers
period = EndValue( BarIndex() ) - BeginValue( BarIndex() );

// store the piece of array you selected by using the markers in the 
Graph
cnt = 0;

for( i = BeginValue( BarIndex() ); i < BeginValue( BarIndex() ) + 
period; i++ ) {

	xoh[cnt] = xo[i];
	xhh[cnt] = xh[i];
	xlh[cnt] = xl[i];
	xch[cnt] = xc[i];
	xvh[cnt] = xv[i];
	cnt = cnt + 1;			
		
}

// define a storage array to store the fit
st = C; st = 0;

// fill the first period bars with a high value to remove the zeros
for( i = 0; i < period; i++) {

	st[i] = 1000;

}

// correlate this selected piece of data with all data in the list
for( i = period; i < BarCount; i++) {

	// calculate scale factor
	scl = xch[0] / C[i-period];

	hsum = 0;
	for( j = 0; j < period; j++) {
			
		// the fit procedure
		hsum = hsum +
			((xoh[j] - O[i-period+j]*scl)/xoh[j])^2 +
			((xhh[j] - H[i-period+j]*scl)/xhh[j])^2 +
			((xlh[j] - L[i-period+j]*scl)/xlh[j])^2 +
			((xch[j] - C[i-period+j]*scl)/xch[j])^2;

	}
	
	st[i] = hsum;

}

Filter=1;
AddColumn(st,"sum");
AddColumn(period,"period fitted");






--- In amibroker@xxxxxxxxxxxxxxx, "ed2000nl" <pablito@xxxx> wrote:
> hello,
> 
> 
> I am trying to understand how the correlation function works. The 
> example from the manual is:
> 
> correlation( close, ref( close, -5 ), 5 ); 
> 
> In this example I assume that at every bar of the close price a 
> comparison is made with the close price 5 bars back. The length of 
> this comparison (periods) is 5 bars. Now how is the correlation 
> exactly calculated. I see the values range between 1 and -1. Does 
it 
> scale at the first bar and then subtract? Is 1 a good correlation 
or 
> is 0 a good correlation?
> 
> If I see for instance an interesting pattern of 20 bars and I want 
to 
> find this pattern elsewhere in a list of symbols could I use the 
> correlation function for this?
> 
> If I want to fit a pattern of 20 bars where the fits would look 
> something like 
> fit = SUM( (high - high_pattern)^2 + (low - low_pattern)^2 + 
(close - 
> close_pattern) + (open - open_pattern)^2 )
> 
> could I use the correlation function for this?
> 
> thanks for any help,
> 
> rgds, Ed


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/