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

Notification

Icon
Error

Options
Go to last post Go to first unread
bikhod  
#1 Posted : Monday, June 19, 2006 2:45:35 PM(UTC)
bikhod

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 30

Hi Not being very good at the Metstock formula language, I am having problems writing the following function: I want to work out the % difference in closing price between two points on the charts. The entry point is when the close crossed above the Bollinger Band one standard deviation and the exit point is when the closing price closed below the Bollinger Band one standard deviation. In other words, I want to get an idea of the % gain (or loss) on each trade if I were to follow this system. I know how to write the individual bits (e.g. close above BB 1 SD etc) but what I don't know is how to link two separate events (entry and exit) together. Is this possible with Metastock?
wabbit  
#2 Posted : Tuesday, June 20, 2006 12:12:07 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)
If you get the free forum.dll, it contains a latch function where you specify your entry and exit criteria. Combined with the ValueWhen() function, you should be able to achieve your goal. Have you tried using the system tester? Or what about Roy Larsen's Trade Equity package, available free from his website: http://www.metastocktips.co.nz/ wabbit :D
mstt  
#3 Posted : Tuesday, June 20, 2006 12:20:19 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)
Bikhod Yes this is possible in MetaStock, and it could be done in a number of ways. I'd suggest you use a latch (The Forum dll Latch function would be fine) and set it with entry, and with the exit being the reset signal. This will give a binary TRUE result while your trade is active. The advantage of using a latch is that you can then ignore all but the first entry signal which is your reference point. The following formula will give the changing % gain as your trade progresses and hold the final value through until the next trade begins. You will need to define "N" and "X" for this to work. {N:=Fml("my entry signal"); X:=Fml("my exit signal");} Tr:=ExtFml("Forum.Latch",N,X,0,0); Nbar:=Tr AND Alert(Tr=0,2); Nprice:=ValueWhen(1,Nbar,CLOSE); Xprice:=ValueWhen(1,Tr,CLOSE); 100*(Xprice-Nprice)/Nprice; There are other approaches you could use too, such as plugging your trade signals into a Trade Equity formula - follow the link below and go to "Trade Equity" pages. Roy MetaStock Tips & Tools
mstt  
#4 Posted : Tuesday, June 20, 2006 12:23:59 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)
Bikhod I forgot to remove the braces from the forst two lines of my formula after I tested it with my own entry and exit signals. Sorry. N:=Fml("my entry signal"); X:=Fml("my exit signal"); Tr:=ExtFml("Forum.Latch",N,X,0,0); Nbar:=Tr AND Alert(Tr=0,2); Nprice:=ValueWhen(1,Nbar,CLOSE); Xprice:=ValueWhen(1,Tr,CLOSE); 100*(Xprice-Nprice)/Nprice; Roy MetaStock Tips & Tools
bikhod  
#5 Posted : Friday, June 23, 2006 10:58:51 PM(UTC)
bikhod

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 30

Thanks for the information guys. I will get hold of the DLL and try it over the weekend. I did try the system tester, but it seems to be buying and selling at the wrong times. I clicked the plot button and looked at the trade entry/exit symbols - it missed a number of very good trades. I'll let you guys know how I get on with the latch approach...
Jose  
#6 Posted : Saturday, June 24, 2006 4:23:49 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)
From MetaStockTools.com:
Quote:
Combined Bollinger Band breakout signals & profit curve indicator Plot this indicator three times on: 1) Price chart - with [4]BBands option; 2) Own window below price chart - [1] Clean signals option; 3) Own window below - [3] %Profit option. This indicator uses a simplified version of the risk-normalized profit Long & Short indicators available with the URSC & MACDH Divergence kits. These proprietary profit indicators can be a powerful part of any system development. They include risk normalization parameters, which allow rapid and valid comparisons between systems with markedly different risk profiles. They also include a Buy & Hold option and an annualized %pa function, for comparing a system's performance to a risk-normalized benchmark. MetaStock -> Tools -> Indicator Builder -> New -> Copy and paste complete formula between "---8<---" lines.
UserPostedImage [code:1:5263c1ed3e] =================================== Bollinger breakout signals & profit =================================== ---8<----------------------------------------- { SMA Bollinger Band breakout signals & profit % curve. ©Copyright 2004~2006 Jose Silva. The grant of this license is for personal use only - no resale or repackaging allowed. All code remains the property of Jose Silva. http://www.metastocktools.com } { User inputs } dev:=Input("BB Std Dev",.001,10,1); pds:=Input("BB periods",2,252,21); swap:=Input("Swap BB top/bot for signals? [0]No, [1]Yes",0,1,0); cost:=Input("Total Transaction costs (Brokerage + Slippage) %:",0,100,.2)/200; plot:=Input("Signals: [1]Clean, [2]All, [3]%Profit, [4]BBands",1,4,1); { Bollinger Bands } BBtop:=BBandTop(C,pds,S,dev); BBbot:=BBandBot(C,pds,S,dev); { BB signals } entry:=If(swap,Cross(C,BBtop),Cross(C,BBbot)); exit:=If(swap,Cross(BBbot,C),Cross(BBtop,C)); allSignals:=entry-exit; { Profit Long % - fixed trade size - v2.2 Basic code - Entry/Exit on Close of signal } { Trade Binary & clean Entry/Exit signals } init:=Cum(IsDefined(entry+exit))=1; flag:=ValueWhen(1,entry-exit<>0 OR init,entry); entry:=flag*(Alert(flag=0,2) OR entry*Cum(entry)=1); exit:=(flag=0)*(Alert(flag,2) OR exit*Cum(exit)=1); signals:=entry-exit; { Profit % curve } EntryVal:=ValueWhen(1,entry,C*(1+cost)); Profit:=C*(1-cost)/EntryVal-1; ProfitPer:=(flag*Profit+Cum(exit*Profit))*100; { Plot signals in own window } If(plot=1,signals,If(plot=2,allSignals, If(plot=3,ProfitPer,BBtop))); If(plot=1,signals,If(plot=2,allSignals, If(plot=3,ProfitPer,BBbot))) ---8<----------------------------------------- [/code:1:5263c1ed3e] jose '-)
Users browsing this topic
Guest (Hidden)
Similar Topics
Is this Possible to Code? (Formula Assistance)
by GameTime 9/11/2011 5:18:50 AM(UTC)
Is this possible ? (Formula Assistance)
by perfecttip 10/10/2009 12:42:19 PM(UTC)
is this possible in expert (Formula Assistance)
by bearishbull 7/23/2005 10:23:50 AM(UTC)
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.