Discussions
»
Product and Service Development
»
MetaStock
»
How do I create my own function? [RESOLVED]
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 4/18/2005(UTC) Posts: 25
|
Hi
Is it possible to create custom functions? I have many things I like to use in all my systems, and if they were functions I could just call them.
For example I want to write a function that tests if the time of day is within a certain range, if so return true otherwise return false.
So far all I could see are custom indicators and for those I have not even worked out how to build parameters into them.
Thanks
Gerrit
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
You could create indicators that would only reprensent a "function" and then use the formula call function to refer to it.
For example I created an indicator called "Patrick" that does a lot of calculations and that I reuse in all my custom indicators.
I can write : fml("Patrick")
rather than retyping all the code again.
This will however not pass any input you might have programmed in your original indicator and will use the default values.
Patrick
PS: Do not abuse the Fml() function as it does slow down the calculation of an indicator ...
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Here is an example of custom function code:
[code:1:f29698c805]
===================
BarsSince Nth event
===================
---8<-----------------------
{ ©Copyright 2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }
{ User inputs }
NthEvent:=Input("BarsSince Nth event (1=last, 2=2nd last, etc)",1,1000,2);
plot:=Input("plot: [1]BarsSince Nth event, [2]Event signals",1,2,1);
{ Event example }
signal:=Cross(RSI(14),40);
{ Count events backwards }
count:=LastValue(Cum(signal))-Cum(signal)+1;
{ BarsSince Nth event }
BarsSinceNth:=
HighestSinceBars(NthEvent+1,signal,count);
{ Plot in own window }
If(plot=1,BarsSinceNth,signal)
---8<-----------------------
[/code:1:f29698c805]
jose '-)
http://www.metastocktools.com
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 4/18/2005(UTC) Posts: 25
|
Hi Patrick/Jose
I'll use the cutom indicator as you describe. It is a pitty I can not pass input parameters in, but will look at the input function.
Copy and paste + hardcoding will have to cover any limitations.
Thanks
Gerrit
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Discussions
»
Product and Service Development
»
MetaStock
»
How do I create my own function? [RESOLVED]
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.