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

Notification

Icon
Error

Options
Go to last post Go to first unread
Gherkin  
#1 Posted : Monday, March 31, 2014 11:16:52 PM(UTC)
Gherkin

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2010(UTC)
Posts: 22

Was thanked: 2 time(s) in 2 post(s)
Hi everyone. I have been trying to make an exploration that returns stocks when an indicator "X" has spent an amount of time "Y" below zero. Like trying to find stocks where the MACD has been below the zero line for 15 bars or more. I have been searching these forums for a while now and the closest thing I can see is BarsSince.

BarsSince("Formula X")>0>15 --- (this is meant to return stocks only when formula X has been below 0 for 15 bars).

however I keep getting told it's an incorrect reference to formula X with the
"The text that begins with this quote is not being used in a valid location." message.

Am I trying to call on a formula inccorrectly?

I also saw lots of other similar solutions using global variable counts but they seemed much harder to understand.

Any help would be appreciated.

Craig


mstt  
#2 Posted : Tuesday, April 1, 2014 12:19:35 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 Craig

MetaStock does not support the direct comparison of 3 values. Example: X>Y>Z;
You could rewrite your formula as...

BarsSince("Formula X" < 0) >= 15;

Or you could try another approach using the Sum() function.

Sum(BarsSince( "Formula X") < 0, 15) =15;

I'd suggest that you test these possibilities as a New Indicator rather than as an exploration. Indicators are easier to troubleshoot than explorations. If you get an N/A result for an indicator (no result showing) you only need to add an output such as 2*C; as the last line of your indicator so that it will display and can therefore be deleted from the current chart. Deleting an N/A indicator is difficult when you can't see it and therefore cannot mark it for deletion.

Hope this helps

Roy
Gherkin  
#3 Posted : Wednesday, April 2, 2014 11:53:07 PM(UTC)
Gherkin

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2010(UTC)
Posts: 22

Was thanked: 2 time(s) in 2 post(s)
Thanks Roy for your quick reply. I'm still finding it's giving me the exact same error message for both re-writes you gave me, so I'm thinking I'm doing something else wrong. I'll going to have to go through it again tonight and see. It's probably something silly that I'm missing.

Craig
wabbit  
#4 Posted : Thursday, April 3, 2014 12:13:38 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)
The correct method to call another formula is Fml(). You can call a variable used in a formula using FmlVar().

It's in the manual.

Gherkin  
#5 Posted : Thursday, April 3, 2014 3:55:36 AM(UTC)
Gherkin

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2010(UTC)
Posts: 22

Was thanked: 2 time(s) in 2 post(s)
Thanks Wabbit and Roy. All working great now.

Thank you for your help.

Craig
henry1224  
#6 Posted : Thursday, April 3, 2014 7:53:35 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)
It should also be noted that in using the Fml() and FmlVar() functions,If the indicator has an Input function,The Fml() and Fmlvar() functions will use the default input value! The Fml() function will also use the value of the last variable of the code!

Code:
1MA:=mov(C,15,s);Signal:= Mov(1ma,3,S);1ma;Signal;
In the above example, if you were to use the Fml() function, the value that would be used is from the Signal because Signal is the last value in that indicator!
Users browsing this topic
Guest (Hidden)
Similar Topics
Fun with BarsSince event (Advanced Coding Techniques)
by Lloyd_au 4/16/2014 9:18:07 AM(UTC)
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.