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

Notification

Icon
Error

Options
Go to last post Go to first unread
slipstream  
#1 Posted : Monday, April 30, 2012 5:30:51 AM(UTC)
slipstream

Rank: Member

Groups: Registered, Registered Users
Joined: 2/15/2010(UTC)
Posts: 14

Hi, I'm sure there's a simple solution to this one, but I can't seem to stumble across it!! How can I create an entry trigger that only occurs once when a condition is first met? I do not want to be notified of further entries once the trade is active. I understand that I can nominate level 0 trades only in my Metastock code, but I want to have indicators to create an expert advisor that only shows level 0 trades. Thanks.
jjstein  
#2 Posted : Monday, April 30, 2012 5:47:58 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)
First, set your signals to buy & sell:
Code:

Entry:={your code here};
Exit:={your code here};



Next, use this bit of "re-usable" code to do the trick:
Code:

{ 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 }


You can then use "Signal" for the entry & exit, or "Season" to tell when in or out of the trade.

slipstream  
#3 Posted : Monday, April 30, 2012 1:23:12 PM(UTC)
slipstream

Rank: Member

Groups: Registered, Registered Users
Joined: 2/15/2010(UTC)
Posts: 14

Thank you Jonathan. I'll give this a go in the coming days and let you know if I have any follow up questions. I really appreciate the detail you have provided. Cheers!
slipstream  
#4 Posted : Tuesday, May 1, 2012 12:26:37 AM(UTC)
slipstream

Rank: Member

Groups: Registered, Registered Users
Joined: 2/15/2010(UTC)
Posts: 14

OK, I generated the indicator and it works a treat. Great!! I haven't examined the code in detail, but I wonder if it is possible to modify slightly so that the value "season" can be increased by 1 every time a subsequent entry trigger occurs after the level 0 trade? I am trying to use this technique to lock in some profit on an open level 0 trade at a certain % and then reset the trade to the original size to limit my open trade exposure. Thanks again.
jjstein  
#5 Posted : Tuesday, May 1, 2012 10:15:47 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)
slipstream wrote:
I haven't examined the code in detail, but I wonder if it is possible to modify slightly so that the value "season" can be increased by 1 every time a subsequent entry trigger occurs after the level 0 trade?


"Season=1" means the trade is active. "Signal" is a buy or a sell.

Are you saying you want a running count of the signals that were filtered out?

slipstream  
#6 Posted : Thursday, May 3, 2012 2:10:55 AM(UTC)
slipstream

Rank: Member

Groups: Registered, Registered Users
Joined: 2/15/2010(UTC)
Posts: 14

Hi again, Basically the answer to your question is Yes! I need to track the overall trade duration which the "season" value does beautifully. I would also like to track subsequent signals once the trade is active. Thanks.
jjstein  
#7 Posted : Thursday, May 3, 2012 10:25:44 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)
This should do it:

Code:
Plot:=Input("Plot: 1=Signal 2=Count Entry",1,2,2);

{ 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:=Cross(MAlong,MAshort);

EntryEvent:=Entry; { 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 }

{ COUNT }
Count:=Cum(EntryEvent);
Counter:=Count-ValueWhen(1,Signal<0 OR Count=1,Count);

{ PLOT }
If(Plot=1,Signal,Counter);


jjstein  
#8 Posted : Thursday, May 3, 2012 11:17:55 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)
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))
));

slipstream  
#9 Posted : Thursday, May 17, 2012 3:21:18 PM(UTC)
slipstream

Rank: Member

Groups: Registered, Registered Users
Joined: 2/15/2010(UTC)
Posts: 14

Thank you so much for the great assistance you have given me. After a few cracks at my idea I have managed to get through it thanks to your input. Cheers! Slipstream
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.