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

RE: [amibroker] Loop



PureBytes Links

Trading Reference Links

Terry,
Thanks for trying.
Ricardo published it to this forum couple of months ago:
 
----------------------------------------------------------------------------------------------------------
HI , in an Italian forum I have found this formula of Adapative Moving
 average
 used in a Trading System . I have translate the formula in excel .
 Someone could translate in language Amibroker ? Thanks
 The formulas of the Moving average :
 T = Close
 Len = periods
 MM = Moving average
 B = smothing
 n = Day
 n-1 = Day-1
Abs = Absolute value
 B = 5*(ABS(T(n)-MM(n-1)) / MM(n-1) - ABS(MM(n-1)-MM(n-5)) / MM(n- 5))
/ (Len - 5)
 MM(n) = B*(T(n)-MM(n-1)) + MM(n-1)

The value of B must be calculated inner to the formula of the average
mobile same in ricursive way (For in Amibroker language ) because
MM(n) = MM in these day
MM(n-1) = MM 1 days ago
MM(n-5 ) = MM 5 days ago
The formula is this where the value of B is calculated from values of
the Moving Average same .
MM(n) = [ 5*(ABS(T(n)-MM(n-1)) / MM(n-1) - ABS(MM(n-1)-MM(n-5)) /
MM(n-5)) / (Len - 5) ] * (T(n)-MM(n-1)) + MM(n-1)
It would have to be like this formula for the calculation of the
exponential moving average in Amibroker :
myema[ 0 ] = Close[ 0 ];
for( i = 1; i < BarCount; i++ )
{
    myema[ i ] = 0.1 * Close[ i ] + 0.9 * myema[ i - 1 ];
}
Plot(myema,"myema",colorRed);

 excused for my English  Iam Italian .
Thanks Riccardo .
------------------------------------------------------------------------------------------------
 
 
I have it in excell so I wanted it in AFL.
Thanks,
Erkan
 

Terry <MagicTH@xxxxxxxxxxx> wrote:

I have no idea what you are doing, but try this (see notes):

 

n = Param("number of bars", 20,1,1000,1);

 

mt = Param("if 1 then 2n else number",1,100,1); //Test was 2m, code was 2n. I changed text.

m = IIf(mt == 1,2 * n,mt);

//nm = C; //Does nothing outside the function

 

function novama(array,m,n)

{

    //nm = array; //accomplishes nothing effective here. Weird when left out and using array, plot is different

    for( i = n+1; i < BarCount; i++ )

    {

 

        kf = n / (m - n) * (abs(array[i] - array[i-1]) / array[i-1] - abs(array[i-1] - array[i-n]) / array[i-n]);

        nm[i] = kf * (array[i] - array[i-1]) + array[i-1];

    }

    return nm;

}

 

Plot(novama(C,m,n),"novama",3,1);

Plot(C,"c",1,64);

 

 

 

--

Terry

-----Original Message-----
From:
amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of ERKAN BISEVAC
Sent: Sunday, October 02, 2005 11:58
To:
amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Loop

 

Can somebody please take a look at this?

I am doing something wrong but I don't see it.

Thanks,

Erkan

 

 

n=Param("number of bars", 20,1,1000,1);

mt=Param("if 1 then 2m else number",1,100,1);

m=IIf(mt==1,2*n,mt);

nm=C;

function novama(array,m,n)

{

nm=array;

for( i = n+1; i < BarCount; i++ )

{

kf=n/(m-n)*(abs(array[i]-nm[i-1])/array[i-1]-abs(nm[i-1]-nm[i-n])/nm[i-n]);

nm[i]=kf*(array[i]-nm[i-1])+nm[i-1];

}

return nm;

}

Plot(novama(C,m,n),"novama",3,1);

Plot(C,"c",1,64);


Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.


Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.

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