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

Notification

Icon
Error

Options
Go to last post Go to first unread
CN001532  
#1 Posted : Sunday, September 18, 2005 12:53:40 PM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

I have a complex indicator that triggers a buy signal +1 some time in the past based on the CCI(14). But my exit rules are fairly simple: If there are two consecutive closes down in the CCI(14) and the current price bar is a black candle then I exit the trade: Black() AND CCI(14)< Ref(CCI(14),-1) AND Ref(CCI(14),-1)<Ref(CCI(14),-2) The problem that I have is that I would only like this exit condition to pop-up after the buy trigger has occurred in the past, instead of every time the exit rules are true. Using the ValueWhen function only allows me to create an exit for the most recent buy signal. I also tried assigning a variable n to the valuewhen function: Valuewhen( n, complex buy function, CCI(14)) - however this function only allows a constant and not a variable. The following code gives me the value of the CCI(14) everytime a buy signal has been triggered. Where (Fml( "//\\\\ CCI ZLR Buy w/34 ema") is the complex buy indicator. n:=If(Fml( "//\\\\ CCI ZLR Buy w/34 ema")=1, CCI(14),0); n Either I'm missing something really simple or this is really something difficult to do.
Jose  
#2 Posted : Sunday, September 18, 2005 3:31:37 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
It sounds to me like you need some of that latch code found at MetaStockTools.com. ;) Try this: [code:1:5a2a999022] ==================== System trade signals ==================== ---8<-------------------------- { System trade signals v2.5 } { ©Copyright 2005 Jose Silva } { For personal use only } { http://www.metastocktools.com } { Note on simultaneous entry/exit on same bar: #1 Ignore: entry/exit signals cancel each other; #2 Preference given to: new entry if currently Short, new exit if currently Long.} { Signals reference example } entry:=White() AND Sum(CCI(14)>Ref(CCI(14),-1),2)=2 AND CCI(14)<100; exit:=Black() AND Sum(CCI(14)<Ref(CCI(14),-1),2)=2; { User inputs } plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1); choose:=Input("Simultaneous entry/exit: [1]Ignore, [2]Preference",1,2,2); delay:=Input("Entry and Exit delay",-1,5,0); { Initialize } Init:=Cum(IsDefined(entry+exit))=1; { #1 - Ignore entry/exit on same bar } bin1:=ValueWhen(1,entry-exit<>0 OR Init, entry-exit); long:=bin1=1 AND (Alert(bin1<>1,2) OR Init); short:=bin1=-1 AND (Alert(bin1<>-1,2) OR Init); signals1:=long-short; { #2 - Preference to first entry/exit } long:=entry AND (Alert(entry=0,2) OR Init); short:=exit AND (Alert(exit=0,2) OR Init); bin2:=ValueWhen(1,long-short<>0 OR Init, long-short); long:=bin2=1 AND (Alert(bin2<1,2) OR Init); short:=bin2=-1 AND (Alert(bin2>-1,2) OR Init); signals2:=long-short; { Select #1 or #2 } binary:=If(choose=1,bin1,bin2); signals:=If(choose=1,signals1,signals2); { Plot in own window } Ref(If(plot=2,entry,0),-delay); Ref(If(plot=1,signals, If(plot=2,-exit,binary)),-delay) ---8<-------------------------- [/code:1:5a2a999022] Jose '-) http://www.metastocktools.com
Patrick  
#3 Posted : Sunday, September 18, 2005 3:32:08 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Take a look at the Formula Trainig video 4 and / or download the forum dll and use the Latch function. Patrick :mrgreen:
CN001532  
#4 Posted : Sunday, September 18, 2005 4:46:13 PM(UTC)
CN001532

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 8/22/2005(UTC)
Posts: 30

I think I answered my own question, I'm curious if there is a simpler solution though =============================== System trade signals - original =============================== ---8<-------------------------- { Original trade signals code } { BarsSince() function prevents first exit plot} { With thanks to Roy Larsen at http://www.metastocktips.co.nz } { Signals reference example } entry:=C>Mov(C,21,E); exit:=C<Mov(C,10,E); { User inputs } plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1); delay:=Input("Entry and Exit delay",-1,5,0); { Clean signals } Init:=Cum(entry+exit>-1)=1; entryInit:=Cum(entry)=1; flag:=BarsSince(Init OR entry) <BarsSince(Init OR exit)+entryInit; signals:=(entryInit AND Alert(entryInit=0,2) OR flag AND Alert(flag=0,2)) -(flag=0 AND Alert(flag,2)); binary:=ValueWhen(1,signals<>0,signals); { Plot in own window } Ref(If(plot=1,signals, If(plot=2,entry-exit,binary)),-delay) ---8<--------------------------
Jose  
#5 Posted : Monday, September 19, 2005 6:29:10 AM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
CN001532 wrote:
I think I answered my own question, I'm curious if there is a simpler solution though
You are staring at the solution, but you've seemed to have missed it all together. ;) jose '-)
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.