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

Notification

Icon
Error

Options
Go to last post Go to first unread
Raymond  
#1 Posted : Wednesday, September 20, 2006 4:14:53 PM(UTC)
Raymond

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/21/2006(UTC)
Posts: 23

It's already a while that i am struggling with this. Still i have not a good solution that i can use to set a stoploss that is related to my entry-price. In this case forex.

The new code i have is this. But it's still not quite working as i want it to.

BUY:

Ref(cross(PDI(14), MDI(14)),-1)
AND
C > Ref(C,-1);

SELL:

LE:=Ref(cross(PDI(14), MDI(14)),-1)
AND
C > Ref(C,-1);
trade:= If(PREV=0, If(LE,Ref(C,-1),0),
If((H>PREV+.0100) OR (L<PREV-.0075) OR
(BarsSince(PREV=0)>150 AND (Ref(C,-150) - C>.005)),0,PREV))
OR
Cross(20,ADX(14));
EnterLong:=Cross(trade=1,0.5);
ExitLong:=Cross(trade=0,0.5);
ExitLong

The SELL code should do the following. Exit long when the current price is moved up100 pips. (should function as a limit) or exit when current price is moved down 75 pips or exit when 150 timeperiods further the current price is down 50 pips or exit when the cross occurs.

I got this code from metastock support, so i guess this should be working allright. When i am testing this in the systemtester i get strange result. The problem is that i can't figure where to find the problem. Is it the systemtester or is the code just wrong? I hope that someone with a experienced eye can review the code for its reliabillity.




wabbit  
#2 Posted : Wednesday, September 20, 2006 6:23:40 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)
Raymond,

Some comments:

1. How can you enter at yesterday's closing price? This isn't realistic. May I suggest you rethink the entry price part of the code?

2. The last part of the exit criteria is outside the latch, so move it back inside the latching for the exit.

3. I mentioned in another thread that sometimes when a muliple PREV latch is not working exactly as you think it should b, to isolate the PREVs from any mathematical computation. I have my suspicion why this occurs, but I have handed this information off to Roy to test for inclusion in his next issue of MSTT, so stay tuned for the definitive answer; but isolating the PREV might solve your problem...

4. On the exit signal, trip a value less than zero (here I used -1) so that a value gets drawn on the exit bar. To find the entry bar, Tr>0 AND Alert(Tr<>0,2). To find the Exit bar, Tr=-1.

Try this for the Trade Latch, and report back its operation:

Code:

Tr:=
If(PREV<=0,
If(LE,Ref(C,-1),0), {how can you enter at yesterday's close?}
If(
(H-0.0100)>PREV OR {isolate the PREVs}
(L+0.0075)<PREV OR {isolate the PREVs}
Cross(20,ADX(14)) OR
(BarsSince(PREV=0)>150 AND (Ref(C,-150)-C>.005))
,-1,PREV)) {trip -1 instead of zero}
);



Hope this helps. Let us know how it goes.


wabbit [:D]


Raymond  
#3 Posted : Thursday, September 21, 2006 9:56:44 AM(UTC)
Raymond

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/21/2006(UTC)
Posts: 23

Thanks Wabbit, this is absolutely great. This is what i was looking for. As far as i've tested it generates the right stoploss-point based on the first entry-price that is generated.

Regarding your comment:

It actually does not enter at yesterday's close. (maybe it should regarding the code, but in my tests it doesn't ...) If i use this code and plot it in a chart a entersignal is always generated 1 timerperiod further then LE=true. When LE is defined i state that the current price should be higher then the close one timeperiod ago. I honestly do not know how to read the if-statement.

If(LE,Ref(C,-1),0)

I mean, this is already defined in LE? I have no idea what to put there to replace the "Ref(C,-1)"


wabbit  
#4 Posted : Thursday, September 21, 2006 10:02:07 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 I use goes something like this:

As my entry criteria is based on the closing prices, if an entry signal is made using the close prices today, the earliest I can get into the stock is on the opening tomorrow.

In code: I have

If(Ref(LE,-1),OPEN,0) etc

which says, (on daily bars) if at yesterdays close there is an entry signal, having placed my order overnight, I will enter (will have entered) at the opening the day after the signal is generated.


Its late here.... I hope this makes sense...

wabbit [:D]


Raymond  
#5 Posted : Thursday, September 21, 2006 12:48:03 PM(UTC)
Raymond

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/21/2006(UTC)
Posts: 23

Yes it definately makes sense.

Your code:

if(Ref(LE,-1), OPEN, 0)

LE is already defined with Ref,-1 so now it would generate a signal two periods further.
The problem with OPEN in my tests is that it keeps on generating entry signals until an exitsignal is generated. The initial entry signal is correct though. To me this IF statement is not really necessary because it is pretty much covered with the definition of LE?


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.