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)
|
jjstein wrote:This should do it: OR NOT! Just realized that it misses the first trade. Here's a correction, with a count of Exits as well: Code:Plot:=Input("Plot: 1=Signal 2=Count Entry 3=Count Exit",1,3,1);
{ BUY & SELL CONDITIONS -- YOUR CODE HERE! }
MAshort:=Mov(C,5,S);
MAlong:=Mov(C,21,S);
Entry:=Sum(H>Ref(H,-1),3)=3;
Exit:=Sum(L<Ref(L,-1),3)=3;
EntryEvent:=Entry; { Store unfiltered signal }
ExitEvent:=Exit; { Store unfiltered signal }
{ REMOVE EXTRA SIGNALS, +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 }
If(Plot=1,Signal,if(Plot=2,
Cum(EntryEvent)-ValueWhen(1,Cum(EntryEvent)=0 OR Signal<0,Cum(EntryEvent)),
Cum(ExitEvent)-ValueWhen(1,Cum(ExitEvent)=0 OR Signal>0,Cum(ExitEvent))
));
|