Discussions
»
Special Interest Groups
»
Advanced Coding Techniques
»
LATCH QUESTION: Redundant Signal Filter misses 1st signal
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))
|
|
|
|
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
|
|
|
|
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))
|
|
|
|
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 '-)
|
|
|
|
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
|
|
|
|
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 '-)
|
|
|
|
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...
|
|
|
|
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 '-)
|
|
|
|
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)
|
Discussions
»
Special Interest Groups
»
Advanced Coding Techniques
»
LATCH QUESTION: Redundant Signal Filter misses 1st signal
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.