The problem is you are beginning on bar 2.

When you use something with a period, i.e., ROC(Array,Period), MA(Array,Period), Amibroker returns the EMPTY value until there have been enough periods to get a valid result (this is a good thing, a lot of T/A software starts giving you (bogus) results right away before there are enough periods).

 

So, either do what I have shown below (which is good up to 100 periods) or transmit the period as an argument and start there instead of 2.

 

SetBarsRequired(100000,0);

PI = 3.1415926;

 

function IIR2( input, f0, f1, f2 )

{

    result = 0; //[ 0 ] = input[ 0 ]; //Just blank the entire array

    //result[ 1 ] = input[ 1 ];

 

    for( i = 100; i < BarCount; i++ ) //Don't compute until we have valid (non-Empty) data

    {

       result[ i ] = f0 * input[ i ] +

                     f1 * result[ i - 1 ] +

                     f2 * result[ i - 2 ];

    }

 

   return result;

}

 

function GSMA( input, Period )

{

  N = 0;

  an = 2 * PI / Period;

  c0 = b0 = 1;

  c1 = b1 = b2 = a1 = a2 = gamma1 = 0;

  beta1 = 2.415 * ( 1- cos( an ) );

  alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 );

  alpha1 = ( cos( an ) + sin( an ) - 1 ) / cos( an );

  {

     fo = alpha ^ 2;

     f1 = 2 * ( 1- alpha );

     f2 = -( 1 - alpha ) * ( 1 - alpha );

  }

  return IIR2( input, fo,f1,f2);

}

A = ROC(C,20);

period = Param("period",13,1,40,1);

 

//Plot( Close, "Price", colorBlack, styleCandle );

Plot( GSMA( A,period), "GSMA", colorRed );

 

--

Terry

 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of karthikmarar
Sent:
Sunday, September 03, 2006 03:55
To: [email protected]
Subject: [amibroker] Gaussian Moving average

 

Hi

 

I made the folowing code for Gaussian Moving average. It works fine

for close, high etc. But does not work if I want to use it on any

indicator.

For example when I substitute close with say ROC the output goes to

zero. Can anybody explain where I am going wrong.

 

 

SetBarsRequired(100000,0);

PI = 3.1415926;

 

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;

}

 

function GSMA( input, Period )

{

  N = 0;

  an = 2 * PI / Period;

  c0 = b0 = 1;

  c1 = b1 = b2 = a1 = a2 = gamma1 = 0;

  beta1 = 2.415 * ( 1- cos( an ) );

  alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 );

  alpha1 = ( cos( an ) + sin( an ) - 1 )/cos( an );

   {

    fo = alpha ^ 2;

    f1 = 2 * ( 1- alpha ); f2 = -( 1 - alpha )*( 1 - alpha );

  }

 

 

  return IIR2( input, fo,f1,f2);

}

A=C;

period=Param("period",13,1,40,1);

 

//Plot( Close, "Price", colorBlack, styleCandle );

Plot( GSMA( A,period), "GSMA", colorRed );

 

regards

 

 

 

 

 

 

 

 

 

 

Please note that this group is for discussion between users only.

 

To get support from AmiBroker please send an e-mail directly to

SUPPORT {at} amibroker.com

 

For other support material please check also:

http://www.amibroker.com/support.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:

    [EMAIL PROTECTED]

 

<*> Your use of Yahoo! Groups is subject to:

    http://docs.yahoo.com/info/terms/

 

 

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html






SPONSORED LINKS
Software support Small business finance Business finance online
Business finance training Business finance course


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to