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

Notification

Icon
Error

Options
Go to last post Go to first unread
crossover  
#1 Posted : Tuesday, November 13, 2012 4:29:15 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

My boss has been creating his own custom indicators in metastock for years.Even though he has a powerfull computer he has been having performance issues when he opens several indicators at the same time. He is suspecting that its the way he has written his formulas that is causing the problem.i will give an example: He made an indicator called "MY ADX FLEXI PRA CHL 14" with the following formula: PlusDM:= If(H>Ref(H,-1) AND L>=Ref(L,-1), H-Ref(C,-1), If(H >Ref(H,-1) AND L<ref(L,-1)AND H-Ref(H,-1)> Ref(L,-1)-L, H-Ref(C,-1), 0)); PlusDI:=10000*Wilders(PlusDM,14)/ATR(14); MinusDM:= If(L<ref(L,-1) AND H<=Ref(H,-1), Ref(C,-1)-L, If(H>Ref(H,-1) AND L<ref(L,-1)AND H-Ref(H,-1)<ref(L,-1)-L, Ref(C,-1)-L, 0)); MinusDI:=10000*Wilders(MinusDM,14)/ATR(14) ; DIDif:=Abs(PlusDI-MinusDI); DISum:=PlusDI+MinusDI; ADXFinal:=10000*Wilders(DIDif/DISum,14); PRA:= Mov(ADXFinal - MinusDI, 14,E)+10000; If( (((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100)>0, (((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100), If( (((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100)<0, (((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100),0)); As you can see he declares 8 variables inside this formula: plusdm,plusdi,minusdm,minusdi,Didif,DISum,ADXFinal,PRA. He has similar indicators that use the same variables and he has declared them in their respective formulas aswell. Would the performance improve if we created 7 new indicators (ie. plusdm,plusdi,minusdm,minusdi,Didif,DISum,ADXFinal,PRA) and used the fml function everytime we needed them instead of declaring the variables in every single indicator that they are used ?
John S  
#2 Posted : Tuesday, November 13, 2012 5:04:57 PM(UTC)
John S

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/9/2012(UTC)
Posts: 169

Hi,

Can you do a direct copy/paste out of the Indicator Editor. I'm getting a number of syntax errors.

Thanks.
henry1224  
#3 Posted : Tuesday, November 13, 2012 5:06:33 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
There are errors with your code

Please post your code again,



Code:


PlusDM:=

If(H>Ref(H,-1) AND L>=Ref(L,-1), 

H-Ref(C,-1),

If(H >Ref(H,-1) AND L??? Ref(L,-1)-L, 
{Error on this line}
H-Ref(C,-1),

0));

PlusDI:=10000*Wilders(PlusDM,14)/ATR(14);



 MinusDM:=

If(LRef(C,-1)-L,

If(H>Ref(H,-1) AND L???Ref(C,-1)-L,
{error on this line}
0));

MinusDI:=10000*Wilders(MinusDM,14)/ATR(14) ;



DIDif:=Abs(PlusDI-MinusDI);

DISum:=PlusDI+MinusDI;

ADXFinal:=10000*Wilders(DIDif/DISum,14);



PRA:=

Mov(ADXFinal - MinusDI, 14,E)+10000;



 If(

(((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100)>0,

(((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100),

If(

(((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100)???(((Mov((PRA-Ref(PRA,-1))*100/Ref(PRA,-1),14,E))*14)*100),0));
{Error on this line}
You also have too many multiplications, if you need to multiply for scale issues, then just multiply the last line of code
crossover  
#4 Posted : Tuesday, November 13, 2012 5:17:20 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

Hey, thanks for the replies.Actually i copied the code directly from the indicator builder.It may very well be wrong but this isnt the point.I just wanted to give you an idea about the situation. Is it likely that the performance improves if we use fml instead of declaring the same variables in several indicators?
crossover  
#5 Posted : Tuesday, November 13, 2012 5:28:00 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

I'll give another example with a differnet indicator: Periods:=Input("ADX",1,10000,14); 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:=10000*Wilders(PlusDM,Periods)/ATR(Periods); 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:="10000*Wilders(MinusDM,Periods)/ATR(Periods)" ;=" didif:="Abs(PlusDI-MinusDI);" disum:="PlusDI+MinusDI;" adxfinal:="10000*Wilders(DIDif/DISum,Periods);" rsi(=" mov(=" if(adxfinal=">= MinusDI AND ADXFinal >= PlusDI AND PlusDI >= MinusDI, ADXFinal, If(ADXFinal>= MinusDI AND ADXFinal >= PlusDI AND PlusDI <= MinusDI,(- ADXFinal), If(ADXFinal>= MinusDI AND ADXFinal <= PlusDI AND PlusDI >= MinusDI, ADXFinal, If(ADXFinal<= MinusDI AND ADXFinal >= PlusDI AND PlusDI <= MinusDI,(- ADXFinal), If(ADXFinal<= MinusDI AND ADXFinal <= PlusDI AND PlusDI >= MinusDI,( ADXFinal), If(ADXFinal<= MinusDI AND ADXFinal <= PlusDI AND PlusDI <= MinusDI,(- ADXFinal),0)))))),1,E),Periods); RSI(Mov(- ADXFinal,1,E),Periods); RSI(Mov(ADXFinal,1,E),Periods); Again here there are several variables declared.The same variables are used in more than one indicators.But they are declared in every single indicator they are used in just like the one here. Would the performance be better if instead of declaring them everytime we just created them as indicators just once and then use them with fml in the indicators?
henry1224  
#6 Posted : Tuesday, November 13, 2012 5:32:06 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
the problem stems from the amount of multiplication in your code, they become redundant.
If you are having problems with scaling the indicator, then just multiply the last variable.

If all of your indicators have that many multiplications, then you are wasting resources.

You don't mention how many indicators are plotted on a chart, and how many charts are open at one time?


when posting code from metastock, you cannot just cut and paste

you need to type an asterisk code asterisk then your code asterisk /code asterisk

asterisk is the little star above the number 8 key
crossover  
#7 Posted : Tuesday, November 13, 2012 5:50:37 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

I didnt get to use his indicators yet so i dont know which ones of the bunch he passed me recently is he using. But based on the ones he asked me to take a look at and see if i can do anthing about the perfromance i'd say there's at least 20 indicators (its actually 4 main indicators but each one of them includes an addition of 5 others so its 5x4) that all include the declarations of the same variables such as minusdm,plusdi etc.. im not sure about the number of the open charts but they are plenty (probably a double digit number) i will ask him tomorrow about that.
crossover  
#8 Posted : Tuesday, November 13, 2012 5:54:41 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

Here's the code using the asterisk
Code:
 Periods:=Input("ADX",1,10000,14);

D3:=Input("MOV: ",1,1000,14);

D5:=Input("RSI: ",1,1000,14);

D1:=Input("Time Periods",1,10000,10000);



PlusDM:=

If(H>Ref(H,-1) AND L>=Ref(L,-1), 

H-Ref(C,-1),

If(H >Ref(H,-1) AND L<ref(L,-1)AND H-Ref(H,-1)> Ref(L,-1)-L, 

H-Ref(C,-1),

0));

PlusDI:=D1*Wilders(PlusDM,Periods)/ATR(Periods);



 MinusDM:=

If(L<ref(L,-1) AND H<=Ref(H,-1), 

Ref(C,-1)-L,

If(H>Ref(H,-1) AND L<ref(L,-1)AND H-Ref(H,-1)<ref(L,-1)-L, 

Ref(C,-1)-L,

0));

MinusDI:=D1*Wilders(MinusDM,Periods)/ATR(Periods) ;



DIDif:=Abs(PlusDI-MinusDI);

DISum:=PlusDI+MinusDI;

ADXFinal:=D1*Wilders(DIDif/DISum,Periods);



 Mov(PlusDI - MinusDI,D3,E);

henry1224  
#9 Posted : Tuesday, November 13, 2012 6:03:06 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
go back to my reply that has the code! you will see 3 lines of code that are marked as errors.

Where you see ??? there should be either a greater than ,less than, equal or some other type of operator
crossover  
#10 Posted : Tuesday, November 13, 2012 6:17:15 PM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

Let me try to be more clear.The 1st code i put might have syntax errors.I doubt he is using it.i just put it here to show the logic that his indicators are based on. See the last code i put. He makes the following declarations:
Code:

PlusDM:= 
If(H>Ref(H,-1) AND L>=Ref(L,-1), 
H-Ref(C,-1), 
If(H >Ref(H,-1) AND L Ref(L,-1)-L, 
H-Ref(C,-1), 
0)); 
PlusDI:=D1*Wilders(PlusDM,Periods)/ATR(Periods); 

MinusDM:= 
If(LRef(C,-1)-L, 
If(H>Ref(H,-1) AND LRef(C,-1)-L, 
0)); 
MinusDI:=D1*Wilders(MinusDM,Periods)/ATR(Periods) ; 

DIDif:=Abs(PlusDI-MinusDI); 
DISum:=PlusDI+MinusDI; 
ADXFinal:=D1*Wilders(DIDif/DISum,Periods); 
He needs these declarations in order to calculate the actual indicator:
Code:

Mov(PlusDI - MinusDI,D3,E);
He has several similar indicators that need the same declarations in order to work.He says that if we transform the declarations to indicators (for example create a new indicator called Plus DM with the following formulla:
Code:
 
If(H>Ref(H,-1) AND L>=Ref(L,-1), 
H-Ref(C,-1), 
If(H >Ref(H,-1) AND L Ref(L,-1)-L, 
H-Ref(C,-1), 
0)); 
 
) and then use fml everytime we need them it could reduce the resources needed. Is this correct or it would still require the same amount of calculations?
henry1224  
#11 Posted : Tuesday, November 13, 2012 6:42:22 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
There needs to be some type of mathematical operator wherever I note an error !
Code:
 PlusDM:= 

If(H>Ref(H,-1) AND L>=Ref(L,-1), 

H-Ref(C,-1), 

If(H >Ref(H,-1) AND L Here is an error Ref(L,-1)-L, 

H-Ref(C,-1), 

0)); 

PlusDI:=D1*Wilders(PlusDM,Periods)/ATR(Periods); 



MinusDM:= 

If(LRef(C,-1)-L, 

If(H>Ref(H,-1) AND L Here is another error Ref(C,-1)-L, 

0)); 

MinusDI:=D1*Wilders(MinusDM,Periods)/ATR(Periods) ; 



DIDif:=Abs(PlusDI-MinusDI); 

DISum:=PlusDI+MinusDI; 

ADXFinal:=D1*Wilders(DIDif/DISum,Periods); 

in this snippet of code you have to declare D3
Code:

Mov(PlusDI - MinusDI,D3,E);


Code:

If(H>Ref(H,-1) AND L>=Ref(L,-1), 

H-Ref(C,-1), 

If(H >Ref(H,-1) AND L here is another error Ref(L,-1)-L, 

H-Ref(C,-1), 

0)); 


crossover  
#12 Posted : Wednesday, November 14, 2012 1:49:41 AM(UTC)
crossover

Rank: Member

Groups: Registered, Registered Users
Joined: 11/13/2012(UTC)
Posts: 19

Henry, thanks a lot for your time trying to help me out but you're not listening to me. The syntax errors are irrelevant to my question.i know the indicator above may be broken.Lets say that the operator missing is >= and lets say that D3= 14. Lets call the Indicator above "Indicator 1". Lets say that we have 5 more indicators that have the very same declarations:
Code:

PlusDM:= 
If(H>Ref(H,-1) AND L>=Ref(L,-1), 
H-Ref(C,-1), 
If(H >Ref(H,-1) AND L Here is an error Ref(L,-1)-L, 
H-Ref(C,-1), 
0)); 
PlusDI:=D1*Wilders(PlusDM,Periods)/ATR(Periods); 

MinusDM:= 
If(LRef(C,-1)-L, 
If(H>Ref(H,-1) AND L Here is another error Ref(C,-1)-L, 
0)); 
MinusDI:=D1*Wilders(MinusDM,Periods)/ATR(Periods) ; 

DIDif:=Abs(PlusDI-MinusDI); 
DISum:=PlusDI+MinusDI; 
ADXFinal:=D1*Wilders(DIDif/DISum,Periods);
My boss claims that instead of making the same declarations 5 times, we should make new indicators equal to the declarations above and then use them with the fml function in our 5 indicators. So for example our actual indicator makes this calculation:
Code:

Mov(PlusDI - MinusDI,14,E); 
It needs PlusDI and MinusDI which need plusDM and minusDM. So what if i create 2 indicators called plusDM and minusDM and then create 2 indicators called PlusDI and MinusDI that use the fml function to reference PlusDM and MinusDM and then create another indicator calculating the:
Code:

Mov(PlusDI - MinusDI,14,E);
but with using the fml function instead:
Code:

Mov(fml("PlusDI") - fml ("MinusDI"),14,E);
Imagine this procedure for several indicators.Is this likely to speed up the calculations and require less resources ?
henry1224  
#13 Posted : Wednesday, November 14, 2012 5:20:42 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
You can have up to 20 declared variables in an indicator.You can also reuse some of those 20 variables again, once you have come to their last value.
The use of the Fml() and VarFml() do speed up processing, there are drawbacks!
If you use those functions in another indicator, they default back to their default values.
IE:
Fml(a) has 3 input values Length, smoothing, lookback, you now create Fml(b) that uses Fml(A) as a Variable. Fml(A) will then revert back to it's default values

Another problem with the use of Fml() functions, say you create an indicator Fml(A) that has multiple plot lines Now if I were to use this Fml(A) in another indicator , only "BearRise" would be used since it is the last value stated, to remedy this you would have to use the VarFml() function

Code:
 pds1:=Input("fast ma",3,100,5);
pds2:=Input("slow ma",5,200,21);
pds3:=Input("signal len",2,100,5);
TF:=Input("Time frame 1",1,100,1);
Off:=Input("Offset",0,100,0);
HD:= ExtFml("PowerPivots.TDataCreate",1,TF); 
LD:= ExtFml("PowerPivots.TDataCreate",2,TF) ;
A:=Mov((HD+LD)/2,pds1,E)-Mov((HD+LD)/2,pds2,E);
Sig:=Mov(A,pds3,E);
BullRise:=If(A>0 AND A>Ref(A,-1),A,0);
BullFall:=If(A>0 AND A<Ref(A,-1),A,0);
BearRise:=If(A<0 AND A>Ref(A,-1),A,0);
BearFall:=If(A<0 AND A<Ref(A,-1),A,0);
BullRise:=ExtFml( "PowerPivots.TDataLocalize",BullRise, TF, Off);
BullFall:=ExtFml( "PowerPivots.TDataLocalize",BullFall, TF, Off);
BearRise:=ExtFml( "PowerPivots.TDataLocalize",BearRise, TF, Off);
BearFall:=ExtFml( "PowerPivots.TDataLocalize",BearFall, TF, Off);
UZ:=Ref(HHV(Sig,52),-1)*.90;
LZ:=Ref(LLV(Sig,52),-1)*.90;
Sig:=ExtFml( "PowerPivots.TDataLocalize", Sig, TF, Off);
UZ:=ExtFml( "PowerPivots.TDataLocalize", UZ, TF, Off);
LZ:=ExtFml( "PowerPivots.TDataLocalize", LZ, TF, Off);

UZ;LZ;Sig;BullRise;Bullfall;BearFall;BearRise;



Another problem with the use of Fml() function is in renaming an indicator or deleting that indicator,
then you will get a rat's nest of error messages

In your first post you stated a performance issue! This resulted in the use of multiple mathematical operations that are redundant and are a waste of computer resources.
There are several reasons as to why Metastock slows down, without a visual chart showing what you are doing, it is difficult to determine the cause!
How many Bars are loaded onto your Chart?Are you looking at RealTime or EOD Data?
The Number of Indicators Plotted on a Chart?
How many open Charts are you looking at once?
How many indicators that you use have the Prev()function?
How many indicators have the Security()function?


I would suggest that you read the formula primer that is in the files section in this forum.

I can tell you that a formula that is short and concise will process a lot faster than one that is poorly written!



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.