Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Thanks for your kind words and thoughts.
I like the look of your code and the indicator. Have you tried experimenting with any of the other moving average types, for example:
{Zero Lag Moving Average}
{cannot remember who to credit with this one?}
prd:= Input("MA Periods",1,250,10);
x:=Input("1-O, 2-H, 3-L, 4-C",1,4,4);
x:=If(x=1,O,If(x=2,H,If(x=3,L,C)));
EMA1:=Mov(x,prd,E);
EMA2:=Mov(EMA1,prd,E);
Difference:= EMA1 - EMA2;
ZeroLagEMA:= EMA1 + Difference;
ZeroLagEMA
{Kaufman Adaptive Moving Average}
Periods := Input("Time Periods",1,1000, 10);
Direction := CLOSE - Ref(Close,-periods);
Volatility := Sum(Abs(ROC(CLOSE,1,$)),periods);
ER := Abs(Direction/Volatility);
FastSC := 2/(2 + 1);
SlowSC := 2/(30 + 1);
SSC := ER * (FastSC - SlowSC) + SlowSC;
Constant := Pwr(SSC,2);
AMA := If(Cum(1) = periods +1, ref(Close,-1) + constant * (CLOSE - ref(Close,-1)),Prev + constant * (CLOSE - PREV));
AMA
{Mod. Kaufman's Adaptive Moving Average}
{modified by wabbit}
prd:=Input("Time Periods",1,1000,31);
K:=Power(ROC(CLOSE,prd,$)/Sum(Abs(ROC(CLOSE,1,$)),prd),2);
If(Cum(1)<=prd+1,C,PREV*(1-K)+C*K);
{PS Adaptive Moving Average}
If(Cum(1)=5,
Ref(C,-1)+(Pwr((Abs((C-Ref(C,-4))/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-Ref(C,-1)),
PREV+(Pwr((Abs((C-Ref(C,-4))/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-PREV))
You might also find you can increase the code's flexibility and edit-ability (if there is such a word?) if you use the Input() function for your variables. when you set the default value, this is the value that any othe indicator calling this formula will "see" so it is just the same as hard-coding, for example the MA periods; e.g.
fastPrd:=Input("Fast MA Periods",1,100,5);
slowPrd:=Input("Slow MA Periods",1,100,20);
{Error checking}
{see Note}
prd1:=LastValue(Min(fastPrd,slowPrd));
prd2:=LastValue(Max(fastPrd,slowPrd));
{Short term EMA}
STEMA:= Mov(C,prd1,E);
{Long term EMA}
LTEMA:= Mov(C,prd2,E);
{Percentage Price Oscillator}
PPO:= (STEMA-LTEMA)/LTEMA;
{Crossover Signal}
XOS:=Mov(PPO,9,E);
If(PPO>XOS,1,-1);0;
Note: Someone once wrote, "Remove errors induced between the chair and the computer!" I laughed.
Hope this helps.
wabbit :D
P.S. G: If ever you don't understand anything, please ask for an explanation. "There is no such thing as a dumb question." I am only too happy to help.
|