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

Notification

Icon
Error

Options
Go to last post Go to first unread
Duffman  
#1 Posted : Thursday, June 21, 2007 2:47:15 AM(UTC)
Duffman

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/21/2007(UTC)
Posts: 3

Hi, I'm developing an MSX dll function using the Microsoft Visual Studio 2005 C++ IDE and have encountered a strange problem that I do not know how to fix.

Similarly to the "MyMov" example "C" dll function given in the MDK manual (Version 9.1), the dll function I'm writing uses a local function that does all of the complex calculations for the main dll function. Just like the "MovingAverage" local function of the "MyMov" dll function, my local function requires an integer number (i.e. "N") of input data values in order to calculate each output value. My local function currently uses a basic "for" loop to read each of the N input values it requires into a one-dimensional array of type double (I do all of the calculations in type double and then typecast the output to type float) and then calculates a single output data value using the input data values stored in the array.

I have been testing my dll function in Metastock using a fictional test security I have created using the Downloader. For ease of testing, the test security only has a sufficient number (i.e. N=20) of data values so that my dll function only outputs a single data value. The input data values as they are shown by the Downloader are exactly as follows: -6.42788, 0, 6.42788, 9.84808, 8.66025, 3.42020, -3.42020, -8.66025, -9.84808, -6.42788, 0, 6.42788, 9.84808, 8.66025, 3.42020, -3.42020, -8.66025, -9.84808, -6.42788, 0.

When I run my dll function in Metastock, the single value it outputs is incorrect. I know that the value it outputs is incorrect because I have developed a basic C++ console program (i.e. a program which runs independently of Metastock) which uses the same algorithm as the local function of my dll and which I know for a fact produces the correct output. The algorithm employed by my console program only differs from that of my local dll function in that instead of reading the input data from a Metastock security file, it reads it from a text file. Even though the data stored in the test file looks exactly the same as that listed above, the output value of my console program is different to that output by Metastock when it runs my dll.

Interestingly, I have found that if I explicitly intialise my local function array with the N input data values (see C++ code below) instead of reading the input data values from the Metastock security file, my dll function produces the correct output when it is run in Metastock.

x[0] = -6.42788; x[1] = 0; x[2] = 6.42788; x[3] = 9.84808; x[4] = 8.66025; x [ 5 ] = 3.4202; x[6] = -3.4202; x[7] = -8.66025; x[ 8] = -9.84808; x[9] = -6.42788; x[10] = 0; x[11] = 6.42788; x[12] = 9.84808; x[13] = 8.66025; x[14] = 3.4202; x[15] = -3.4202; x[16] = -8.66025; x[17] = -9.84808; x[18] = -6.42788; x[19] = 0;

Amongst other things, I have checked to make sure that the local function of my dll is correctly reading in the input data values into the data array, and I have also tried explicitly type-casting the input data to type double and type float. Nothing I have tried makes any difference.

It would be greatly appreciated if anyone can help.

Cheers,

Duffman

wabbit  
#2 Posted : Thursday, June 21, 2007 3:10: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)
Duffman,

Without seeing the code that is actually driving this and the intended algorithm, it is very hard to diagnose exactly where the problem is occurring.

One thing to consider is that your array is indexed 0 to 19, when MS stores its bar count from sClose.iFirstValid to sClose.iLastValid, which is 1 indexed. Your computation might be out by one value from the array?

I don't think the problem would lie in the type casting to/from float/double, but again, this is only a guess.



wabbit [:D]

P.S. I have sent you a PM with an alternative?
smg  
#3 Posted : Thursday, June 21, 2007 11:27:16 PM(UTC)
smg

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2005(UTC)
Posts: 90

Mr. Duffman,

I am also trying to learn to write MSX Dlls, however the main difference with me is that I do not know much of C++ programming and am trying to learn it first.

However, from what I understand of Metastock in general, independent of MDK is that it has nice error filtering and fault tolerance capabilities. So it might be possible that it might be filtering data before passing it to your dll for any unwanted or illegal values. Since your data is having negative values as well as Zeros, it could be possible that these values might having been modified or filtered before being supplied to your code.

You have said that you have already checked to make sure that the local function of your dll is correctly reading the input data values from the MetaStock security file, so the above mentioned possibility seems to have been taken care of by you. Still, I would have written some functions to do the following to find the cause of error:

1. Write a function to return just the raw data values.

2. A funnction to return data with 1 added to them.

3. A function to return data with -1 added to them.

4. A function to return data after division by -1.

etc. etc.

Again Mr. Duffman, my C++ programming level is more of a novice, so the above suggestions might be very simplistic, let's see if these simple tests lead to a solution.

Regards

SMG

Duffman  
#4 Posted : Friday, June 22, 2007 1:32:01 AM(UTC)
Duffman

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/21/2007(UTC)
Posts: 3

Hi Wabbit and SMG,

Many thanks to both of you for your prompt replies and helpful suggestions.

SMG, I think that you could be on to something regarding the negative values in my test security data. I'll try testing my dll with only positive data and will also have another look at the Metastock/Downloader documentation to see what it says about negative data values. If this turns out to be the problem something that concerns me is that I may not be able to use my dll with continuous futures data as I understand that this kind of data can have negative values as a consequence of the back-adjustment of earlier contract month data... I'm probably wrong about this though as you would think that any indicator based on such data would be erroneous.

Also, what if my dll processes data output from another indicator and that data contains negative values? I guess in that case the problem may not arise as the data is being passed from another indicator/function and is not security data.

I'll keep everyone posted of my findings...

Thank you both once more.

Cheers,

Duffman

smg  
#5 Posted : Friday, June 22, 2007 2:37:16 AM(UTC)
smg

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2005(UTC)
Posts: 90

Duffman,

You may look for Error # 1093 - Close equal to zero

Regards

SMG

Duffman  
#6 Posted : Friday, June 22, 2007 4:43:01 AM(UTC)
Duffman

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/21/2007(UTC)
Posts: 3

Problem solved! It wasn't my dll, it was the test data I was using. My dll works fine with real data.

Duffman

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.