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

Notification

Icon
Error

Options
Go to last post Go to first unread
Precisely  
#1 Posted : Wednesday, April 25, 2012 3:38:17 AM(UTC)
Precisely

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 6/9/2010(UTC)
Posts: 17

Hi Given a signal X how would I code sell on first profitable close or at the latest the 5th day's close? Really appreciate any help. BR
jjstein  
#2 Posted : Wednesday, April 25, 2012 11:05:40 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Precisely wrote:
Given a signal X how would I code sell on first profitable close or at the latest the 5th day's close?

Try this:
Code:

Entry:=sum(H>ref(h,-1),2)=2; { Signal "X" = 2 higher highs }
EntryPrice:=ValueWhen(1,ref(Entry,-1),OPEN); { Yesterday's signal, Today's Open }
Exit1:=Close>EntryPrice;
Exit2:=BarsSince(Entry)>=5;
Exit:=Exit1 or Exit2;

{ CLEAN - REMOVE REDUNDANT SIGNAL, +1=Buy -1=Sell }
Signal:=Cum(IsDefined(entry+exit))=1; { Enough data ? }
Signal:=ValueWhen(1,entry-exit<>0 OR Signal,entry); { Current }
entry:=Signal*(Alert(Signal=0,2) OR entry*Cum(entry)=1); { Current or 1st }
exit:=(Signal=0)*(Alert(Signal,2) OR exit*Cum(exit)=1); { Current or 1st }
entry:=(exit=0)*entry; { favor EXIT }
Signal:=Entry-Exit; { Signal }
Season:=ValueWhen(1,Signal<>0,Entry)*2-1; { Signal active }

{ Plot }
Signal;


Precisely  
#3 Posted : Wednesday, April 25, 2012 1:47:38 PM(UTC)
Precisely

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 6/9/2010(UTC)
Posts: 17

Many thanks Jjstein. Another newbie question though. How would I use this in the EST to test a system? I guess below is wrong? I want it to buy at closing the same day the signal is given. In EST: Buy Order Entry:= X; Sell Order Entry:= X; EntryPrice:=ValueWhen(1,ref(Entry,-1),open); Exit1:=Close>EntryPrice; Exit2:=BarsSince(Entry)>=5; Exit:=Exit1 or Exit2;
jjstein  
#4 Posted : Wednesday, April 25, 2012 5:50:43 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Hang on, that won't work -- a latch is needed to store price. Try this as an indicator:
Code:

Entry:=sum(H>ref(h,-1),2)=2; { Signal "X" }

Latch:=If(PREV=0, { no trade }
If(Entry,CLOSE,0), { store price }
If(CLOSE>PREV or BarsSince(PREV=0)>=5,0,PREV { reset }
));

Entry:=Alert(Latch,2)*(ref(Latch,-1)=0); { 1st entry }
Exit:=Alert(Latch,2)*(Latch=0); { 1st exit }

Signal:=Entry-Exit;

Signal;


For a test, either copy the formula and replace the last line with SIGNAL=+1 for Buy and SIGNAL=-1 for SELL. Or, you can use FML().

wabbit  
#5 Posted : Wednesday, April 25, 2012 8:47:18 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)
I don't have MS installed on this machine, but I'd be using the EST stops in lieu of complicated PREV based codes?

Code:

{Buy}
x:=h>ref(h,-1);
sum(x,2)=2;

{Profit stop}
0%

{Inactivity stop}
100%
5 periods



Give it a whirl and let us know how it goes.


wabbit [:D]

Precisely  
#6 Posted : Wednesday, April 25, 2012 11:38:49 PM(UTC)
Precisely

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 6/9/2010(UTC)
Posts: 17

Jjstein: Worked! Crappy system though... :) Greatful. Wabbit: Clever. Though seems to enter and exit on the same bar? While I have you in a thread. Been looking for a way to clean up EST signals from my templats. Is there a way? Know that I can chose not to plot them, but too late...
wabbit  
#7 Posted : Thursday, April 26, 2012 12:14:44 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)
Remove the profit target (leaving the inactivity stop as is) and add a SELL condition:

Code:

{Sell}
Simulation.CurrentProfit > 0;


The simulation function might not be called CurrentProfit, but it's something like; use the Function button in the formula editor to find the exact simulation function name.

What do you mean "clean up" the EST signals?



wabbit [:D]

Precisely  
#8 Posted : Thursday, April 26, 2012 11:22:48 AM(UTC)
Precisely

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 6/9/2010(UTC)
Posts: 17

Great. Will check that. Well, when I have run a simulation in EST and choose to plot the signals (plot to chart) I get a lot of labels of buy's and exits (of course), but how do I remove them? I don't want to remove the chart itself since I have a lot of support, resistance and trend lines there. Any ideas?
Precisely  
#9 Posted : Thursday, April 26, 2012 11:40:17 AM(UTC)
Precisely

Rank: Member

Groups: Registered, Registered Users, Unverified Users
Joined: 6/9/2010(UTC)
Posts: 17

Ah, "edit\delete all"...
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.