Graham,
I also get the same result for the explore
and the scan but the chart shows the signals at a different date. Below I
show where I first encountered a problem. I made a Zig function that allows for
"dynamic change". The Buy and Short signals are displayed in the chart. However,
if I do a backtest or a scan using this code it doesn't find any signals.
Try to do a scan with the code below. It doesn't give any signals. The chart
however shows where the signals are. ...... can't figure it out .... but I am
sure I am overlooking something. If I change ZZ = ffZig(C,PercentChange);
using the normal Zig function: ZZ = Zig(C,PercentChange); then the problem disappears. So it seems to
be caused by the function but the function ffZig gives a normal output (as far
as I can see).
rgds, Ed
/*
Zig function
enabling use of a "dynamic" percentage change
Edward Pottasch, dec 2004
vv: the variable pp: dynamic percentage change
*/
function ffZig(vv,pp) {
// initialize fzg
array fzg = 0;
// setting
things up if (vv[ 1 ] > vv[ 0 ]) {
// direction
is up dir = 1; // high hvv = vv[
1 ];
//
low lvv = vv[ 0 ]; // indicate sb sb =
0;
//
eb eb = 1; }
else {
// direction
is down dir = -1; // low lvv = vv[
1 ];
//
high hvv = vv[ 0 ]; // indicate sb sb =
0;
// eb
eb = 1; }
// perform loop to fill fzg
array for( i = 2; i < BarCount; i++ ) {
//
direction is up if (dir == 1) {
// update the high if necessary
if (vv[ i ] >= hvv) {
// update high
hvv
= vv[ i ];
// update eb
eb =
i;
}
// check if dropped below threshold
if ( (hvv - vv[ i ]) / hvv *
100 >= pp[ i ]) {
// change direction
dir
= -1;
// fill zig
nbr
= eb - sb + 1;
dlta
= hvv - lvv;
incr
= dlta / (nbr - 1);
for (j = 0; j < nbr; j++) {
fzg[
j + sb ] = lvv + j * incr;
}
// update the start and end bar position
sb =
eb; eb = i;
// set the low
lvv
= vv[ i
];
// special situation at the end of the
array }
else if (i == BarCount - 1) {
// fill zig
eb =
BarCount -
1;
hvv
= vv[ BarCount -
1 ];
nbr
= eb - sb + 1;
dlta
= hvv - lvv;
incr
= dlta / (nbr - 1);
for (j = 0; j < nbr; j++) {
fzg[
j + sb ] = lvv + j * incr;
}
}
// direction
is down } else if (dir == -1) {
// update the low if necessary
if (vv[ i ] <= lvv) {
// update low
lvv
= vv[ i ];
// update eb
eb =
i;
}
// check if price increase above
threshold
if ( (vv[ i ] - lvv) / lvv *
100 >= pp[ i ]) {
// change direction
dir
= 1;
// fill zig
nbr
= eb - sb + 1;
dlta
= hvv - lvv;
incr
= dlta / (nbr - 1);
for (j = 0; j < nbr; j++) {
fzg[
j + sb ] = hvv - j * incr;
}
// update the start and end bar position
sb =
eb; eb = i;
// set the high
hvv
= vv[ i ];
// special situation at the end of the
array }
else if (i == BarCount - 1) {
// fill zig
eb =
BarCount -
1;
lvv
= vv[ BarCount -
1 ];
nbr
= eb - sb + 1;
dlta
= hvv - lvv;
incr
= dlta / (nbr - 1);
for (j = 0; j < nbr; j++) {
fzg[
j + sb ] = hvv - j * incr;
}
}
}
}
return fzg; }
SetBarsRequired(100000,100000); PercentChange = abs(3*ATR(20)/((H+L)/2)*100); ZZ = ffZig(C,PercentChange) ;
PivotLow = ZZ <
Ref(ZZ,-1) AND ZZ < Ref(ZZ,1); PivotHigh = ZZ > Ref(ZZ,-1) AND ZZ > Ref(ZZ,1); PlotShapes( shapeSmallCircle*PivotLow, colorBrightGreen,0, L, -20) ; PlotShapes( shapeSmallCircle*PivotHigh,colorRed,0,H,
20) ;
Buy = (C - ValueWhen(PivotLow, C, 1)) / ValueWhen(PivotLow, C, 1) * 100 > PercentChange AND ROC(ZZ,1) > 0; Short = (ValueWhen(PivotHigh, C, 1) -
C) / ValueWhen(PivotLow, C, 1) * 100 > PercentChange AND ROC(ZZ,1) < 0;
Buy = ExRem(Buy,Short); Buy = Ref(Buy,-1); Short = ExRem(Short,Buy); Short = Ref(Short,-1);
BuyPrice = C; ShortPrice = C; Sell = Short; SellPrice = C; Cover = Buy; CoverPrice = C;
PlotShapes( shapeUpArrow*Buy, colorWhite,0, BuyPrice, 0); PlotShapes( shapeDownArrow*Short, colorYellow,0,ShortPrice, 0) ;
BuyArea =
IIf(BarsSince(Buy) < BarsSince(Short) AND BarsSince(Buy)!=0, 1, 0); ShortArea = IIf(BarsSince(Short) < BarsSince(Buy)
AND BarsSince(Short)!=0, 1, 0);
BarColors = IIf(BarsSince(Buy) < BarsSince(Short) AND BarsSince(Buy)!=0, colorBrightGreen, IIf(BarsSince(Short) < BarsSince(Buy) AND BarsSince(Short)!=0, colorRed, colorBlue));
Plot(C, "
", BarColors, styleCandle ) ; Plot(ZZ,"
", BarColors,styleDots|styleNoLine); Plot(ZZ,"
", colorLightGrey,styleLine|styleThick);
Filter = 1; AddColumn(Buy,"Buy");
WriteVal(Buy);
----- Original Message -----
Sent: Monday, December 27, 2004 12:03
PM
Subject: RE: [amibroker] what am I doing
wrong??
I always feel it best to start
with i=1
You specify inputs of vv and pp
for the function, but you have not sued them within the
calculation
I checked against a range of
stocks and got the same results for explore and scan
function ffZig(vv,pp) {
// initialize fzg
array
fzg =
0;
// perform loop to
fill fzg array
for( i =
0; i <
BarCount; i= i +
10 ) {
fzg[ i ] = 1;
}
return fzg;
}
SetBarsRequired(10000,10000);
ZZ =
ffZig(C,0) ;
Buy = ZZ ==
1;
Short =
0;
PlotShapes(
shapeUpArrow*Buy,
colorGreen);
Plot(C,
"
",
colorBlue,
styleCandle ) ;
Filter =
1;
AddColumn(Buy,"Buy");
-----Original
Message----- From: ed nl
[mailto:ed2000nl@xxxxxxx] Sent: Monday, December 27, 2004 5:30
PM To:
amibroker@xxxxxxxxxxxxxxx Subject: [amibroker] what am I doing
wrong??
can't figure out what I am doing
wrong. Below a simple example. I create an array using a function. This array
I use to find Buy signals. I put the buy signals in a chart. All seems good.
Then I do an explore and then I see that the explore puts the buy signals at a
different date. There seems nothing strange about the code. What could be
wrong?
function ffZig(vv,pp) {
//
initialize fzg array fzg =
0;
// perform
loop to fill fzg array
for( i = 0; i < BarCount; i= i + 10 ) {
fzg[ i ] = 1; }
return fzg; }
SetBarsRequired(10000,10000); ZZ = ffZig(C,0) ;
Buy = ZZ == 1; Short = 0;
PlotShapes( shapeUpArrow*Buy, colorGreen); Plot(C, "
", colorBlue, styleCandle ) ;
Filter = 1; AddColumn(Buy,"Buy");
Check AmiBroker web page at: http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Check AmiBroker web page at: http://www.amibroker.com/
Check
group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Sponsor |
ADVERTISEMENT
| |
|
Yahoo! Groups Links
|