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

Notification

Icon
Error

Options
Go to last post Go to first unread
Mark Hartshorne  
#1 Posted : Monday, November 21, 2005 4:55:46 PM(UTC)
Mark Hartshorne

Rank: Newbie

Groups: Registered, Registered Users
Joined: 11/21/2005(UTC)
Posts: 2
Location: Bahrain

I have has MS for just over a week now and am discovering how to develop my systems but I am having trouble understanding how I can store the (unit) price that the stock was bought for so that I can use it to base some of my sell activity on. For example, if the stock was bought for $10 (based on the buy entry conditions) and the sell conditions wanted to sell at a 67% retracement back up toward the stocks last highest high. How do I capture and maintain the value of the stock at the time of purchase ($10)? I have read about 'latches' etc. but am still quite confused! Any help would be appreciated, thank you.
Patrick  
#2 Posted : Monday, November 21, 2005 4:59:52 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)
Unfortunateky it depends on your system but I would suggest you read about the Valuewhen function. For example here is a logic that could work: BC:={BUY CONDITION}; PriceBought:=ValueWhen(1,BC,Close); PriceBought Patrick :mrgreen:
mstt  
#3 Posted : Monday, November 21, 2005 8:07:12 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Mark You will need the PREV function if your trades are more than a few bars long. A PREV-based latch will allow you to reference the entry bar regardless of how many secondary signals have occured since the original entry. ValueWhen() can be used in conjunction with PREV to reference almost any value relating to the original buy signal. Patrick's ForumDll has a "latch" function that's useful for holding a logical TRUE or FALSE, "remembering" set and reset signals, but it cannot operate with resets (sells) that relate to the set (buy) in any way. Discrete MS formula language simple latches (unrelated exit latches) have the same limitation. If the exit is entry-dependant in some way then you have little choice but to use a PREV-based formula (probably in the form of a latch as set out below). In theory the Simulation functions in the Enhanced System Tester should allow the same sort of control as PREV. In practice the Simulation fuctions are not that easy to work with and not well documented. While PREV code looks ugly and uses a lot of resources, it's probably still the best way to manage entry-dependant exits. {Sample PREV-based trade latch} N:= Ref(Cross(Mov(C,7,E),Mov(C,15,E)),-1); {buy} A:= ATR(10); X:= 0; {independant sell if used} Np:=OPEN; {buy price} Tr:=If(PREV<=0,N, {set condition} {reset conditions} If(X {independant sell} OR {dependant sell condition 1 - profit target} H>ValueWhen(1,PREV<=0,Np+5*A) OR {dependant sell condition 2 - stoploss} L<ValueWhen(1,PREV<=0,Np-2.5*A),-1,1)); {reconstructed internal latch activity and prices} Entry:=Tr AND ValueWhen(2,1,Tr)<=0; Exit:=Tr<0; Trade:= Abs(Tr); I:=Cum(Tr>-2)=1; EntryPrice:=ValueWhen(1,I+Entry,Np); ProfitTarget:=ValueWhen(1,I+Entry,Np+5*A); LossTarget:=ValueWhen(1,I+Entry,Np-2.5*A); {Trade*EntryPrice;} {plots entry price} {Trade*ProfitTarget;} {plots profit target} {Trade*LossTarget;} {plots stoploss} Exit; Roy MetaStock Tips & Tools
Mark Hartshorne  
#4 Posted : Monday, November 21, 2005 8:23:17 PM(UTC)
Mark Hartshorne

Rank: Newbie

Groups: Registered, Registered Users
Joined: 11/21/2005(UTC)
Posts: 2
Location: Bahrain

I have tried the PriceBought illustration and it appears to work OK (MS v9.1). This is the SELL code. BC:= CLOSE > 20 AND CLOSE <= LLV(C,opt1) AND V > Mov(V,opt2,S); PriceBought:=ValueWhen(1,BC,Close); CLOSE >= PriceBought + ((HHV(C,opt3) - PriceBought) * 0.67) Is there anything inherently wrong or is it accurately reporting what I want it to?
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.