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

Notification

Icon
Error

Options
Go to last post Go to first unread
j32driver  
#1 Posted : Sunday, September 16, 2007 7:48:28 PM(UTC)
j32driver

Rank: Member

Groups: Registered, Registered Users
Joined: 6/29/2007(UTC)
Posts: 19

Good evening everyone,

I'm trying to use the forum.latch function for the 1st time. The "Long Entry" and "Short Entry" generate the expected signals. Both exit signals however fail to print on a chart. Here is the code I'm using:

{ENTER LONG}

LE:= OscP(10,30,S,$)>0;

LX:= OscP(10,30,S,$) < Ref(OscP(10,30,S,$),-1);

SE:= OscP(10,30,S,$)<0;

SX:= OscP(10,30,S,$) > Ref(OscP(10,30,S,$),-1);

B:= ExtFml(“forum.Latch",LE,LX,SE,SX);

B = 1 AND Ref(B,-1) <> 1

{ENTER SHORT}

LE:= OscP(10,30,S,$)>0;

LX:= OscP(10,30,S,$) < Ref(OscP(10,30,S,$),-1);

SE:= OscP(10,30,S,$)<0;

SX:= OscP(10,30,S,$) > Ref(OscP(10,30,S,$),-1);

B:= ExtFml(“forum.Latch",LE,LX,SE,SX);

B = -1 AND Ref(B,-1) <> -1

{EXIT LONG}

LE:= OscP(10,30,S,$)>0;

LX:= OscP(10,30,S,$) < Ref(OscP(10,30,S,$),-1);

SE:= OscP(10,30,S,$)<0;

SX:= OscP(10,30,S,$) > Ref(OscP(10,30,S,$),-1);

B:= ExtFml(“forum.Latch",LE,LX,SE,SX);

B = 0 AND Ref(B,-1) = 1

{EXIT SHORT}

LE:= OscP(10,30,S,$)>0;

LX:= OscP(10,30,S,$) < Ref(OscP(10,30,S,$),-1);

SE:= OscP(10,30,S,$)<0;

SX:= OscP(10,30,S,$) > Ref(OscP(10,30,S,$),-1);

B:= ExtFml(“forum.Latch",LE,LX,SE,SX);

B = 0 AND Ref(B,-1) = -1

Any idea why the entry signals print, but the exits do not?

johnl  
#2 Posted : Sunday, September 16, 2007 8:36:59 PM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602


Here is a latch code given by Wabbit a while back. You may want to use this and look
closer at the the values of each variable if this is what you are trying to code.
=============
a1:= Fml("a");
a2:= Fml("b");
i:=Cum(a1+a2>-1)=1; {initialixation - inputs are valid}
x:=BarsSince(i OR a1)<BarsSince(i OR a2); {latch}
x:=Alert(x,2) AND a2; {first a2 after a1}
x;
============

wabbit  
#3 Posted : Sunday, September 16, 2007 11:33:55 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)
The code you provided is basically a swing trading method where the exit from a trade in one direction is the signal to enter the trade in the opposite direction... but not absolutely every time, but this is predominately the case. If you plotted each of the indicators in the same inner window, some of the signals would obscure the other signals for the same bar; this is why you cannot see some of the signals.

Another way to view the trade status would be to use the continuous indicator, "B" and view this in the inner window. If you must see the signals then use a modified binary system to combine signals in each direction:

e.g.

Code:
data:=OscP(10,30,S,$);

LE:= data>0;
LX:= data < Ref(data,-1);
SE:= data<0;
SX:= data > Ref(data,-1);

{1 if long, -1 if short, 0 if no trade open}
status:=ExtFml("forum.Latch",LE,LX,SE,SX);

{plot}
status;



and for the signals themselves, there are many ways to do this, here are two:

Code:
data:=OscP(10,30,S,$);

LE:= data>0;
LX:= data < Ref(data,-1);
SE:= data<0;
SX:= data > Ref(data,-1);

B:=ExtFml("forum.Latch",LE,LX,SE,SX);

{recycling the variables}
LE:= B=1 AND Ref(B,-1)<>1;
LX:= B<>1 AND Ref(B,-1)=1;
SE:= B=-1 AND Ref(B,-1)<>-1;
SE:= B<>-1 AND Ref(B,-1)=-1;

{assign binary values, 1* shown for consistency}
signals:= 1*LE + 2*LX + 4*SE + 8*SX;

{plot}
status;


Each time there are two signals on the same bar, we will be able to tell by learning the simple values for each possible scenario:

status = 1 then only the LE signal is given
status = 6 then there was a LX and a SE signal on the same bar
status = 9 then there was a SX and a LE signal on the same bar etc etc.

Another way might be to:

Code:
data:=OscP(10,30,S,$);

LE:= data>0;
LX:= data < Ref(data,-1);
SE:= data<0;
SX:= data > Ref(data,-1);

B:=ExtFml("forum.Latch",LE,LX,SE,SX);

{recycling the variables}
LE:= B=1 AND Ref(B,-1)<>1;
LX:= B<>1 AND Ref(B,-1)=1;
SE:= B=-1 AND Ref(B,-1)<>-1;
SE:= B<>-1 AND Ref(B,-1)=-1;

long:= 2*(LE-LX);
short:= SE-SX;

{plot}
long;
short;


where we would see values of 2 and -2 for long trade entry and exit signals, 1 and -1 for short trade signals.

By observing the signals from the last posted code, it is possible to see how the latch algorithm works/does not work: A word of warning about the forum.latch function, it might not perform exactly as you might like to trade. The action of the latch on receipt of the different signals might not be exactly to your requirements. The forum.latch is an adequate, generalised function for a lot of people but may not suit every trader and their style. Please do a search of the forum to find out more information on how the latch function works/does not work (http://forum.equis.com/forums/permalink/24615/24615/ShowThread.aspx#24615
j32driver  
#4 Posted : Monday, September 17, 2007 8:10:07 AM(UTC)
j32driver

Rank: Member

Groups: Registered, Registered Users
Joined: 6/29/2007(UTC)
Posts: 19

Thanks a ton guys. Wabbit... as always... YOU ROCK! Its going to take me a while to digest this. Thank you!

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.