Re: [amibroker] cross price calculations

 

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 PM
Subject: 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

__._,_.___

Posted by: "Edward Pottasch" <empottasch@skynet.be>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (41)
**** 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/


.

__,_._,___


EmoticonEmoticon