logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
noumann  
#1 Posted : Monday, April 30, 2012 1:40:37 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

Hello everyone, i'm studying a special exponential moving average,described by R.F. Meyer in his "An adaptive Method of Routine Short Term Forecasting".Renato Di Lorenzo,in his recent book,has published the ProRealTime formula,but i can't translate it in Metastock language. Can anyone help me? Here is the ProRealTime code: //Indicatore FiltroDiMeyer datatime=N PeriodoEma = 17 SmoothingEma= 2 / (PeriodoEma + 1) PeriodoStdDeviationEma = 9 PeriodoStdDeviationPrezzo = 9 //condizioni iniziali IF BarIndex=0 THEN Ema = close ELSE //crea EMA di Meyer Ema = Ema[1] * (1 - SmoothingEma) + close * SmoothingEma SigmaEma = STD[PeriodoStdDeviationEma](Ema) SigmaPrezzo = STD[PeriodoStdDeviationPrezzo](close) Alfa = SigmaEma / SigmaPrezzo SmoothingEma=Alfa ENDIF RETURN Ema[datatime] COLOURED(0,0,255) AS "Filtro di Meyer " // Nella finestra 2-Variables si deve aggiungere la variabile N (con valore di default 0).
jjstein  
#2 Posted : Monday, April 30, 2012 6:11:49 AM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Well, this is what I came up with:
Code:

{_FilterDiMeyer}
PeriodEma:=17;
SmoothingEma:=2/(PeriodEma+1);
PeriodStdDev:=9;
PeriodStdDevPrice:=9;

{ Initial Condition }
EMA:=If(Cum(1)=1,CLOSE,
{ DiMeyer EMA }
PREV*(1-SmoothingEma)+CLOSE*SmoothingEma);

{ Calc'd, but not plotted }
SigmaEma:=Stdev(EMA,PeriodStdDev);
SigmaPrice:=Stdev(CLOSE,PeriodStdDevPrice);
Alfa:=SigmaEma/SigmaPrice;
SmoothingEma:=Alfa;

{ Plot }
Ema;



But, it seems to plot IDENTICALLY to a 17 period Exponetial MA:
Code:


mov(C,17,e);


Are you sure you copied the code correctly? What software was it in, originally?

noumann  
#3 Posted : Monday, April 30, 2012 7:17:26 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

Thanks for your reply,jjstein.The code is correct and it works well on prorealtime.The problem seems to be all that you have calculated but not plotted.The classic ema formula is correctly : EMA:=If(Cum(1)=1,CLOSE, PREV*(1-SmoothingEma)+CLOSE*SmoothingEma); but,in order to plot the desired ema,we would substitute SmoothingEma with Alfa.In this way we would obtain an adaptive ema,with adaptive factor equal to the ratio between the signal(Devstand of a classic ema in a certain period) end the noise(Devstand of the closes in the same period). Forgive my poor english,i hope i was clear. Regards
jjstein  
#4 Posted : Monday, April 30, 2012 9:09:00 AM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
noumann wrote:
Thanks for your reply,jjstein.The code is correct and it works well on prorealtime.The problem seems to be all that you have calculated but not plotted.The classic ema formula is correctly : EMA:=If(Cum(1)=1,CLOSE, PREV*(1-SmoothingEma)+CLOSE*SmoothingEma); but,in order to plot the desired ema,we would substitute SmoothingEma with Alfa.In this way we would obtain an adaptive ema,with adaptive factor equal to the ratio between the signal(Devstand of a classic ema in a certain period) end the noise(Devstand of the closes in the same period). Forgive my poor english,i hope i was clear. Regards


If I understand you, then "Alfa" should be used to recalculate. the code should look like this:
Code:

PeriodEma:=17;
SmoothingEma:=2/(PeriodEma+1);
PeriodStdDev:=9;
PeriodStdDevPrice:=9;

{ Initial Condition }
EMA:=If(Cum(1)=1,CLOSE,
{ DiMeyer EMA }
PREV*(1-SmoothingEma)+CLOSE*SmoothingEma);

SigmaEma:=Stdev(EMA,PeriodStdDev);
SigmaPrice:=Stdev(CLOSE,PeriodStdDevPrice);
Alfa:=SigmaEma/SigmaPrice;
SmoothingEma:=Alfa;

If(Cum(1)=1,CLOSE,
{ DiMeyer EMA }
PREV*(1-SmoothingEma)+CLOSE*SmoothingEma);


It might help if you could capture a screen from ProRealTime and put it here. Use PtrSc with Paint, save as PNG, upload to IMGUR and paste here.

By any chance, can you post a link to the original article?

noumann  
#5 Posted : Monday, April 30, 2012 10:26:48 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

Here it is: http://i.imgur.com/6YXJP.png?1 I also have a worksheet made by tha author to explain how to calculate the indicator. Let me know how i can send you, Thanks
noumann  
#6 Posted : Monday, April 30, 2012 10:34:19 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

and here is the worksheet: http://min.us/mCnHJyNq4
jjstein  
#7 Posted : Monday, April 30, 2012 12:39:01 PM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Well, the plot from IMGUR is much smoother than mine, here:
UserPostedImage

But I don't know why. Maybe someone else can chime in.

wabbit  
#8 Posted : Monday, April 30, 2012 8:26:43 PM(UTC)
wabbit

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)
Code:

maPrd:=17;
sdPrd:=9;

data:=close;

ma:=extfml("forum.mov",data,maPrd,e);

StDevOfMA:=extfml("forum.stdev",ma,sdPrd,1);
StDevOfData:=extfml("forum.stdev",data,sdPrd,1);

ratio:=stdevOfMA/max(stdevOfData,0.00001);

meyer:=if(cum(isdefined(data+ratio))=1,data,prev*(1-ratio)+(data*ratio));

{plot}
meyer;


Requires the Forum.dll

I'd have to dig into the source code of the forum.dll to see if it allowed fractional inputs to the ema in order to possible remove the PREV in the last line?/?



wabbit [:D]

[edit] There are going to be minor differences in the values for the initial 9 bars or so, as there are different seeds to the ema algos. After then though, the differences will be insignificant.

jjstein  
#9 Posted : Monday, April 30, 2012 8:50:56 PM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Wabbit: That gives identical results on 27 Apr 12 on the $COMP:

3030.56 -- Mine
3030.56 -- Wabbit

3029.4 -- Original at IMGUR.

The "original" also has a much smoother curve.

wabbit  
#10 Posted : Monday, April 30, 2012 9:11:44 PM(UTC)
wabbit

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)
After a very quick play, I came up with another solution (and tested this time! [:)] ) which produces the same results as the spreadsheet...

Code:

maPrd:=17;
sdPrd:=9;

data:=CLOSE;

ma:=ExtFml("forum.mov",data,maPrd,e);

StDevOfMA:=Stdev(ma,sdPrd);
StDevOfData:=Stdev(data,sdPrd);

ratio:=stdevOfMA/Max(stdevOfData,0.00001);
i:=Ref(Cum(IsDefined(data+ratio))=1,+1);

ratio:=ExtFml("forum.sum",ratio,1);
i:=ExtFml("forum.sum",i,1);

limit:=BarsSince(i=1)>=0;

meyer:=If(i,data,PREV*(1-ratio)+(data*ratio));

{plot}
limit*meyer


It uses a few tricks here and there to make things fit in the timescale, and although there is a forward Ref() it is not crystal balling prices.


wabbit [:D]


mstt  
#11 Posted : Tuesday, May 1, 2012 1:19:17 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Wabbit

My version just focuses on removing both PREVs from Johnathan's version by using the MSTT.EMA DLL function. I doubt that the "code" boundaries will work (not if I believe the Preview) but I'll post it anyway and see what happens..

Code:


PeriodEma:=17;
SmoothingEma:=2/(PeriodEma+1);
PeriodStdDev:=9;
PeriodStdDevPrice:=9;

{ Initial Condition }
{ DiMeyer EMA }
EMA:=ExtFml("MSTT.EMA",C,PeriodEma);

SigmaEma:=Stdev(EMA,PeriodStdDev);
SigmaPrice:=Stdev(CLOSE,PeriodStdDevPrice);
Alfa:=SigmaEma/SigmaPrice;
SmoothingEma:=2/Alfa-1;

{ DiMeyer EMA }
ExtFml("MSTT.EMA",C,SmoothingEma);



Roy


wabbit  
#12 Posted : Tuesday, May 1, 2012 1:43:27 AM(UTC)
wabbit

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)
Hi Roy,

You and I know the MSTT.dll will do the trick (we wrote it) but I'm unsure of the distribution of the library.

Unfortunately, the Forum.dll statically casts the periods to their integer values, so it cannot be used to remove the PREV in this instance.



wabbit [:D]

jjstein  
#13 Posted : Tuesday, May 1, 2012 10:38:15 AM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
The figure for 27 Apr 12 on the $COMP is still different:

3029.4 -- Original
3030.56 -- Mine
3030.56 -- Wabbit
3030.56 -- Roy

The "original" has a smoother curve, as well.


ORIGINAL
------------
UserPostedImage

CURRENT -- Johnathan, Wabbit#2 and Roy
----------------------------------------------
UserPostedImage

noumann  
#14 Posted : Tuesday, May 1, 2012 10:45:48 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

thank you all...but i can't understand..may i use the wabbit's code?..and if yes,where can i find the dll?
jjstein  
#15 Posted : Tuesday, May 1, 2012 12:29:22 PM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
noumann wrote:
thank you all...but i can't understand..may i use the wabbit's code?..and if yes,where can i find the dll?


The forum.dll is here.

However, the three versions of the code produce identical results (slight difference in Feb 12 for Roy's version), and none match the original; something is still off...

wabbit  
#16 Posted : Tuesday, May 1, 2012 4:49:33 PM(UTC)
wabbit

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)
jjstein wrote:
the three versions of the code produce identical results (slight difference in Feb 12 for Roy's version), and none match the original; something is still off..
Code:
// FiltroDiMeyer 

datatime=N 

PeriodoEma = 17 
SmoothingEma= 2 / (PeriodoEma + 1) 
PeriodoStdDeviationEma = 9 
PeriodoStdDeviationPrezzo = 9 

//condizioni iniziali 
IF BarIndex=0 THEN 
Ema = close 
ELSE 
//crea EMA di Meyer 
Ema = Ema[1] * (1 - SmoothingEma) + close * SmoothingEma 
SigmaEma = STD[PeriodoStdDeviationEma](Ema) 
SigmaPrezzo = STD[PeriodoStdDeviationPrezzo](close) 
Alfa = SigmaEma / SigmaPrezzo 
SmoothingEma=Alfa 
ENDIF 

RETURN Ema[datatime] COLOURED(0,0,255) AS "Filtro di Meyer " 

// Nella finestra 2-Variables si deve aggiungere la variabile N (con valore di default 0). 
In the OP code, there is the "datetime" variable which is assigned a value "N" and this never changes. There is no mention of an Ema[] function in the online help manual for the software, so I'm going to guess any differences lie in that Ema[] function; we might even discover that if what I suspect is happening, when we call Ema[0] that a default 14 or 21 period ema of close prices is returned? Who has the source code for that function? For those with access to the software, try changing the last line to:
Code:
RETURN Ema[Alfa] COLOURED(0,0,255) AS "Filtro di Meyer " 
and see what difference that makes? wabbit [:D] P.S. I will be home at the end of today and if not too jet lagged, may have another play, but I reckon we have the solution nailed, proving its better to have a description of how functions are supposed to work instead of other peoples interpreted code.
wabbit  
#17 Posted : Wednesday, May 2, 2012 4:55:27 AM(UTC)
wabbit

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)
Well...

the original code doesn't even compile in the application, so what chance have we of making something from it?

Thanks to the OP for wasting our time. [:(]




wabbit [:D]

jjstein  
#18 Posted : Wednesday, May 2, 2012 6:52:14 AM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
wabbit wrote:
the original code doesn't even compile in the application, so what chance have we of making something from it?


Noumann -- Would you please check the original code, and/or post a link to the original? Make sure to use the CODE tags (see below), so nothing gets left out.

Code:

//Indicatore FiltroDiMeyer



datatime=N



PeriodoEma = 17

SmoothingEma= 2 / (PeriodoEma + 1)

PeriodoStdDeviationEma = 9

PeriodoStdDeviationPrezzo = 9



//condizioni iniziali

IF BarIndex=0 THEN

	Ema = close

ELSE

	//crea EMA di Meyer

	Ema = Ema[1] * (1 - SmoothingEma) + close * SmoothingEma

	SigmaEma = STD[PeriodoStdDeviationEma](Ema)

	SigmaPrezzo = STD[PeriodoStdDeviationPrezzo](close)

	Alfa = SigmaEma / SigmaPrezzo

	SmoothingEma=Alfa

ENDIF



RETURN Ema[datatime] COLOURED(0,0,255) AS "Filtro di Meyer "



// Nella finestra 2-Variables si deve aggiungere la variabile N (con valore di default 0).

noumann  
#19 Posted : Wednesday, May 2, 2012 7:30:19 AM(UTC)
noumann

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 10/16/2009(UTC)
Posts: 34

Dear jonathan,i wrote the code correctly.Anyway you can check it here: http://min.us/mbrOIXbLx1 Thank you all
jjstein  
#20 Posted : Wednesday, May 2, 2012 7:58:22 AM(UTC)
jjstein

Rank: Advanced Member

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
noumann wrote:
Anyway you can check it here: http://min.us/mbrOIXbLx1


Well, I tried plugging that in, but it doesn't work, either. Where did you get the original chart, posted to IMGUR?

I wonder if that last line means to return an EMA-smoothed version...

Users browsing this topic
Guest (Hidden)
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.