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 : Thursday, October 5, 2006 1:10:26 PM(UTC)
Raymond

Rank: Member

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

I need a trailing stop function for the code below. I've checked out several trailing stop functions from metastocktools.com and also the Advanced trailing stop plugin. I am not able to integrate this as a working method for my code using a 5 min. chart forex.

For BUY
c1:=MACD();
c2:=Mov(MACD(),9,E);

LE:=Ref(Cross(c1,c2),-1) AND
C > Ref(C,-1) AND Stoch(12,3)<50;

Tr:=
If(PREV<=0,
If(Ref(LE,-1),O,0),
If(
(H-0.0020)>PREV OR
(L+0.0050)<PREV,-1,PREV)
);

Tr>0 AND Alert(Tr<>0,2)

-----------------------------
For SELL

c1:=MACD();

c2:=Mov(MACD(),9,E);

LE:=Ref(Cross(c1,c2),-1) AND
C > Ref(C,-1) AND Stoch(12,3)<50;

ATRstop:=ATR(10)*2;

Tr:=
If(PREV<=0,
If(Ref(LE,-1),O,0),
If(
(H-0.0020)>PREV OR
(L+0.0050)<PREV OR C<PREV-ATRstop
,-1,PREV));

Tr=-1;

You see, i've been trying something with ATRstop, but it actually doesn't make any sense (C<PREV-ATRstop)

I want a trailing stop that is activated when the first 20 pip pricetarget has been reached OR when a certain amount of timeperiods has passed. That trailing stop should be able to exit the trade when 15% decrease has taken place based on the highest value since the 20 pip pricetarget has been reached. Any help is welcome!

(ps. the buysignal still carries the problem that it keeps plotting buysignals even if the condition isn't true anymore...very weird. The reference to the entryprice for defining the exittarget is working fine though)


wabbit  
#2 Posted : Thursday, October 5, 2006 6:18:28 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)
redrunner wrote:
I want a trailing stop that is activated when the first 20 pip pricetarget has been reached OR when a certain amount of timeperiods has passed. That trailing stop should be able to exit the trade when 15% decrease has taken place based on the highest value since the 20 pip pricetarget has been reached.


Deja vu? Haven't we been through this already?


One of your exit conditions will be :

.... other exit crtiteria
OR ((H-0.0020)>PREV AND C<(HighestSince(1,PREV<=0,H)*0.85))),
-1,PREV);
etc....


If it doesn't work like you want... let me know and I will have another look at it with you.


wabbit [:D]

P.S. Charts people! We need to some more charts! Its easier to analyse what is going on/wrong when we can see the formulas in action on the actual data. Personally I hate having to copy the code from here into a new indicator, try and find a suitable chart in amongst the myriads of possibilities to find that to me everything looks OK. Often it is because we do not know EXACTLY what you are intending the code to do. If you post a fully annotated chart, highlighting where the problems are, then it makes it easier to help you. The easier it is for someone to help, the faster you get an answer....

Raymond  
#3 Posted : Friday, October 6, 2006 7:06:32 AM(UTC)
Raymond

Rank: Member

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

Thanks Wabbit, yes indeed deja vu, i'm still not finished with this code :-)

Nevertheless, this new topic concerns a new problem. The previous problems with referencing the openingprice so i could catch a 20 pip movement is solved.

Next problem is activating a trailing stoploss AFTER this 20 pip movement has evolved.
Your suggestion is therefore not suitable as i wish to cancel the 20 pip exitcriteria when the trailing stoploss is activated. In other words, the High doesn't have to be 20 pips higher for the trailing stoploss to be active later on....the 20 pips higher should only work as a trigger. So....the code below is wrong, but i'll try to explain:

c1:=MACD();
c2:=Mov(MACD(),9,E);

LE:=Ref(Cross(c1,c2),-1) AND
C > Ref(C,-1) AND Stoch(12,3)<50;

Tr:=
If(PREV<=0,If(Ref(LE,-1),O,0),
If(
(L+0.0050)<PREV OR (H-0.0050)>PREV OR
C<HighestSince(1,PREV<=0,H) {this must be active after PREV has a new value (prev=h) }
,-1,If(((H-0.0020)>PREV),PREV=H,PREV)));

Tr=-1;

I've added an extra if-statement that should look for a pipmove of 20, if the move is found i want the openingprice to change from the PREV value to the H value that contains the price with 20 pip move in it. So next time this is executed this line: C<HighestSince(1,PREV<=0,H)
that works as a trailing stoploss should have the last H value. But i've no idea how to code this. I hope this makes sense..

ps. right now my chart only represents one buy signal followed by an immediate sell signal because the trailing stoploss looks for the first highestbar, so this is the bar next to the buysignal.
wabbit  
#4 Posted : Tuesday, October 10, 2006 2:49:18 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)

Raymond,

There are a number of ways to tackle my interpretation of your problem….

In pseudo code, this is one way:

Code:


If the current price is less than (entry
price + 20 pips)

 Use
a trailing exit of (something)

Else if the current price is more than (entry
price + 20 pips) but less than (entry price + 40 pips)

 Use
a different criteria for trailing stop

Else

 Use
another different criteria for trailing stop

 

e.g.

 

If(C<(If((C-0.002)>PREV,3.5,If((C-0.004)>PREV,3.0,2.5)*ATR(10))
then exit etc

This might be another way:
Code:


If the price has been above (entry price +
20 pips) at any time during this trade (regardless of the price now)

 Use
a trailing exit of (something)

Else

 Use
a different criteria for trailing stop

 

 

e.g.

 

If(BarsSince((H-0.002)>PREV)<BarsSince(PREV<=0)
AND C<(HighestSince(1,PREV<=0,H)*0.85) then exit etc

If you can annunciate what you are trying to achieve using this sort of pseudo code, then I will have a better understanding of what you are trying to achieve with your code. The codes are just examples, so they will not stand up by themselves, but you should get the idea of what I am trying to do…..

wabbit [:D]

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.