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

Notification

Icon
Error

Options
Go to last post Go to first unread
Wayne  
#1 Posted : Wednesday, August 17, 2005 3:03:25 AM(UTC)
Wayne

Rank: Member

Groups: Registered, Registered Users
Joined: 4/14/2005(UTC)
Posts: 11

In Enhance system tester Can anyone tell me the formular/fucntion to Sell after it is 10% below buying price(entry price)? Basically what is the function to sell base on entry price? Can someone pls get me an example?
bearishbull  
#2 Posted : Wednesday, August 17, 2005 6:10:51 AM(UTC)
bearishbull

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 6/30/2005(UTC)
Posts: 71

Wayne wrote:
In Enhance system tester Can anyone tell me the formular/fucntion to Sell after it is 10% below buying price(entry price)? Basically what is the function to sell base on entry price? Can someone pls get me an example?
entry:= {your entry} l < (highestsince( 1, entry, h) * (1/1.10)) something like this
Wayne  
#3 Posted : Wednesday, August 17, 2005 6:47:51 AM(UTC)
Wayne

Rank: Member

Groups: Registered, Registered Users
Joined: 4/14/2005(UTC)
Posts: 11

Thanks :D
bearishbull  
#4 Posted : Wednesday, August 17, 2005 8:12:33 AM(UTC)
bearishbull

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 6/30/2005(UTC)
Posts: 71

Wayne wrote:
Thanks :D
by the way, that was a 10% trailingstoploss..A normal stoploss of 10% should be l < (entry * (1/1.10)
Wayne  
#5 Posted : Thursday, August 18, 2005 10:39:12 AM(UTC)
Wayne

Rank: Member

Groups: Registered, Registered Users
Joined: 4/14/2005(UTC)
Posts: 11

entry:= whatever.....; L < entry * (1/1.10) .... does not work I think entry value is 1(true) so therefore for a stock that is $20 the 1 * 0.909 will almost always be below $20 the entry price. I am wrong??
bearishbull  
#6 Posted : Thursday, August 18, 2005 11:13:29 AM(UTC)
bearishbull

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 6/30/2005(UTC)
Posts: 71

Wayne wrote:
entry:= whatever.....; L < entry * (1/1.10) .... does not work I think entry value is 1(true) so therefore for a stock that is $20 the 1 * 0.909 will almost always be below $20 the entry price. I am wrong??
your absolutely right, my bad L < ValueWhen(1, entry, c) * (1/1.10) this should wor
mstt  
#7 Posted : Thursday, August 18, 2005 9:50:27 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Guys The problem with "L < ValueWhen(1, entry, c) * (1/1.10) " as a stop is that successive "entry" signals set a new stop price that's unrelated to the actual entry price. In some situations the above code might be sufficient, but if multiple entry signals are received while the trade remains active then it's going to fail. The original question was for a formula so I'm assuming you want to code the exit rather than use the "max loss" System Tester stop. To code an accurate stop you need to use the PREV function and base a latch around it such that the stop always references tha actual entry price, not the price of any subsequent entry signal. Even then there can be minor timing issues in certain situations. The underlying latch can act to store the actual entry price until reset to zero, and in that case the entry price is referenced within the latch reset code as PREV. Alternately, the latch might operate in pseudo or pure binary (by pseudo binary I mean it has states of 1, 0, or -1), and then the entry price is referenced within the latch with, for example, by ValueWhen(1,PREV=0,CLOSE). Instead of a PREV-based formula you may be able to use something like ValueWhen(1,Simulation.CurrentPositionAge=1,C) in the System Tester (or is it "=0"), but there appears to little advantage in using Simulation as it slows things down as much as PREV. A minimum of 2 PREVs is necessary (assuming you don't have access to a dll to perfom some of the tasks) in a latch formula to manage a stop based on the first entry signal. The first PREV ensures that the latch cannot accept a second entry (and price) until after it has reset (stop or normal exit); the second PREV monitors the latch for the stop condition, and resets it when the stop is activated. The PREV-based "R" variable in the following formula is a latch that monitors for both stop-loss and profit targets without adding a 3rd PREV. This is only possible when both exits are calculated on the CLOSE (don't ask why as it's difficult to explain). Setting the profit target to 999% would effectively disable the profit target and leave only the stop-loss operational. Obviously you'd have to remove the Input() functions befor this code could be used directly in the System Tester but it might be something you'd like to play with. The formula can have a number of outputs, and what output you use depends on what you want the code to do. {Trade Stop Lite} {2004 Roy Larsen, www.metastocktips.co.nz} No:=Input("Entry Price 1=O 2=C 3=H 4=L",1,4,1); Nd:=Input("Entry Delay",0,3,1); Xd:=Input(" Exit Delay",0,3,1); Pf:=1+Input("Profit Target %",1,999,40)/100; Lf:=1-Input("Stoploss %",1,99,4)/100; N:=Cross(Mov(WC(),10,E),Mov(WC(),30,E)); {Buy} X:=Cross(Mov(WC(),30,E),Mov(WC(),10,E)); {Sell} {* end of user area *} N:=N AND Alert(N=0,2); X:=X AND Alert(X=0,2); N:=ValueWhen(1+Nd,1,N); N:=If(N>0,If(No=1,O,If(No=3,H,If(No=4,L,C))),0); X:=ValueWhen(1+Xd,1,X); I:=Cum(N+X>-1)=1; M:=C<ValueWhen(2,1,C); R:=If(PREV<=0,N>0,If(X OR If(M,-1,1)*ValueWhen(1,PREV=0,N)<= If(M,-C/Lf,C/Pf),-1,1)); X:=R<0; R:=Abs(R)*ValueWhen(1,I+Alert(R=0,2)*R,N); { R; R*Pf; R*Lf; X*C; } X; Roy
Rogerio  
#8 Posted : Sunday, September 9, 2007 11:00:46 PM(UTC)
Rogerio

Rank: Newbie

Groups: Registered, Registered Users
Joined: 3/14/2007(UTC)
Posts: 9

Hello Roy,

I worked in this code for the weekend and I really had problem to make it work as I desired. I struggle with the Prev function. I want to update my entries and exits every time I had to stop either because I sold uncovered and price went up or I bought and price went down.

I could not add the Buy to cover function on it with a regular buy signal . Here is what I have done in the last part:

R:=If(PREV<=0,If(N>0,N>0,
ValueWhen(1,PREV=0,X)<= C*pf),
If(X OR
ValueWhen(1,PREV=0,N)>=
C*Lf,-1,1));

X:=R<0;

R:=Abs(R)*ValueWhen(1,I+Alert(R=0,2)*R,N);

Can you help with that ?

Thanks,

Rog

kassaindia  
#9 Posted : Monday, March 29, 2010 3:59:10 AM(UTC)
kassaindia

Rank: Newbie

Groups: Registered, Registered Users
Joined: 1/25/2010(UTC)
Posts: 2

Hello 1 could someone kindly help me code a stop loss and a tsl in the expert advisor. My problem is that after an ebtry if a stop loss gets executed it also executes a profit target and a TSL as and when that price is reached. This does not happen only when there comes a new entry after the first exit.
mstt wrote:
Hi Guys The problem with "L < ValueWhen(1, entry, c) * (1/1.10) " as a stop is that successive "entry" signals set a new stop price that's unrelated to the actual entry price. In some situations the above code might be sufficient, but if multiple entry signals are received while the trade remains active then it's going to fail. The original question was for a formula so I'm assuming you want to code the exit rather than use the "max loss" System Tester stop. To code an accurate stop you need to use the PREV function and base a latch around it such that the stop always references tha actual entry price, not the price of any subsequent entry signal. Even then there can be minor timing issues in certain situations. The underlying latch can act to store the actual entry price until reset to zero, and in that case the entry price is referenced within the latch reset code as PREV. Alternately, the latch might operate in pseudo or pure binary (by pseudo binary I mean it has states of 1, 0, or -1), and then the entry price is referenced within the latch with, for example, by ValueWhen(1,PREV=0,CLOSE). Instead of a PREV-based formula you may be able to use something like ValueWhen(1,Simulation.CurrentPositionAge=1,C) in the System Tester (or is it "=0"), but there appears to little advantage in using Simulation as it slows things down as much as PREV. A minimum of 2 PREVs is necessary (assuming you don't have access to a dll to perfom some of the tasks) in a latch formula to manage a stop based on the first entry signal. The first PREV ensures that the latch cannot accept a second entry (and price) until after it has reset (stop or normal exit); the second PREV monitors the latch for the stop condition, and resets it when the stop is activated. The PREV-based "R" variable in the following formula is a latch that monitors for both stop-loss and profit targets without adding a 3rd PREV. This is only possible when both exits are calculated on the CLOSE (don't ask why as it's difficult to explain). Setting the profit target to 999% would effectively disable the profit target and leave only the stop-loss operational. Obviously you'd have to remove the Input() functions befor this code could be used directly in the System Tester but it might be something you'd like to play with. The formula can have a number of outputs, and what output you use depends on what you want the code to do. {Trade Stop Lite} {2004 Roy Larsen, www.metastocktips.co.nz} No:=Input("Entry Price 1=O 2=C 3=H 4=L",1,4,1); Nd:=Input("Entry Delay",0,3,1); Xd:=Input(" Exit Delay",0,3,1); Pf:=1+Input("Profit Target %",1,999,40)/100; Lf:=1-Input("Stoploss %",1,99,4)/100; N:=Cross(Mov(WC(),10,E),Mov(WC(),30,E)); {Buy} X:=Cross(Mov(WC(),30,E),Mov(WC(),10,E)); {Sell} {* end of user area *} N:=N AND Alert(N=0,2); X:=X AND Alert(X=0,2); N:=ValueWhen(1+Nd,1,N); N:=If(N>0,If(No=1,O,If(No=3,H,If(No=4,L,C))),0); X:=ValueWhen(1+Xd,1,X); I:=Cum(N+X>-1)=1; M:=C<valueWhen(2,1,C); R:=If(PREV<=0,N>0,If(X OR If(M,-1,1)*ValueWhen(1,PREV=0,N)<= If(M,-C/Lf,C/Pf),-1,1)); X:=R<0; R:=Abs(R)*ValueWhen(1,I+Alert(R=0,2)*R,N); { R; R*Pf; R*Lf; X*C; } X; Roy
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.