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

Notification

Icon
Error

Options
Go to last post Go to first unread
anilcool  
#1 Posted : Saturday, December 1, 2012 11:51:28 PM(UTC)
anilcool

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/16/2011(UTC)
Posts: 12

Original code: {Calculate Wilders Average Directional Index [ADX] } TH:= IF(Ref(Close,-1) > High,Ref(Close,-1), High); TL:= IF(Ref(Close,-1) < Low ,Ref(Close,-1), Low ); TR:= TH-TL; {--------------} PlusDM := IF(High > Ref(High,-1) AND Low >= Ref(Low,-1), High-Ref(High,-1), If(High > Ref(High,-1) AND Low < Ref(Low,-1) AND High - Ref(High,-1) > Ref(Low,-1) - Low, High - Ref(High,-1),0)); PlusDI := 100 * Wilders(PlusDM,ADXPr) / Wilders(Tr,ADXPr); MinusDM:= IF(Low < Ref(Low,-1) AND High <= Ref(High,-1), Ref(Low,-1) - Low, If(High > Ref(High,-1) AND Low < Ref(Low,-1) AND High - Ref(High,-1) < Ref(Low,-1) - Low, Ref(Low,-1) - Low,0)); {--------------} MinusDI := 100 * Wilders(MinusDM,ADXPr) / Wilders(Tr,ADXPr); DIDif := Abs(PlusDI - MinusDI); DISum := PlusDI + MinusDI; ADXFinal := 100 * Wilders(DIDif/DISum,ADXPr); ADXRCustom:= (ADXFinal + Ref(ADXFinal,1-ADXPr)) / 2; _ADX := IF( ADXtype = 0,ADXFinal,ADXRCustom); {Calculate a Variable Moving Average using method devised by Tushar Chande} Barnum := BarCount(); EmaIndex:= IF(VarMAPr > 0 ,(2 / (1+VarMAPr)) ,0.20); Diff := HHV(_ADX, ADXPr) - LLV(_ADX, ADXPr); MyConst := IF(Diff > 0,(_ADX - LLV(_ADX,ADXPr)) / Diff,EmaIndex); MyConst := IF(MyConst > EmaIndex,EmaIndex,MyConst); VarMA := IF(Barnum < ADXPr + (ADXPr * 1.5), Close,MOV((((1 - MyConst) * Ref(VarMA,-1)) + (MyConst * Close)), 2, s)); {Calculte & Plot Multiple MA's of the Variable Moving Average} MA1 :=Mov(VarMA, 2,Initial_MA_Type); MA2 :=Mov(VarMA, 4,Initial_MA_Type); MA3 :=Mov(VarMA, 6,Initial_MA_Type); MA4 :=Mov(VarMA, 8,Initial_MA_Type); MA5 :=Mov(VarMA,10,Initial_MA_Type); MA6 :=Mov(VarMA,12,Initial_MA_Type); MA7 :=Mov(VarMA,14,Initial_MA_Type); MA8 :=Mov(VarMA,16,Initial_MA_Type); MA9 :=Mov(VarMA,18,Initial_MA_Type); MA10:=Mov(VarMA,20,Initial_MA_Type); MA11:=Mov(VarMA,22,Initial_MA_Type); MA12:=Mov(VarMA,24,Initial_MA_Type); MA13:=Mov(VarMA,26,Initial_MA_Type); MA14:=Mov(VarMA,28,Initial_MA_Type); MA15:=Mov(VarMA,30,Initial_MA_Type); MA16:=Mov(VarMA,32,Initial_MA_Type); MA17:=Mov(VarMA,34,Initial_MA_Type); MA18:=Mov(VarMA,36,Initial_MA_Type); MA19:=Mov(VarMA,38,Initial_MA_Type); MA20:=Mov(VarMA,40,Initial_MA_Type); MA21:=Mov(VarMA,42,Initial_MA_Type); MA22:=Mov(VarMA,44,Initial_MA_Type); MA23:=Mov(VarMA,46,Initial_MA_Type); MA24:=Mov(VarMA,48,Initial_MA_Type); MA25:=Mov(VarMA,50,Initial_MA_Type); MA26:=Mov(VarMA,52,Initial_MA_Type); MA27:=Mov(VarMA,54,Initial_MA_Type); MA28:=Mov(VarMA,56,Initial_MA_Type); MA29:=Mov(VarMA,58,Initial_MA_Type); MA30:=Mov(VarMA,60,Initial_MA_Type); MA31:=Mov(VarMA,62,Initial_MA_Type); MA32:=Mov(VarMA,64,Initial_MA_Type); MA33:=Mov(VarMA,66,Initial_MA_Type); MA34:=Mov(VarMA,68,Initial_MA_Type); MA35:=Mov(VarMA,70,Initial_MA_Type); MA36:=Mov(VarMA,72,Initial_MA_Type); MA37:=Mov(VarMA,74,Initial_MA_Type); MA38:=Mov(VarMA,76,Initial_MA_Type); MA39:=Mov(VarMA,78,Initial_MA_Type); MA40:=Mov(VarMA,80,Initial_MA_Type); MA41:=Mov(VarMA,82,Initial_MA_Type); MA42:=Mov(VarMA,84,Initial_MA_Type); MA43:=Mov(VarMA,86,Initial_MA_Type); MA44:=Mov(VarMA,88,Initial_MA_Type); MA45:=Mov(VarMA,90,Initial_MA_Type); MA46:=Mov(VarMA,92,Initial_MA_Type); MA47:=Mov(VarMA,94,Initial_MA_Type); MA48:=Mov(VarMA,98,Initial_MA_Type); MA49:=Mov(VarMA,100,Initial_MA_Type); My code for Metastock: TH:= If(Ref(CLOSE,-1) > HIGH,Ref(CLOSE,-1), HIGH); TL:= If(Ref(CLOSE,-1) < LOW ,Ref(CLOSE,-1), LOW ); TR:= TH-TL; PlusDM := If(HIGH > Ref(HIGH,-1) AND LOW >= Ref(LOW,-1), HIGH-Ref(HIGH,-1), If(HIGH > Ref(HIGH,-1) AND LOW < Ref(LOW,-1) AND HIGH - Ref(HIGH,-1) > Ref(LOW,-1) - LOW, HIGH - Ref(HIGH,-1),0)); ADXPr:=8; PlusDI := 100 * Wilders(PlusDM,ADXPr) / Wilders(Tr,ADXPr); MinusDM:= If(LOW < Ref(LOW,-1) AND HIGH <= Ref(HIGH,-1), Ref(LOW,-1) - LOW, If(HIGH > Ref(HIGH,-1) AND LOW < Ref(LOW,-1) AND HIGH - Ref(HIGH,-1) < Ref(LOW,-1) - LOW, Ref(LOW,-1) - LOW,0)); MinusDI := 100 * Wilders(MinusDM,ADXPr) / Wilders(Tr,ADXPr); DIDif := Abs(PlusDI - MinusDI); DISum := PlusDI + MinusDI; ADXFinal := 100 * Wilders(DIDif/DISum,ADXPr); ADXRCustom:= (ADXFinal + Ref(ADXFinal,1-ADXPr)) / 2; ADXtype:=0; VADX := If(ADXtype = 0,ADXFinal,ADXRCustom); Barnum := BarsSince(100); VarMAPr:=4; EmaIndex:= If(VarMAPr > 0 ,(2 / (1+VarMAPr)) ,0.20); Diff := HHV(VADX, ADXPr) - LLV(VADX, ADXPr); MyConst := If(Diff > 0,(VADX - LLV(VADX,ADXPr)) / Diff,EmaIndex); MyConst := If(MyConst > EmaIndex,EmaIndex,MyConst); VarMA := If(Barnum < ADXPr + (ADXPr * 1.5), CLOSE,Mov((((1 - MyConst) * Ref(VarMA,-1)) + (MyConst * CLOSE)), 2, S)); Two probelms i am facing is, 1) VarMa not returning any value 2) Metastock limiting to number of variables defined to 20 So point 2 can be solvable, as all MA's are computed from VarMa only, so once VarMa got completed, one can add moving averages on it. Please help in getting VarMa... Disclaimer: i am a new coder, its an attmept from my side
wabbit  
#2 Posted : Sunday, December 2, 2012 1:28:42 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)
You need to make a few changes to get the code to work and understand more about the self-referencing in MS...

ALWAYS check for DBZ errors.


Code:

ADXPr:=8;
ADXType:=0;
VarMAPr:=4;

{Calculate Wilders Average Directional Index [ADX]}
TH:=If(Ref(C,-1)>H,Ref(C,-1),H);
TL:=If(Ref(C,-1)<L,Ref(C,-1),L);
TR:=TH-TL;

PlusDM:=If(H>Ref(H,-1) AND L>=Ref(L,-1),H-Ref(H,-1),If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)>Ref(L,-1)-L,H-Ref(H,-1),0));
PlusDI:=100*Wilders(PlusDM,ADXPr)/Wilders(Tr,ADXPr);

MinusDM:=If(L<Ref(L,-1) AND H<=Ref(H,-1),Ref(L,-1)-L,If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)<Ref(L,-1)-L,Ref(L,-1)-L,0));
MinusDI:=100*Wilders(MinusDM,ADXPr)/Wilders(Tr,ADXPr);

DIDif:=Abs(PlusDI-MinusDI);
DISum:=PlusDI+MinusDI;

ADXFinal:=100*Wilders(DIDif/DISum,ADXPr);
ADXRCustom:=(ADXFinal+Ref(ADXFinal,1-ADXPr))/2;

myADX:=If(ADXtype=0,ADXFinal,ADXRCustom);

{Calculate a Variable Moving Average using method devised by Tushar Chande}
EmaIndex:=If(VarMAPr>0,(2/(1+VarMAPr)),0.20);
Diff:=HHV(myADX,ADXPr)-LLV(myADX,ADXPr);

MyConst:=If(Diff>0,(myADX-LLV(myADX,ADXPr))/Max(Diff,Power(10,-8)),EmaIndex);
MyConst:=If(MyConst>EmaIndex,EmaIndex,MyConst);
VarMA:=Mov((1-MyConst)*PREV)+(MyConst*C),2,S);

{PLOT}
VarMA;
Mov(VarMA, 5,E);
Mov(VarMA,10,E);
Mov(VarMA,15,E);
Mov(VarMA,20,E);
Mov(VarMA,25,E);
Mov(VarMA,30,E);
Mov(VarMA,35,E);
Mov(VarMA,40,E);
Mov(VarMA,45,E);
Mov(VarMA,50,E);
Mov(VarMA,55,E);
Mov(VarMA,60,E);
Mov(VarMA,65,E);
Mov(VarMA,70,E);
Mov(VarMA,75,E);
Mov(VarMA,80,E);
Mov(VarMA,85,E);
Mov(VarMA,90,E);
Mov(VarMA,95,E);
Mov(VarMA,100,E);
which ends up with VarMA being a 2 period SMA of variable period EMA of CLOSE price, where the length of the EMA is driven by a scaled stochastic value of myADX... and I reckon there's quite a few better ways to achieve this result.


wabbit [:D]

anilcool  
#3 Posted : Sunday, December 2, 2012 2:02:03 AM(UTC)
anilcool

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/16/2011(UTC)
Posts: 12

Dear wabbit, Thanks a lot, really a prompt reply...and thanks for guidance... Will look into Metastock primer more thoroughly...
wabbit  
#4 Posted : Sunday, December 2, 2012 2:06:26 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)
There's lots in this code which makes no sense to me, so have a very close look at each line of code and try to understand what it is doing. I am not sure whether what the original author achieved was through intention, or they just didn't quite understand what they were doing, but ended up with something which looked pretty (and they could probably flog to the uneducated masses?)

There's plenty of scope in there to "improve" the code, or at least, make it much more logical (and/or explainable)!


wabbit [:D]
anilcool  
#5 Posted : Sunday, December 2, 2012 2:22:05 AM(UTC)
anilcool

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/16/2011(UTC)
Posts: 12

Dear Wabbit, Yes, actually i am on testing phase, and looking into it. The original code proposed VT users, and his idea is, In VMA as proposed by tushar chande, it is using CMO, but here he try to induce ADX into it, so that trending/non trending phase can be taken into consideration. The idea has been explained here.. http://www.traderslabora...-forex-trend-trades.html
wabbit  
#6 Posted : Sunday, December 2, 2012 7:34:42 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)
I had a quick peruse of that thread on TL... could be useful for some people, lots of rubbish there too though.

Anyway, I did a quick edit of the code commensurate with what I thought of the many discussions there and added something new, I came up with this :

Code:

{ALL inputs must be >= 1.0}
ADXPr:=8;
VarMAPr:=4.0;
Sensitivity:=2.5;

data:=(H+L)/2;

{error/bounds checks}
ADXPr:=LastValue(Max(ADXPr,1));
VarMAPr:=Max(VarMAPr,1);
Sensitivity:=Max(Sensitivity, 1);

{Calculate Wilders Average Directional Index [ADX]}
TR:=ATR(ADXPr);

PlusDM:=If(H>Ref(H,-1) AND L>=Ref(L,-1),H-Ref(H,-1),If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)>Ref(L,-1)-L,H-Ref(H,-1),0));
PlusDI:=Wilders(PlusDM,ADXPr)/TR;

MinusDM:=If(L<Ref(L,-1) AND H<=Ref(H,-1),Ref(L,-1)-L,If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)<Ref(L,-1)-L,Ref(L,-1)-L,0));
MinusDI:=Wilders(MinusDM,ADXPr)/TR;

DIDif:=Abs(PlusDI-MinusDI);
DISum:=PlusDI+MinusDI;

myADX:=Wilders(DIDif/DISum,ADXPr);

{Variable Moving Average}
Diff:=HHV(myADX,ADXPr)-LLV(myADX,ADXPr);
len:=(myADX-LLV(myADX,ADXPr))/Max(Diff,Power(10,-8)); {len : [0,1]}

len:=len*(2/(1+VarMAPr)); {len : [0,0<expr<=1]}

VarMA:=(((Sensitivity-len)*PREV)+(len*data))/Sensitivity;

{PLOT}
VarMA;
Mov(VarMA, 5,E);
Mov(VarMA,10,E);
Mov(VarMA,15,E);
Mov(VarMA,20,E);
Mov(VarMA,25,E);
Mov(VarMA,30,E);
Mov(VarMA,35,E);
Mov(VarMA,40,E);
Mov(VarMA,45,E);
Mov(VarMA,50,E);
Mov(VarMA,55,E);
Mov(VarMA,60,E);
Mov(VarMA,65,E);
Mov(VarMA,70,E);
Mov(VarMA,75,E);
Mov(VarMA,80,E);
Mov(VarMA,85,E);
Mov(VarMA,90,E);
Mov(VarMA,95,E);
Mov(VarMA,100,E);


The key changes I have made are to the last two lines of working code, len and of course the VarMA itself; I also put more weight in MEDIAN PRICE than CLOSE. Have a play and let us know how you get along with it.



wabbit [:D]

anilcool  
#7 Posted : Tuesday, December 4, 2012 10:56:49 PM(UTC)
anilcool

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/16/2011(UTC)
Posts: 12

Dear Wabbit, Thanks for the updated code..will surely know of strategy buildup, if any here only... Thanks...
Gun4hire  
#8 Posted : Sunday, February 17, 2013 2:48:09 PM(UTC)
Gun4hire

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/17/2013(UTC)
Posts: 2

Hello Guys!
Its a wonderful community ya'all have nurtured.I landed here while looking for Fantail VMA for Metastock.I have recently made the switch from Ninja, and i absolutely love Fantail VMA for trend identification.I picked the formula here ,so far so good, but when i added vertical shift, it doesnot work.I was wondering if anybody out here could help and resolve the issue.I would be grateful! Heres the code:

{ALL inputs must be >= 1.0}
ADXPr:=6;
VarMAPr:=4.0;
Sensitivity:=2.5;

data:=(H+L)/2;

{error/bounds checks}
ADXPr:=LastValue(Max(ADXPr,1));
VarMAPr:=Max(VarMAPr,1);
Sensitivity:=Max(Sensitivity, 1);

{Calculate Wilders Average Directional Index [ADX]}
TR:=ATR(ADXPr);

PlusDM:=If(H>Ref(H,-1) AND L>=Ref(L,-1),H-Ref(H,-1),If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)>Ref(L,-1)-L,H-Ref(H,-1),0));
PlusDI:=Wilders(PlusDM,ADXPr)/TR;

MinusDM:=If(L<Ref(L,-1) AND H<=Ref(H,-1),Ref(L,-1)-L,If(H>Ref(H,-1) AND L<Ref(L,-1) AND H-Ref(H,-1)<Ref(L,-1)-L,Ref(L,-1)-L,0));
MinusDI:=Wilders(MinusDM,ADXPr)/TR;

DIDif:=Abs(PlusDI-MinusDI);
DISum:=PlusDI+MinusDI;

myADX:=Wilders(DIDif/DISum,ADXPr);

{Variable Moving Average}
Diff:=HHV(myADX,ADXPr)-LLV(myADX,ADXPr);
len:=(myADX-LLV(myADX,ADXPr))/Max(Diff,Power(10,-8)); {len : [0,1]}

len:=len*(2/(1+VarMAPr)); {len : [0,0<expr<=1]}

VarMA:=(((Sensitivity-len)*PREV)+(len*data))/Sensitivity;
shift:=Input("VarMA vertical shift %", -100,100,0)/100+1;
{PLOT}
VarMA;
wabbit  
#9 Posted : Sunday, February 17, 2013 4:58:10 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)
Gun4hire wrote:
when i added vertical shift, it doesnot work.I was wondering if anybody out here could help and resolve the issue.

You added the line of code to get the vertical shift value, but you didn't do anything with that value.

Change the last line in your code to read:
Code:

{plot}
VarMA*shift;




wabbit [:D]

Gun4hire  
#10 Posted : Monday, February 18, 2013 12:18:28 AM(UTC)
Gun4hire

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/17/2013(UTC)
Posts: 2

Woh Wabbit!
I am elated.I couldn't sort it out ,i'm a noob at programming.Thanks a ton !

Regards
Sidhu
Users browsing this topic
Guest (Hidden)
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.