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

Notification

Icon
Error

Options
Go to last post Go to first unread
dieselpr  
#1 Posted : Thursday, July 14, 2005 1:52:24 AM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

If this is the bases for a latch it only provides a latch for a buy and a buy exit. How would you encode a Buy,Sell with both exits for a total system? Because you have now two set signal and 2 reset signal? I hope I explained this right. Any ideas? {Example 2} N:=Fml("set signal"); X:=Fml("reset signal"); I:=Cum(N+X>-1)=1; Tr:=BarsSince(I OR N)<BarsSince(I OR X); Tr;
wabbit  
#2 Posted : Thursday, July 14, 2005 6:23:51 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)
dieselpr wrote:
If this is the bases for a latch it only provides a latch for a buy and a buy exit.
This is a buy and sell system e.g. {Moving average crossover system} a:=Mov(C,13,S) > Mov(C,21,S); N:=a AND Ref(a=0,2); X:=a=0 AND Ref(a=1,2); I:=Cum(N+X>-1)=1; Tr:=BarsSince(I OR N)<BarsSince(I OR X); Tr; Do you mean a complete system, Enter Long, Exit Long, Enter Short, Exit Short?? wabbit :D
dieselpr  
#3 Posted : Thursday, July 14, 2005 11:28:12 AM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Yes wabbit, My problem is when my buy signal is true the sell signal will become true before the buy signal has gotten to exit. I was tring to see if Roy had designed a complete Buy & Sell system that prevents a sell signal before the buy has gotten to exits.
wabbit  
#4 Posted : Thursday, July 14, 2005 12:28:10 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)
dieselpr, Quite often I see this happen when you have code where it is possible to be long and short simultaneously. Personally I dont like this situation, but if you trade like this then... ok. What you need to do is to is code the Long Entry and Long Exit in one latching code section, and the Short Entry and Short Exit in another section. When you combine the sections, you should end up with an indicator that has values: 2 when long 1 when long entered first, then short entry 0 when out of all trades -1 when short short entered first, then long entry -2 when short To make this happen, test to see if any trades are open, and if so, are they long or short? If no trades are open, the first trade opened is multiplied by 2. If a subsequent trade is opened, a value of 1 is subtracted/added. If this are not the results you are looking for, please provide a detailed example, and maybe your conditions and I will try to code them up for you. Hope this helps. wabbit :D
dieselpr  
#5 Posted : Thursday, July 14, 2005 12:56:23 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

pds:=2; XAT:=2; {Zero Lag MA} EMA8:=Mov(2*(Mov(C,8/2,W))-Mov(C,8,W),2,W); EMA17:=Mov(2*(Mov(C,17/2,W))-Mov(C,17,W),4,W); {Entry Signals} MACBuy:=If((EMA8-EMA17)>Mov((EMA8-EMA17),9,E) AND Alert((EMA8-EMA17)<Mov((EMA8-EMA17),9,E),pds),1,0); MACSell:=If((EMA8-EMA17)<Mov((EMA8-EMA17),9,E) AND Alert((EMA8-EMA17)>Mov((EMA8-EMA17),9,E),pds),-1,0); {Buy & Sell Exit Alerts} LE:=HHV(H - XAT*ATR(5),10);{For Long} SE:=LLV(L + (XAT*2)*ATR(5),10);{For Short} MACBuyExit:=If(L<LE AND Alert(L>LE,pds) OR L<HHV(H - (XAT*2)*ATR(5),10) AND Alert(L>HHV(H - (XAT*2)*ATR(5),10),pds),-1,0); MACSellExit:=If(H>SE AND Alert(H<SE,pds) OR H>LLV(L + (XAT*2)*ATR(5),10) AND Alert(H<LLV(L + (XAT*2)*ATR(5),10),pds),1,0); What I want this formula to do is enter either buy or short and not give another signal until either the buy has been exited or the sell has been exited. example- I get a buy alert, at this point I want to enter the trade but at the same time I now want to completely turn off my Sell and sell exit alert or make them both false until I get a buy exit alert. After I get a buy exit alert I then want both long and short to be active or true so that either one can take a trade. I only want to take 1 trade at a time once I'm in that trade I want the other signals to be turned off until the exit has been given. I tried Roy latch in several different ways but it only works on one side of the system not both sides.
dieselpr  
#6 Posted : Thursday, July 14, 2005 1:03:12 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Wabbit, This is what I came up with on the latch design into the system but it still allow for more then one trade at a time before an exit. pds:=2; XAT:=2; {Zero Lag MA} EMA8:=Mov(2*(Mov(C,8/2,W))-Mov(C,8,W),2,W); EMA17:=Mov(2*(Mov(C,17/2,W))-Mov(C,17,W),4,W); {Entry Signals} MACBuy:=If((EMA8-EMA17)>Mov((EMA8-EMA17),9,E) AND Alert((EMA8-EMA17)<Mov((EMA8-EMA17),9,E),pds),1,0); MACSell:=If((EMA8-EMA17)<Mov((EMA8-EMA17),9,E) AND Alert((EMA8-EMA17)>Mov((EMA8-EMA17),9,E),pds),-1,0); {Buy & Sell Exit Alerts} LE:=HHV(H - XAT*ATR(5),10);{For Long} SE:=LLV(L + (XAT*2)*ATR(5),10);{For Short} MACBuyExit:=If(L<LE AND Alert(L>LE,pds) OR L<HHV(H - (XAT*2)*ATR(5),10) AND Alert(L>HHV(H - (XAT*2)*ATR(5),10),pds),-1,0); MACSellExit:=If(H>SE AND Alert(H<SE,pds) OR H>LLV(L + (XAT*2)*ATR(5),10) AND Alert(H<LLV(L + (XAT*2)*ATR(5),10),pds),1,0); {Buy & sell latchs-turning On & Off} IBuy:=Cum(MACBuy+MACBuyExit>-1)=1; ISell:=Cum(MACSell+MACSellExit>-1)=1; BuyEnterExits:=BarsSince(IBuy OR MACBuy=1)<BarsSince(IBuy OR MACBuyExit=-1); SellEnterExits:=BarsSince(ISell OR MACSell=-1)<BarsSince(ISell OR MACSellExit=1); {Formula} Buy:=If(BuyEnterExits=BuyEnterExits AND Alert(BuyEnterExits=0,pds) AND SellEnterExits=0,1,0); Sell:=If(SellEnterExits=SellEnterExits AND Alert(SellEnterExits=0,pds) AND BuyEnterExits=0,-1,0); BuyExits:=If(BuyEnterExits=0 AND Alert(BuyEnterExits=1,pds),-2,0); SellExits:=If(SellEnterExits=0 AND Alert(SellEnterExits=SellEnterExits,pds),2,0); Buy+Sell+BuyExits+SellExits
dieselpr  
#7 Posted : Thursday, July 14, 2005 1:15:46 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

The exit latch condition are wrong I forgot I switch testing something else last night. They should be set as followed with a 2 not a 1 MACBuyExit:=If(L<LE AND Alert(L>LE,pds) OR L<HHV(H - (XAT*2)*ATR(5),10) AND Alert(L>HHV(H - (XAT*2)*ATR(5),10),pds),-2,0); MACSellExit:=If(H>SE AND Alert(H<SE,pds) OR H>LLV(L + (XAT*2)*ATR(5),10) AND Alert(H<LLV(L + (XAT*2)*ATR(5),10),pds),2,0);
wabbit  
#8 Posted : Thursday, July 14, 2005 2:18:05 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)
If I have interpreted what you are trying to do correctly then hopefully this code will suit your purpose: --8<------------------------ pds:=2; XAT:=2; {0-Trade Short before Long} {1-Trade Long before short} bias:=0; {Zero Lag MA} EMA8:=Mov(2*(Mov(C,8/2,W))-Mov(C,8,W),2,W); EMA17:=Mov(2*(Mov(C,17/2,W))-Mov(C,17,W),4,W); myMACD:=EMA8-EMA17; myTrigger:=Mov(myMACD,9,E); {Buy & Sell Exit Alerts} LE:=HHV(H - XAT*ATR(5),10);{For Long} SE:=LLV(L + (XAT*2)*ATR(5),10);{For Short} {Long Trades Section} nLong:=myMACD>myTrigger AND Alert(myMACD<myTrigger,pds); xLong:=(L<LE AND Alert(L>LE,pds)) OR (L<HHV(H - (XAT*2)*ATR(5),10) AND Alert(L>HHV(H - (XAT*2)*ATR(5),10),pds)); I:=Cum(nLong+xLong>-1)=1; Long:=BarsSince(I OR nLong)<BarsSince(I OR xLong); {Short Trades Section} nShort:=myMACD<myTrigger AND Alert(myMACD>myTrigger,pds); xShort:=(H>SE AND Alert(H<SE,pds)) OR (H>LLV(L + (XAT*2)*ATR(5),10) AND Alert(H<LLV(L + (XAT*2)*ATR(5),10),pds)); I:=Cum(nShort+xShort>-1)=1; Short:=BarsSince(I OR nShort)<BarsSince(I OR xShort); {plot as line} 0; {plot as histograms} Long; -Short; {Actual Trade Open - plot as heavy line} If(bias=1,If(Long=1,1,long-short),If(Short=1,-1,long-short)) --8<----------------------------------- I have taken some liberties with your code that will hopefully make it a bit easier to read and manipulate. Firstly, the judicious use of variables will speed up your code and make it easier to read, understand and debug. Secondly, I was able to solve the problem by breaking it into the two sections for long and short trading, then combining the two at the end. As you are only going to be long OR short, then you need to set a priority; you will either trade long in prefernce to short, OR, you will trade short in preference to long. This indication is set with the bias value. Hope this helps. wabbit :D Two pictures of the same stock: the heavy line is the current trade, +1 is long, -1 is short, 0 is out
Patrick  
#9 Posted : Thursday, July 14, 2005 2:26:39 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)
Have you guys looked at this post? Might be helpful ... http://forum.equis.com/viewtopic.php?t=1116 Patrick :mrgreen:
wabbit  
#10 Posted : Thursday, July 14, 2005 2:33:50 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)
If I was reading the code in that discussion correctly (I probably wasnt 'caus eI am very tired atm) it looked like there was the possibility to have long and short trades open at the same time? Diesel was looking to avoid that situation, I think???? Now, I am just confused! :-k wabbit :D :smt015
Patrick  
#11 Posted : Thursday, July 14, 2005 2:36:28 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)
No it was the exact same request ... :D
dieselpr  
#12 Posted : Thursday, July 14, 2005 5:08:29 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Patrick, I read that post last night but I ran away from it because it used the prev function which for Intraday trading the way I want to trade would be very foolish. I was looking for speed because I am trading on a 5 min chart. Wabbit has the correct idea I wanted to either be long or short not both. I'll take a look at the code more later tonight when I'm sitting in front of metastock Thanks Wabbit.
dieselpr  
#13 Posted : Thursday, July 14, 2005 5:43:01 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Wabbit, I reworked a few lines of the code but I'm not sitting in front of metastock right now. I reworked this part because I was confused about how the alerts would come. I wanted to ref when the latch came on and when it went off. {Actual Trade Open - plot as heavy line} Switch:=If(bias=1,If(Long=1,1,long-short),If(Short=1,-1,long-short)); Buy:=If(Switch=1 AND Ref(Switch=0,-1),1,0); Sell:=If(Switch=-1 AND Ref(Switch=0,-1),-1,0); BuyExit:=If(Switch=0 AND Ref(Switch=1,-1),-2,0); SellExit:=If(Switch=0 AND Ref(Switch=-1,-1),2,0); Buy+Sell+BuyExit+SellExit; {0-Trade Short before Long OR 1-Trade Long before short} bias:=1; I also hard encode my pds:=2; XAT:=2; because I saw we where pushing the 20 var limit but is this a correct ref to your code or did I miss something? I'm pretty new at this encoding stuff.
Patrick  
#14 Posted : Thursday, July 14, 2005 5:53:05 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)
Quote:
I wanted to either be long or short not both
That's what the code iI refered to does. If you guys find the way to do this without the prev function and so that it can be used as an expert properly, let me know ... Patrick :mrgreen:
dieselpr  
#15 Posted : Thursday, July 14, 2005 11:17:09 PM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Wabbit, The full system latch design on a scale from 1 to 10 had to be at least a 80 plus!!! Thanks for the help. Your design work great with the expert codes below. The entry need some work but my major problem was that dog gone latch and its solved now. Thanks for help Experts Buy Fml("Formula")=1 AND Ref(Fml("Formula")=0,-1) OR Ref(Fml("Formula")=1 AND Ref(Fml("Formula")=-1,-1),-1) Sell Fml("Formula")=-1 AND Ref(Fml("Formula")=0,-1) OR Ref(Fml("Formula")=-1 AND Ref(Fml("Formula")=1,-1),-1) Buy Exit Fml("Formula")=0 AND Ref(Fml("Formula")=1,-1) OR Fml("Formula")=-1 AND Ref(Fml("Formula")=1,-1) Sell Exit Fml("Formula")=0 AND Ref(Fml("Formula")=-1,-1) OR Fml("Formula")=1 AND Ref(Fml("Formula")=-1,-1)
dieselpr  
#16 Posted : Friday, July 15, 2005 12:14:41 AM(UTC)
dieselpr

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/27/2005(UTC)
Posts: 130

Wabbit, Do you know if there is a better profit stop that doesn't use the prev function that I might use?
wabbit  
#17 Posted : Saturday, July 16, 2005 2:33:29 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)
Have you had a look at Richard Dale's excellent trailing stops functions? See: http://www.tradernexus.c...edstop/advancedstop.html Their server seems to be down at the moment?? wabbit :D
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.