I get Error 13. Endless loop detected in WHILE loop on line 76
On Thu, May 5, 2016 at 1:33 AM, 'Edward Pottasch' empottasch@skynet.be [amibroker] <amibroker@yahoogroups.com> wrote:
so below the solution for the BBandtop of High where it was all about. Idea was that when using for instance 1 hour bars you can predict the price at which the intrabar high crosses the BBand function without needing intrabar data. For small periods this seems to give better backtest results, code below (this is just test code => blue dots show a close approaximation of the price at which the BBand (white line) is crossed intrabar. Seems like it is working correctly// AFL code E.M.Pottasch
period = Param( "Period", 3, 3, 30, 1 );
width = Param( "Width", 1, 0, 10, 0.1 );
mah = BBandTop( H, period, width );
// adapted/adjusted from H.B.Bandy Quatitative Trading Systems (2007) p. 184-185
AccuracyTarget = TickSize / 4;
LGuessArray = Null;
HGuessArray = Null;
IterationsArray = 0;
// Bollinger Band Top of High Price calculation
function ZeroToFind( i, period, P )
{
aa = 0;
for( j = i - period + 1; j < i; j++ )
{
aa = H[j] + aa;
}
aa = ( aa + P ) / period;
sdp = 0;
for( j = i - period + 1; j < i; j++ )
{
sdp = sdp + ( H[j] - aa ) ^ 2;
}
sdp = sdp + ( P - aa ) ^ 2;
FTZ = P - ( aa + width * sqrt( sdp / period ) );
return FTZ;
}
for( i = period; i < BarCount; i++ )
{
it = 0;
HGuess = H[i] * 100;
HSign = ZeroToFind( i, period, HGuess );
if( HSign > 0 ) HSign = 1;
else HSign = -1;
LGuess = L[i] * 0.01;
LSign = ZeroToFind( i, period, LGuess );
if( LSign > 0 ) LSign = 1;
else LSign = -1;
if( HSign == LSign )
{
HGuess = 0.0;
}
else
{
while( abs( HGuess - LGuess ) > AccuracyTarget )
{
MGuess = ( HGuess + LGuess ) / 2;
MSign = ZeroToFind( i, period, MGuess );
if( MSign > 0 ) MSign = 1;
else MSign = -1;
if( HSign == MSign ) HGuess = MGuess;
if( LSign == MSign ) LGuess = MGuess;
it = it + 1;
HGuessArray[i] = HGuess;
LGuessArray[i] = LGuess;
IterationsArray[i] = it;
}
}
}
GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 0, chartShowDates );
SetBarFillColor( IIf( C > O, colorGreen, IIf( C <= O, colorRed, colorLightGrey ) ) );
Plot( C, "", IIf( C > O, colorDarkGreen, IIf( C <= O, colorDarkRed, colorLightGrey ) ), 64, null, null, 0, 0, 1 );
Plot( mah, "", colorWhite, 1, null, null, 0, 1, 1 );
Plot( HGuessArray, "", colorBlue, styleDots | styleNoRescale | styleNoline, null, null, 0, 1, 4 );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );Sent: Wednesday, May 04, 2016 3:51 PMSubject: Re: [amibroker] cross price calculations
messages don't come through these days, will try again ....cool, thanks for the info.I just adjusted Howard's method for arrays. I tested first on a simple MA function because I know the mathematical solution for this one. Seems to work good and is not even that slow. But one needs it for backtesting only so speed is not really an issue.Now I can just replace the simple MA with a Bollinger band in the function ZeroToFind. Code for simple MA test below. I just made this so might change or correct it later on but looks correct. Orange dots are the mathematical solution, Blue dots the approached solution as per Bandy,regards, Ed// AFL code E.M.Pottasch
period = Param( "Period", 2, 2, 30, 1 );
mah = MA( H, period );
pph = Ref( MA( H, period - 1 ), -1 ); // mathmatical solution
// adapted from H.B.Bandy Quatitative Trading Systems (2007) p. 184-185
AccuracyTarget = TickSize / 4;
LGuessArray = 0;
HGuessArray = 0;
IterationsArray = 0;
function ZeroToFind( i, period, P )
{
aa = 0;
for( j = i - period + 1; j < i; j++ )
{
aa = H[j] + aa;
}
aa = ( aa + P ) / period;
FTZ = P - aa;
return FTZ;
}
for( i = period; i < BarCount; i++ )
{
it = 0;
HGuess = H[i] * 10;
HSign = ZeroToFind( i, period, HGuess );
if( HSign > 0 ) HSign = 1;
else HSign = -1;
LGuess = L[i] * 0.1;
LSign = ZeroToFind( i, period, LGuess );
if( LSign > 0 ) LSign = 1;
else LSign = -1;
if( HSign == LSign )
{
HGuess = 0.0;
}
else
{
while( abs( HGuess - LGuess ) > AccuracyTarget )
{
MGuess = ( HGuess + LGuess ) / 2;
MSign = ZeroToFind( i, period, MGuess );
if( MSign > 0 ) MSign = 1;
else MSign = -1;
if( HSign == MSign ) HGuess = MGuess;
else HGuess = HGuess;
if( LSign == MSign ) LGuess = MGuess;
else LGuess = LGuess;
it = it + 1;
HGuessArray[i] = HGuess;
LGuessArray[i] = LGuess;
IterationsArray[i] = it;
}
}
}
GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 0, chartShowDates );
SetBarFillColor( IIf( C > O, colorGreen, IIf( C <= O, colorRed, colorLightGrey ) ) );
Plot( C, "Last", IIf( C > O, colorDarkGreen, IIf( C <= O, colorDarkRed, colorLightGrey ) ), 64, null, null, 0, 0, 1 );
Plot( mah, "", colorWhite, 1, null, null, 0, 1, 1 );
Plot( pph, "", colorOrange, styleDots | styleNoRescale | styleNoline, null, null, 0, 1, 4 );
Plot( HGuessArray, "", colorBlue, styleDots | styleNoRescale | styleNoline, null, null, 0, 1, 6 );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );Sent: Wednesday, May 04, 2016 2:50 PMSubject: Re: [amibroker] cross price calculations
Howard also has some code and information about signal anticipation in his new book, Quantitative Technical Analysis (from p.261). It basically zeroes in on a value (like the one being discussed). It is very good code, and a very good idea, as it doesn't require insanely complicated maths and code to figure out the anticipated signal. I use it on a Bollinger band system to calculate close prices, and it works wonderfully. (I haven't included code here, as it is Howard's work. I recommend the book!)
CK
--
Karl Bergerson (カール バーガーソン)
〒002-0857
札幌市北区屯田7条11丁目10-10
電話 050-5809-7325 (Skype)
〒002-0857
札幌市北区屯田7条11丁目10-10
電話 050-5809-7325 (Skype)
__._,_.___
Posted by: Karl Bergerson <karl.bergerson@gmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (44) |
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
.
__,_._,___
EmoticonEmoticon