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

Code question and Adaptive Moving Averages



PureBytes Links

Trading Reference Links

[This message also answers another thread about Adaptive Moving Averages]

Daniel Poiree wrote:
>IF CurrentBar > 1 and XAverage(Close,Length1) crosses above
>XAverage(Close,Length2) Then Buy on Close;
>
>Knowing that there a few known bugs in Omega's code, does anyone know if the
>XAverage function has any flaws?

Yes, it does.  I have seen xAverage screw up if you try to make it
adaptive by feeding it a Length parameter that changes with each
bar.  Actually it does more than screw up.  Doing this has crashed
Tradestation, forcing me to re-boot to recover from locking up
and/or erratic behavior.

What YOU are trying to do should cause no problems.

However, I have grown to distrust the xaverage function so much that
I implemented my own:

{Function EMA - Exponental Moving Average}
Inputs: last_EMA(NumericSimple), newvalue(NumericSimple),
        length(NumericSimple);
Variables: w(0);
w = 2 / (length + 1);
EMA = w*newvalue + (1-w)*last_EMA;

The difference between my EMA function and xAverage is that mine
requires you to maintain a variable to hold the EMA results so that
you can pass the previous result into EMA().  So an adaptive moving
average would be implemented like so:

Variables: adaptEMA(0);
adaptEMA = EMA(adaptEMA[1], Close, HilbertCycle/2);
{where HilbertCycle is a function returning the dominant cycle length}

Try passing HilbertCycle (which I posted to this list a month or two
ago) to xAverage and watch TS lock up.

-Alex