Discussions
»
Product and Service Development
»
Formula Assistance
»
Code for sell on first profitable close or latest 5th day's close
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
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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().
|
|
|
|
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]
|
|
|
|
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...
|
|
|
|
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]
|
|
|
|
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?
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Unverified Users Joined: 6/9/2010(UTC) Posts: 17
|
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Discussions
»
Product and Service Development
»
Formula Assistance
»
Code for sell on first profitable close or latest 5th day's close
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.