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

Notification

Icon
Error

Options
Go to last post Go to first unread
SKLiF  
#1 Posted : Wednesday, December 14, 2005 6:49:21 AM(UTC)
SKLiF

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2005(UTC)
Posts: 2

Just intro :) Here is some code to enter Long, it is also detecting that it IS in Long, so not to enter when the signal is repeating. --LONG-- Long1:= Long terms; Close1:=Close Long terms; Z:=BarsSince(Long1)<BarsSince(Close1); Z1:=BarsSince(Long1)>BarsSince(Close1); Z=1 AND Ref(Z1,-1)=1 Ok now imagine that you whant to place a stop loss depending on enter price :) Something like Low of the entering candle, or Low-X So as soon as you try to do it, the formula will get in circle :( something like this Long1:= Long terms; Close1:=[color=green:57673acb17]cross(P,ValueWhen(1,Long1,L)) [/color]; Z:=BarsSince(Long1)<BarsSince(Close1); Z1:=BarsSince(Long1)>BarsSince(Close1); Z=1 AND Ref(Z1,-1)=1 And here is picture for help :) http://forum.sysadmins.ru/adv/show.gif UserPostedImage All entering trigers (L1,L1b,L1c) are the same, but if i whant to exit on stop loss S1 i can use something like the code from above but alittle changed Close1:=[color=green:57673acb17]cross(L,ValueWhen(1,Long1,L-X)); [/color] But as we move to S1 :D we pass L1b and stoploss changes to S1b :( etc ... So the question is - how not to loose S1 price? :( :D thank you beforehand !
mstt  
#2 Posted : Wednesday, December 14, 2005 9:56:43 AM(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)
SKLiF The short answer to your question is that you need to use a PREV-based latch, or use an appropriate Simulation function to create same. Without resorting to these functions you cannot accurately program an exit that is dependant on some entry parameter. Giving instructions on how to do this is not just a simple matter of trotting out a couple of lines of code. Roy MetaStock Tips & Tools
SKLiF  
#3 Posted : Wednesday, December 14, 2005 10:32:43 AM(UTC)
SKLiF

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2005(UTC)
Posts: 2

mabe some Example mstt? :) just to know where to dig... i tried Prev function but maybe not the way you meen? :(
Jose  
#4 Posted : Wednesday, December 14, 2005 12:17:56 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)
Below is an example of a Prev-based latch that references the entry signal: [code:1:e15caf7f1f] ======================= EntryPrice related exit ======================= ---8<------------------------------ { EntryPrice reference, stoploss code example for use in EntryPrice-related exit } { http://www.metastocktools.com } { User inputs } x:=Input("EntryPrice: [1]Open, [2]High, [3]Low, [4]Close",1,4,3); plot:=Input("[1]true EntryPrice, [2]System signals",1,2,1); Stoploss:=1-Input("StopLoss %",0,100,4)/100; { Sample system Entry & Exit signals } entry:=Cross(C,Mov(C,21,E)); exit:=Cross(Mov(C,10,E),C); { Reference Open/High/Low/Close choice } prc:=If(x=1,O,If(x=2,H,If(x=3,L,C))); { Reference system entry price, and apply to exit as a stoploss } trade:=If(PREV=0,If(entry,prc,0), If(exit OR C<PREV*Stoploss,0,PREV)); { New entry signal } NuEntry:=trade>0 AND Alert(trade=0,2); { New exit signal } NuExit:=trade=0 AND Alert(trade>0,2); { True entry price } EntryPrice:=ValueWhen(1,NuEntry,prc); { Plot on price chart } If(plot=1,EntryPrice,NuEntry-NuExit) ---8<------------------------------ [/code:1:e15caf7f1f] jose '-)
hyperdimension  
#5 Posted : Monday, December 19, 2005 2:17:24 PM(UTC)
hyperdimension

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2005(UTC)
Posts: 7

How would you do this for a Tradesim exploration? Is it possible to retrieve the value of the entry price variable from Tradesim.RecordTrades? It would be perfect if it was possible but I can't find any information on it. Or would something like Jose's code above have to be used (with some slight changes for use with Tradesim)? All we require is the actual original entry price during a particular open trade, so that we can use it for calculations e.g. to set a stop that is related to the original entry price. I would never have thought it would be so difficult! Please help!
Jose  
#6 Posted : Monday, December 19, 2005 3:16:44 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)
You can reference the above formula's EntryPrice in any MetaStock process, including TradeSim Explorations: entryPrice:=FmlVar("EntryPrice related exit","ENTRYPRICE"); To set a stop properly based on the EntryPrice, you will need to do it as per the formula above - after all, that was the whole point of it. { Reference system entry price, and apply to exit as a stoploss } jose '-)
hyperdimension  
#7 Posted : Friday, December 23, 2005 1:59:20 PM(UTC)
hyperdimension

Rank: Newbie

Groups: Registered, Registered Users
Joined: 12/19/2005(UTC)
Posts: 7

Thanks for the help Jose. What I was instead thinking of was simply being able to retrieve the value of the actual entry price from the Tradesim.RecordTrades function. After all, ReccordTrades obviously does store it, along with the values of initial stop, exit price, and entry and exit trigger conditions. Is it possible to access the values of these variables directly from Tradesim.RecordTrades, instead of having to go through a roundabout way as above? Thanks again for your help Jose.
Jose  
#8 Posted : Friday, December 23, 2005 3:47:02 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)
Anything is possible, provided that enough resources are applied to the task. MetaStock cannot access external data directly. However, if you can export the TradeSim trade database as a text csv file, there are custom solutions available. 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.