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

Notification

Icon
Error

Options
Go to last post Go to first unread
AMSH  
#1 Posted : Thursday, February 12, 2009 6:59:15 AM(UTC)
AMSH

Rank: Member

Groups: Registered, Registered Users
Joined: 11/15/2008(UTC)
Posts: 17

Hey Guys,

Anybody know how to get the barssince function to return zero (instead of having no value) before the condition it's based on becomes true for the first time. In other words, if I'm using Barssince(cross(C,mov(C,5,e))) and the cross hasn't yet happened, the funtion returns no value at all. I need a zero returned up to the point that the condition is met, then the funtion is fine.

This seems a bit basic, but I can't find a way to do it.

Any thoughts?

Cheers,

AMSH
oztrader  
#2 Posted : Thursday, February 12, 2009 3:14:37 PM(UTC)
oztrader

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 7/12/2007(UTC)
Posts: 134
Location: Perth Western Australia

Hi AMSH,

Your formula, Barssince(cross(C,mov(C,5,e))), will return a value of zero on the bar that the close crosses above the 5 bar EMA.

Cheers,

oz

wabbit  
#3 Posted : Thursday, February 12, 2009 3:31:13 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)
Metastock indicators have a number of "attributes" not accessible by the user, but the program itself has access to these; these include any data array first valid and last valid attributes.

The BarsSince() function becomes valid for the first time when the first instance of the expresssion in the brackets becomes true; before this time the function returns N/A (as you have seen).

There are a number of different ways to deal with this, but the simplest solution is to use the free forum.dll library of functions, and use the Sum() function from that library. This particular function returns a value of 0 when its input argument is N/A, sum over one bar.

Try something like:
Code:

x0:=cross(C,mov(C,5,e));
x1:=Barssince(x0);
x2:=ExtFml("Forum.sum",x1,1);
{plot}
x2;



Hope this helps.

wabbit [:D]

AMSH  
#4 Posted : Friday, February 13, 2009 1:22:21 AM(UTC)
AMSH

Rank: Member

Groups: Registered, Registered Users
Joined: 11/15/2008(UTC)
Posts: 17

Hey Wabbit,
Mate, that gives me a zero value up to the condition being met but then reverts back to the zero value after the condition is met (and it returns a 1 for one bar). This is what I kept getting when I was playing with it. I need the code to return a zero up to the condition being met and afterwards reverting to the barssince function. In other words, one day before the condition is met, I want a zero value; one day after it's met I want a one value; twenty six days after the condition is met I want a twenty six value.

Basically, I'm using Tradesim and MS and am trying to avoid TS giving me hundreds of errors because the barssince function is returning a N/A value for stocks where no trades are made - this slows the testing process down significantly.

I've tried playing with comparing two functions (barssince and a variable sum of barssince) for a greater value (or any value) but because the N/A value isn't really a value, it can't be used in this way (or so it appears).

Any other ideas?

By the way, I emailed you re some custom coding a couple of nights ago.
wabbit  
#5 Posted : Friday, February 13, 2009 2:56:39 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 code seems to be working fine here? Compare your code with what I have (a pic is attached to show it all working too...) It's easier to provide assistance if you post the code you are using (please cut-and-paste instead of re-typing any code, sometimes people can post the right code when the error is in the code in MS).

I am working my way through a plethora of emails I received whilst away. Hopefully I will get to yours soon (I think I saw your requests last night?)


wabbit [:D]

wabbit attached the following image(s):
ccl.jpg
AMSH  
#6 Posted : Friday, February 13, 2009 3:11:12 AM(UTC)
AMSH

Rank: Member

Groups: Registered, Registered Users
Joined: 11/15/2008(UTC)
Posts: 17

Sorry mate, that does seem to be doing what I want it to do now. Not sure how/why it was returning different values last time. It's still doing strange stuff when I substitute my actual entry code for the cross but I'll have a play with it and should be able to sort it out. Many thanks for the help champ.

Sent an email Wed night entitled - "Custom External Formula Quote".

Cheers,

AMSH
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.