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

Notification

Icon
Error

Options
Go to last post Go to first unread
mlr94549  
#1 Posted : Saturday, January 3, 2009 11:11:04 AM(UTC)
mlr94549

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/5/2008(UTC)
Posts: 8
Location: California

Ever have the problem where you create a [buy] signal and it lasts for many time periods? What you would like to do, especially in the explorer, is just emit the first signal, then not repeat it through all the time periods. Used Roy Larsen's excellent Latch construct to create a buy signal, but wanted to emit just the first one in the series.
One needs and XOR function for this, but it appears to be missing from MS formula language. One could simulate it using NOT, but that isn't present in MS FL either. But here's something that actually works, and simulates NOT and XOR - in pseudo code...
N:= fml("set signal");
X:= if(N,0,1); {inverse of "set signal}
Latch:= if(n,1,if(x,0,Prev); {Thanks Roy Larsen}
NL:= if(Latch,0,1); {Not Latch}
PL:= Ref(Latch,-1); {Prior value of Latch - ref seems to work here!}
NPL:= if(PL,0,1); {Not Prior Latch}
{And now the formula.....Signal:= (Latch XOR PriorLatch) AND Latch; }
{The XOR is simulated using (Latch and NotPrior) or (NotLatch and Prior) }

Signal:= ( (Latch AND NPL) OR (NL AND PL) AND Latch) {And any other conditions you want}

How it works:
When Signal goes 0->1, XOR yields 1 and Latch yields 1, so the AND is 1.
When Signal goes 1->1, XOR yields so AND with Latch is always 0
When Signal goes 1->0, XOR yields 1 but Latch is now 0, so AND with Latch yields 0

What this will do for you is every time Latch goes from 0 to 1 it will emit a 1; everyother time it will emit zero. This is sometimes known as a rising edge detector. One can similarly create a falling edge detector, but I have no need for one at present.

Michael

oztrader  
#2 Posted : Saturday, January 3, 2009 6:02:02 PM(UTC)
oztrader

Rank: Advanced Member

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

Hi Michael,

Another alternative is to use the Cross function to establish when the 1st event has occurred.

The code below is a slight adaptation of the 1st example in Forum DLL Manual:-

fastMA:=Mov(C,7,S);
slowMA:=Mov(C,21,S);
Buy:=Cross(fastMA,slowMA);
LE:=Cross(Buy,0.5);
LX:=Cross(slowMA,fastMA);
Z:= ExtFml("forum.Latch",LE,LX,0,0);
EnterLong:=Z = 1 AND Ref(Z,-1) <> 1;
ExitLong:=Z = 0 AND Ref(Z,-1) = 1;
EnterLong{-ExitLong;}

Regards,

oz

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.