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

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
chris3105  
#1 Posted : Friday, November 11, 2005 8:52:50 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
This week EQUIS sent the new Dev 9.1 to me and by looking for a good starting/learning project I decided to write a new Equity function. The Equity function is a kind of quick and dirty system tester. It plots the Equity of a given trading system into a chart and writes some info about all trades and statistics into a text file, which is located in the folder of the security. Optional this text file is automatically opened with notepad after the indicator is dropped on the chart. The output of the equity function is nearly the same as you get, when you make a system test with the enhanced system tester, the reason for the small difference is, that EQUIS calculates the number of shares on the basis of the open price before the trade and I do my calculations on the really entry price. The indictor call is a little bit complex, so here's a brief description: ExtFml( "TMW.Equity", Latch, Wrapper: EL CL ES CS Delay Show, Entry/Exit Commission in $, Portfolio in $, Shares in % of Portfolio, Contracts, Point Multiplier) In total there an actually 7 function input parameters: 1) Latch The latch is a binary Signal, which gives you the actual state of a trading system. You can find further information in den doc of the forumdll. 2) Wrapper: EL CL ES CS Delay Show In this string are stored 6 information’s EL => At which price do you want to enter a long trade, valid entries are: O, H, L, C CL => At which price do you want to close a long trade, valid entries are: O, H, L, C ES => At which price do you want to enter a short trade, valid entries are: O, H, L, C EL => At which price do you want to close a short trade, valid entries are: O, H, L, C Delay => Here you can specify the delay for EL, CL, ES and EL, valid entries are 0,1,2,3 Show => after the indicator is plotted on the chart (or refreshed), a result file is opened. If you don't like this, you must enter N or n. Examples: oOhl1y ==> Valid hHlL2j ==> Valid OOHH7u ==> invalid, fifth character is not in the range of 0 to 3 KOOO1n => invalid, for the first four characters are only O,H,L or C allowed. Default value should be OOOO1Y what means: Buy and sell with a delay of one bar 3) Entry/Exit Commission in $ Valid all numbers greater 0, trades without commissions are not allowed. 4) Portfolio in $ Enter the $ value of your initial portfolio, valid all numbers greater than 1000 5) Shares in % of Portfolio Enter a number, which part of your Portfolio (Initial portfolio + net profit - commission) you want to invest in every new trade. Valid entries are all number greater than 0 and less or equal 100. 6) Contracts If you want to do a points only test, then you can set contracts to a number greater than 0. If contracts are 0, the number of current shares is new calculated by the value in No. 5, if contracts is greater than 0, No. 5 is ignored. 7) Point Multiplier Every gain or loss is multiplied with this number, default value should be 1. Valid are all numbers greater or equal than 1. Although this thing sounds very complicated, it's very easy to handle. See the following two examples: Sample 1: The PS Aroon System {Sample Code 1 Start} Buy:=AroonUp(14)=100 AND AroonDown(14)=0; Sell:=AroonUp(14)=0 AND AroonDown(14)=100; InitialEquity:=Input("Initial Equity in $",1000,10000000,100000); Commi:=Input("Entry/Exit Commission in $",1,1000,10); PercShares:=Input("Shares/Contracts in % of Portfolio",1,10000,10); Contracts:=Input("Number of Contracts",0,50,0); MultiPly:=Input("Point Multiplyer",1,50,1); ExtFml( "TMW.Equity", Latch, "OOOO1Y", Commi, InitialEquity, PercShares, Contracts,MultiPly) Buy:=AroonUp(14)=100 AND AroonDown(14)=0; Sell:=AroonUp(14)=0 AND AroonDown(14)=100; EL:= buy; CL:= sell; ES:= sell; CS:= buy; Latch:=ExtFml( "tmw.Latch", EL, CL, ES, CS); ExtFml( "TMW.Equity", Latch, "OOOO1Y", Commi, InitialEquity, PercShares, Contracts,MultiPly) {Sample Code 1 End} Just copy the code above in the indicator builder and drop it on a chart. Sample 2: Henry's famous MACD with case Stop 3 System {Sample Code 2, Part 1 Start: Name:_MACD System with Case Stop} ShortMA:= Input("Short EMA",1,200,12); LongMA:= Input("Long EMA",1,200,26); MovAvg:=Input("Mov",1,200,9); periods:=30; hlperiod:=20; cMACD:=Mov(C,ShortMA,E) - Mov(C,LongMA,E); cTrigger:=Mov(Mov(C,ShortMA,E) - Mov(C,LongMA,E),MovAvg,E); RWH:=(H-Ref(L,-periods))/(ATR(periods)*Sqrt(periods)); RWL:=(Ref(H,-periods)-L)/(ATR(periods)*Sqrt(periods)); Pk:=Mov((RWH-RWL),3,W); AVTR:=Mov(HHV(H,2) - LLV(L,2), hlperiod, S); SD:=Stdev(HHV(H,2) - LLV(L,2), hlperiod); Val3:=If(Pk>0,HHV(H-AVTR-2*SD, hlperiod),LLV(L+AVTR+2*SD, hlperiod)); EL:= (cTrigger <cMACD) AND (Val3<C); CL:= (Val3>C) OR ((cTrigger>cMACD) AND Val3>C); ES:= (cTrigger>cMACD) AND (Val3>C); CS:= (Val3<C) OR ((cTrigger <cMACD) AND Val3<C); state:=ExtFml( "tmw.Latch", EL, CL, ES, CS); State {Sample Code 2, Part 1 End} Just copy the code above in the indicator builder and give it the name _MACD System with Case Stop {Sample Code 2, Part 2 Start, Name:_TMW Equity} InitialEquity:=Input("Initial Equity in $",1000,10000000,100000); Commi:=Input("Entry/Exit Commission in $",1,1000,10); PercShares:=Input("Shares/Contracts in % of Portfolio",1,10000,10); Contracts:=Input("Number of Contracts",0,50,0); MultiPly:=Input("Point Multiplyer",1,50,1); Latch:=Fml("_MACD System with Case Stop"); ExtFml( "TMW.Equity", Latch, "OOOO1Y", Commi, InitialEquity, PercShares, Contracts,MultiPly) {Sample Code 2, Part 2 End} Just copy the code above in the indicator builder and give it the name _TMW Equity Sample 3: Use of the indicator in exploration {Sample Code 3 Start} Fml("_TMW Equity") {Sample Code 3 End} Important: By using this formula in an exploration the string input should look like this "OOOO1N" or "OOOO1n". The sixth letter is N or n, which means that no text file is opened!!! This exploration over all stocks the NASDAQ 100 takes about 10 seconds, which is quite okay I think. Further examples for Settings: InitialEquity := 10000; Commi := 10; PercShares:= 10; Contracts := 0; MultiPly := 3; ==> You trade an initial portfolio of 10.000 $, your trading size is 10% of the available equity, the net profit is multiplied with 3. InitialEquity := 100000; Commi := 10; PercShares:= 5; Contracts := 0; MultiPly := 1; ==> You trade an initial portfolio of 100.000 $, your trading size is 5% of the available equity, the round turn per Trade is 20$, the net profit is multiplied with 1. InitialEquity := 10000; Commi := 5; PercShares:= 10; Contracts := 1; MultiPly := 5; ==> Point only test, because Contracts is set to 1, you always trade 1 contract, the round turn per Trade is 10$, the net profit is multiplied with 5. The initial Equity is only for the Buy and Hold Statistic. InitialEquity := 10000; Commi := 5; PercShares:= 10; Contracts := 100000; MultiPly := 1; ==> Point only test, because Contracts is set to 100000, you always trade 100000 contract/shares, the round turn per Trade is 10$, the net profit is multiplied with 1. The initial Equity is only for the Buy and Hold Statistic. If you want the commission set to 7.95$, you had to enter this value manually or per variable, because decimals are not possible in the Input Function of the Indicator Builder. The second function in the dll, the Latch function, is nearly the same as in the forum dll, for further information look there.
Because this is my first project with the DevKit I don't know, on which versions of MetaStock it works fine. I use the dll on a Pentium 4, XPPro with service pack 2 and MetaStock Pro 9.1 without problems. The dll is written in the actual version of Visual C++ .Net. I think, the results are correct, but if anyone find some mistakes, please tell me and I try to correct them. If anyone likes to have some other trade statistics like Sharpe ratio or monthly/weekly stats, then I can implement it. To avoid mistakes, the correct mathematical formula would be nice. The text file output, the format and the information in it can easily be modified, if there's any interest. Currently I would call the version a pre release version and I would be happy, if anyone can make some more tests with it. If the dll is stable and all (eventually) user wishes are implemented I give the code to Patrick, so he can put it in the forum dll. If possible, I like to join the MSX Programmers Group. If you have any questions, problems or wishes please write it in this thread. Any comments are welcome Chris
chris3105  
#2 Posted : Friday, November 11, 2005 8:57:01 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
:oops: I forget to attach the dll. Rename the attachment into tmw.dll and copy it to ..\\Equis\\MetaStock\\External Function DLLs Chris
StorkBite  
#3 Posted : Friday, November 11, 2005 9:03:43 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Wow Chris, that's an awesome amount of work in just a short time! Did you write it in C++ or what? Is there any chance that you'd share the source code?
StorkBite  
#4 Posted : Friday, November 11, 2005 9:05:49 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Your download link is not working... Could be the .[censored] extension, though we've done that before. Can you try it as a .zip? The download counter is being triggered, but there is an error response that the file is not available. I believe all 4 of the d/l's on the counter were my attempts.
chris3105  
#5 Posted : Friday, November 11, 2005 9:06:34 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
Another :oops: Just read my text and found a mistake: The correct Sample 1 Code is: {Sample Code 1 Start} Buy:=AroonUp(14)=100 AND AroonDown(14)=0; Sell:=AroonUp(14)=0 AND AroonDown(14)=100; InitialEquity:=Input("Initial Equity in $",1000,10000000,100000); Commi:=Input("Entry/Exit Commission in $",1,1000,10); PercShares:=Input("Shares/Contracts in % of Portfolio",1,10000,10); Contracts:=Input("Number of Contracts",0,50,0); MultiPly:=Input("Point Multiplyer",1,50,1); Buy:=AroonUp(14)=100 AND AroonDown(14)=0; Sell:=AroonUp(14)=0 AND AroonDown(14)=100; EL:= buy; CL:= sell; ES:= sell; CS:= buy; Latch:=ExtFml( "tmw.Latch", EL, CL, ES, CS); ExtFml( "TMW.Equity", Latch, "OOOO1Y", Commi, InitialEquity, PercShares, Contracts,MultiPly) {Sample Code 1 End} :oops: No 3. My text was too long and was not complete, here's the end of text 1: Because this is my first project with the DevKit I don't know, on which versions of MetaStock it works fine. I use the dll on a Pentium 4, XPPro with service pack 2 and MetaStock Pro 9.1 without problems. The dll is written in the actual version of Visual C++ .Net. I think, the results are correct, but if anyone find some mistakes, please tell me and I try to correct them. If anyone likes to have some other trade statistics like Sharpe ratio or monthly/weekly stats, then I can implement it. To avoid mistakes, the correct mathematical formula would be nice. The text file output, the format and the information in it can easily be modified, if there's any interest. Currently I would call the version a pre release version and I would be happy, if anyone can make some more tests with it. If the dll is stable and all (eventually) user wishes are implemented I give the code to Patrick, so he can put it in the forum dll. If possible, I like to join the MSX Programmers Group. If you have any questions, problems or wishes please write it in this thread. Any comments are welcome Chris
chris3105  
#6 Posted : Friday, November 11, 2005 9:13:00 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
George, i just send the file to your email adress, so you can put it here. Chris
StorkBite  
#7 Posted : Friday, November 11, 2005 11:48:21 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Got it. I'll test it out over the next few trading days and get back with you. Thanks for sharing!
StorkBite  
#8 Posted : Friday, November 11, 2005 11:51:34 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Chris's dll in .zip format. This seems to d/l OK. Maybe now the masses will come... :D
wabbit  
#9 Posted : Saturday, November 12, 2005 3:21:18 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)
Any chance of a copy of the source code too, please? wabbit :D
RUAGOODP  
#10 Posted : Saturday, November 12, 2005 8:01:31 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

Hi Chris, Its not working with metastock8.0 It says "an msx dll is reporting a floating point invalid operation error>" Ref dll TMW equity Norman
chris3105  
#11 Posted : Saturday, November 12, 2005 9:26:51 AM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
@Wabbit, i told before, when the Equity function is completed, i'll share the code, no problem :twisted: @RUAGOODP, is the tmw.latch working? If so, maybe there's a buy in the Equity function. I'll set up this weekend a computer with MS 8 and test it. Chris
RUAGOODP  
#12 Posted : Saturday, November 12, 2005 10:10:31 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

Hi Chris, The latch is working :) Norman
Patrick  
#13 Posted : Sunday, November 13, 2005 9:39:31 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)
wow this sounds great. Good job =D>
chris3105  
#14 Posted : Monday, November 14, 2005 12:26:04 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
Okay, after hours of searching I found the damned bug, here's a working version of the dll and some small samples. Just put the dll in ..\\Equis\\MetaStock\\External Function DLLs. If you lke to use the samples, rename MS91FORM.DTA into your MS version (MS8 in MS80FORM.DTA, ...) and import the files via Organizer. The indictors all starts with _TMW. Chris
RUAGOODP  
#15 Posted : Tuesday, November 15, 2005 2:42:34 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

Hi Chris, Latch is not working now Norman
RUAGOODP  
#16 Posted : Tuesday, November 15, 2005 2:44:29 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

Hi Chris, Sorry. Tmw Latch is not showing in the external folder Norman
chris3105  
#17 Posted : Tuesday, November 15, 2005 10:02:31 AM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
Hi RUAGOODP, I've compiled it again and tested it with no problems on a MSPro 9.1 and a clean MSPro 8.01 System. So if this version is not working on your system, I give up :cry:
arnevanveen  
#18 Posted : Monday, November 21, 2005 5:28:46 PM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

What a great feature is this, unfortunately it is not working on my pc. Is there anyone who can fix it? Or maybe is Chris in a good mood and will give it another try? You will definitely help me (and a lot of others!!) Greetings! Arne
chris3105  
#19 Posted : Monday, November 28, 2005 11:05:30 PM(UTC)
chris3105

Rank: Advanced Member

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

Was thanked: 1 time(s) in 1 post(s)
@arnevanveen, the current version of the dll is at the end of this thread (with some other nice function), maybe this version works on your PC. At the moment I've some problems with version 8.01 and I can't find the reason for it, because I use no MSFL functions. Maybe a windows dll or Service is missing. Please give me some details on your PC-Configuration and MS Version. Chris
RUAGOODP  
#20 Posted : Wednesday, November 30, 2005 8:21:50 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

Hi Chris, Your latest dll works on Meatsock 8.0 :) . Just curious why your equity curves differs from Roy's Trade Equity formula curves? Cheers Norman
Users browsing this topic
Guest (Hidden)
2 Pages12>
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.