I would like to modify the AMA.efs (kaufman adaptive moving avg.) so that it can be offset or lagged forward by 2 bars and also so it calculates only on the close of the bar instead of every tick. Offsetting this AMA forward provides much shaper and clearer cutoffs with fewer whipsaws. I could do this in a few minutes using TS easy language or Ensign's ESPL but I don't even know where to begin with Java.
Would someone like to take a crack at it? The original code below was written by Mechos (file sharing site).
function preMain()
{
setPriceStudy(true);
}
var dLastAMA = 0.0;
var dThisAMA = 0.0;
var fc;
var sc;
function main(nLength,nFastPeriod,nSlowPeriod)
{
if(nLength == null)
nLength = 9;
if(nFastPeriod == null)
nFastPeriod = 2;
if(nSlowPeriod == null)
nSlowPeriod = 30;
var nBarState = getBarState();
var vClose;
var i;
var volatility = 0.0;
var ratio;
var ssc;
var constant;
if(nBarState == BARSTATE_ALLBARS) {
// reset!
dLastAMA = 0.0;
dThisAMA = 0.0;
fc = 2/(nFastPeriod + 1);
sc = 2/(nSlowPeriod + 1);
}
else if(nBarState == BARSTATE_NEWBAR) {
dLastAMA = dThisAMA;
}
dThisAMA = dLastAMA;
vClose = close(0,-nLength - 1);
if(vClose == null)
return;
for(i = 0;i < nLength;i++){
volatility += Math.abs(vClose[i] - vClose[i+1]);
}
ratio = Math.abs((vClose[0] - vClose[nLength-1]) / volatility);
ssc = ratio * (fc - sc) + sc;
constant = ssc * ssc;
dThisAMA = dLastAMA + (constant * (vClose[0] - dLastAMA));
return(dThisAMA);
}
Would someone like to take a crack at it? The original code below was written by Mechos (file sharing site).
function preMain()
{
setPriceStudy(true);
}
var dLastAMA = 0.0;
var dThisAMA = 0.0;
var fc;
var sc;
function main(nLength,nFastPeriod,nSlowPeriod)
{
if(nLength == null)
nLength = 9;
if(nFastPeriod == null)
nFastPeriod = 2;
if(nSlowPeriod == null)
nSlowPeriod = 30;
var nBarState = getBarState();
var vClose;
var i;
var volatility = 0.0;
var ratio;
var ssc;
var constant;
if(nBarState == BARSTATE_ALLBARS) {
// reset!
dLastAMA = 0.0;
dThisAMA = 0.0;
fc = 2/(nFastPeriod + 1);
sc = 2/(nSlowPeriod + 1);
}
else if(nBarState == BARSTATE_NEWBAR) {
dLastAMA = dThisAMA;
}
dThisAMA = dLastAMA;
vClose = close(0,-nLength - 1);
if(vClose == null)
return;
for(i = 0;i < nLength;i++){
volatility += Math.abs(vClose[i] - vClose[i+1]);
}
ratio = Math.abs((vClose[0] - vClose[nLength-1]) / volatility);
ssc = ratio * (fc - sc) + sc;
constant = ssc * ssc;
dThisAMA = dLastAMA + (constant * (vClose[0] - dLastAMA));
return(dThisAMA);
}
Comment