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

Notification

Icon
Error

Options
Go to last post Go to first unread
jjstein  
#1 Posted : Monday, August 14, 2006 8:02:58 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
I'd like to put this in the TREND section of an Expert: BULLISH buy:=If(Cross(C,Mov(C,10,E)),-1,0); sell:=If(Cross(Mov(C,10,E),C),1,0); init:=Cum(buy)+Cum(sell)=0; Bull:=BarsSince(Ref(buy,-1))>BarsSince(Ref(sell,-1)); Bear:=BarsSince(Ref(buy,-1))
wabbit  
#2 Posted : Monday, August 14, 2006 8:11:03 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)
buy:=If(Cross(C,Mov(C,10,E)),-1,0);
sell:=If(Cross(Mov(C,10,E),C),1,0);

init:=Cum(buy)+Cum(sell)=0;

Bull:=BarsSince(Ref(buy,-1))>BarsSince(Ref(sell,-1));
Bear:=BarsSince(Ref(buy,-1))

You INITIALISE the criteria, but you don't use this in your latch!



Hope this helps.

wabbit :D
jjstein  
#3 Posted : Monday, August 14, 2006 8:45:01 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Code:

buy:=If(Cross(C,Mov(C,50,E)),-1,0); 
sell:=If(Cross(Mov(C,50,E),C),1,0); 
{init:=Cum(buy)+Cum(sell)=0;}

Bull:=Buy AND BarsSince(Ref(buy,-1))>BarsSince(Ref(sell,-1));
Bear:=Sell AND BarsSince(Ref(buy,-1))
Jose  
#4 Posted : Tuesday, August 15, 2006 2:25:30 PM(UTC)
Jose

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)
Jjstein, the BarsSince() function creates a missing 1st signal problem, whenever the first entry signal arrives before an exit signal is generated. Try my simple solution to this problem by using the ValueWhen() function, from MetaStockTools.com: Trade signals jose '-)
jjstein  
#5 Posted : Friday, August 18, 2006 10:08:44 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)

Thanks, Jose. I'm studing your code now. My solution (with Wabbit's help) is:

Code:

buy:=If(Cross(C,Mov(C,50,E)),-1,0);
sell:=If(Cross(Mov(C,10,E),C),1,0);
init:=Cum(buy+sell>-1)=1;
Bull:=BarsSince(Init OR Buy)<
 BarsSince(Init OR Sell);
Bear:=BarsSince(Init OR Buy)>
 BarsSince(Init OR Sell);
If(Bull,1,If(Bear,-1,0));
--Johnathan

Jose  
#6 Posted : Friday, August 18, 2006 11:01:44 PM(UTC)
Jose

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)

Simply put:

entry:=Cross(C,Mov(C,50,E));

exit:=Cross(Mov(C,10,E),C);

init:=Cum(IsDefined(entry+exit))=1;

flag:=ValueWhen(1,entry-exit<>0 OR init,entry);

flag

jose '-)

jjstein  
#7 Posted : Saturday, August 19, 2006 8:49:46 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)

Jose -- Elegant simplification! If I read it right:

1. "Init" is true ONLY on the 1st valid entry OR exit, on-or-after the 50th data point.

2. "Flag" can only be 0 for exit "season", or 1 for entry "season", on-or-after either is valid, due to use of "IsDefined" through "init."

But, how to stay consistent with a positve (+1) for up and negative (-1) for down?

If I'm correct, the last line must be: If(flag,1,-1);

This leaves out the option of (0) for unknown/neither, but I can probably live w/that...

Jose  
#8 Posted : Saturday, August 19, 2006 4:38:27 PM(UTC)
Jose

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)
"But, how to stay consistent with a positve (+1) for up and negative (-1) for down?" flag*2-1 J, the "0" option in your original formula is not useful - it just seems to plot a zero when signals are not yet defined. jose '-)
jjstein  
#9 Posted : Saturday, August 19, 2006 5:21:06 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)

After upping the "exit" MA to 20, I plotted this indicator on DIA, and it's clear that it there's an exit bias PRIOR to an actual cross in late Apr 98.

Wouldn't the "0" option be needed AFTER signals are possible, but BEFORE a signal is given, to avoid a possible initial bias? I see four possibilities:

1. Undefined. Signal irrelevant.

2. Defined, but no signal.

3. Defined, 1st signal is/was Entry.

4. Defined, 1st signal is/was Exit.

The "0" option allows for possibility #2.

P.S. It seems "IsDefined" acts like NA() in Excel - nullifies anything dependent on it -- is that right?

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.