Delphi DLL using PLkit.dll not able to get data2 stream.

Questions about MultiCharts and user contributed studies.
cyberdad
Posts: 36
Joined: 10 Aug 2009

Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 16 Sep 2010

I wrote a "hello world" dll in Delphi that interfaces with MC through PLkit.dll.
The DLL has 2 basic functions returning the value of data1.Close[bars] and data2.Close[bars].
The function using data1 stream works fine. But when attempting to use data2 stream an error occurs.
Capture.PNG
(6.44 KiB) Downloaded 665 times
Here is the code of the functions

Code: Select all

var C30,C2 :double;
function GetCloseData1(pELObj : IEasyLanguageObject; Bars : integer): double; stdcall;
begin
C2 := pELObj.CloseMD[data1].AsDouble[Bars];
Result := C2;
end;

function GetCloseData2(pELObj : IEasyLanguageObject; Bars : integer): double; stdcall;
begin
C30 := pELObj.CloseMD[data2].AsDouble[Bars];
Result := C30;
end;

exports GetCloseData1;
exports GetCloseData2;
Here is the EL indicator calling the DLL functions

Code: Select all

inputs: barsback(0);
vars: myCloseData1(0),myCloseData2(0);

external: "TmolosMechano.dll", double, "GetCloseData1", IEasyLanguageObject {self},int {length};
external: "TmolosMechano.dll", double, "GetCloseData2", IEasyLanguageObject {self},int {length};

myCloseData1 = GetCloseData1(self,barsback);
myCloseData2 = GetCloseData2(self,barsback);


plot1(myCloseData1);
plot2(myCloseData2);
The indicator is applied on a chart with 2 data streams: one 2minute stream and one 30minute stream (data1 and data2 respectively).
Is there something special to do when referencing a data stream other than the first one (data1) in the DLL? Isn't IEasyLanguageObject carrying all data streams available in a chart?

Any help would greatly appreciated. I am out of ideas since data1 works fine.
Last edited by cyberdad on 16 Sep 2010, edited 1 time in total.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby TJ » 16 Sep 2010

... But when attempting to use data2 stream an error occurs.
....

what is the error?
what is the error message?

cyberdad
Posts: 36
Joined: 10 Aug 2009

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 16 Sep 2010

The error is

"Message: Error in Study 'Mechano DLL' ; ;"
Capture.PNG
(6.44 KiB) Downloaded 631 times
The error occurs when the strategy is applied to data1 (as base stream) and calling a data2 stream value inside the DLL

Code: Select all

pELObj.CloseMD[data2].AsDouble[Bars];
When the strategy is applied to data2 stream (as base stream), no error occurs but this renders the whole idea useless as I need the strategy to be calculated on every small timeframe (i.e. 2 minute data1) but still being able to handle the data from the longer timeframes in the chart (i.e. 30 minute data2).

cyberdad
Posts: 36
Joined: 10 Aug 2009

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 17 Sep 2010

I just need to know one thing basically.
Does "IEasyLanguageObject" carry all available data streams in a chart as it gets passed to a custom DLL function(s) (ie data1,data2 etc)?
If I know that indeed it does, then I can try to figure out what's wrong with my code. If it doesn't then I can try to alter my code accordingly.

Anybody from tssupport? Just a simple yes or no should suffice.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 19 Sep 2010

Never mind, 3 days for an answer to such a simple matter is a bit much.
I decided to just feed the dll with all price data needed and let everything get calculated inside the dll code. Which makes my code platform independent too. You never know which is the next best platform, after all :)

For anyone who cares, such a dll is actually quite easy to code in Delphi and I suppose in other languages as well. You just create a dll project, import PLkit.dll as a type library and include a sharemem module of your choice to overcome the different way of string handling in Delphi.
Write your code and state your exposing dll functions as external in an EL code to call them from.

That is all there is to it really, and if your code is huge like mine it is totally worth it. You get a vast improvement over the programming IDE, a lot faster compiling and calculating times, as well as almost total expansion capabilities. Good luck to anyone who will give it a spin. Be warned though, support on this subject is next to zero throughout the web.
Cheers.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby Dave Masalov » 21 Sep 2010

Dear cyberdad,

Sorry for the late answer. In fact you can reference data of any data series. If you pass IEasyLanguageObject in custom dll, you can get all the necessary data from chart.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 22 Sep 2010

Thank you for your reply Dave.

One indeed should be able to access all data series. For some reason though, I couldn't get it to work in Delphi. I really don't know why. Any attempt to access any data series beyond the base one, fails. I guess I am doing something wrong on a very basic level and I can't figure out what. I suspect it has to do with pointers to the EL object.

But in the end it makes no difference really. It took me less than an hour to simulate data series access and manipulation using custom code inside the DLL. A dynamic array of records of arrays is all it takes to hold all data series information in a chart (and I am sure there are much better ways than this one).

Debugging is the major pain of dll coding, but you can't have it all... and maybe you really shouldn't anyway.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby Dave Masalov » 22 Sep 2010

Dear cyberdad,

You are welcome. Please tell me how are you trying to get access to prices? Using what functions of interface?

cyberdad
Posts: 36
Joined: 10 Aug 2009

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby cyberdad » 22 Sep 2010

God bless you Dave,

By reassuring me that all data streams are accessible, I now understand what happened. There was another irrelevant error in my code at the time I was trying to access the data streams from my DLL.
So. I decided to code the data streams structure myself and just feed the prices to the DLL. Doing so, I also fixed the irrelevant error without giving the normal data streams access a second try. Mea Culpa.

So, long story short, everything works ok now. But still I think I am gonna go with my custom data structure. I believe this will be a safer approach in terms of compatibility with future PLKit.Dlls. By just feeding the DLL with price data I can actually be sure that my code will work everywhere with just the minimal need for price data.

Of course the PLKit interface has a lot of goodies that will make my coding a lot faster. So in the end it is a choice between coding speed vs platform independence.
Speed is the easy choice but platform independence is probably the wisest one.
I ll have to think this one over I think.

Anyway, thank you for your answer, it saved the day and gave me a choice.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Delphi DLL using PLkit.dll not able to get data2 stream.

Postby Dave Masalov » 22 Sep 2010

Dear cyberdad,

You are welcome. Glad to hear that the problem has been solved.


Return to “MultiCharts”